From: Michael Tremer Date: Sun, 9 Feb 2025 13:23:48 +0000 (+0000) Subject: registry: Create a function to find a blob X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=69d2bb6da3fe723617e7f9286c41dd98035f187c;p=pbs.git registry: Create a function to find a blob Signed-off-by: Michael Tremer --- diff --git a/src/web/registry.py b/src/web/registry.py index 3f0f3200..62359261 100644 --- a/src/web/registry.py +++ b/src/web/registry.py @@ -31,6 +31,25 @@ class BaseHandler(base.BaseHandler): """ A base handler for any registry stuff """ + async def get_blob(self, distro, digest): + """ + Returns a blob if we have it. + """ + # Fetch all releases + releases = await distro.get_releases() + + # This is a super naive approach because we don't have an index + # for the files. Considering how rarely we are running through this code, + # it might work out perfectly fine for us to just walk through all images + # until we find the correct file. As we are starting with the latest release, + # chances should be high that we don't have to iterate through all of this + # for too long. + for release in releases: + for image in release.oci_images: + blob = await image.get_blob(digest) + if blob: + return blob + async def write_error(self, *args, **kwargs): pass # Don't send any body @@ -111,29 +130,13 @@ class BlobOrManifestHandler(BaseHandler): if not distro: raise tornado.web.HTTPError(404) - # Fetch all releases - releases = await distro.get_releases() - - # This is a super naive approach because we don't have an index - # for the files. Considering how rarely we are running through this code, - # it might work out perfectly fine for us to just walk through all images - # until we find the correct file. As we are starting with the latest release, - # chances should be high that we don't have to iterate through all of this - # for too long. - - for release in releases: - for image in release.oci_images: - blob = await image.get_blob(reference) - - # Continue if there was no match - if blob is None: - continue - - # Send the blob! - return await self._send_blob(blob, type, send_body=send_body) + # Fetch the blob + blob = await self.get_blob(distro, reference) + if not blob: + raise tornado.web.HTTPError(404) - # If we get here, we didn't find anything - raise tornado.web.HTTPError(404) + # Send the blob! + return await self._send_blob(blob, type, send_body=send_body) async def _send_blob(self, blob, type, send_body=True): """