]> git.ipfire.org Git - pbs.git/commitdiff
registry: Create a function to find a blob
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 9 Feb 2025 13:23:48 +0000 (13:23 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 9 Feb 2025 13:23:48 +0000 (13:23 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/web/registry.py

index 3f0f3200db135f682c7336a388347106fd5f65ee..62359261dd5982bb15181f34426a84ee810e036f 100644 (file)
@@ -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):
                """