"""
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
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):
"""