Skip to content

Commit

Permalink
draft
Browse files Browse the repository at this point in the history
  • Loading branch information
git-hyagi committed Mar 27, 2024
1 parent b7eb315 commit 5dfe9b0
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 56 deletions.
4 changes: 1 addition & 3 deletions pulp_container/app/redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
from django.shortcuts import redirect

from pulp_container.app.exceptions import ManifestNotFound
from pulp_container.app.models import ConfigBlob
from pulp_container.app.utils import get_accepted_media_types
from pulp_container.constants import BLOB_CONTENT_TYPE, MEDIA_TYPE

from pulp_container.app.models import ConfigBlob


class CommonRedirects:
"""
Expand Down Expand Up @@ -107,7 +106,6 @@ def issue_blob_redirect(self, blob):
"""
Redirect to the passed blob or stream content when an associated artifact is not present.
"""

try:
artifact = blob._artifacts.get()
except ObjectDoesNotExist:
Expand Down
33 changes: 21 additions & 12 deletions pulp_container/app/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,17 +302,6 @@ async def get_by_digest(self, request):
ca = await blob.contentartifact_set.afirst()
return await self._stream_content_artifact(request, web.StreamResponse(), ca)
elif request.match_info["content"] == "config-blobs":
blob = await ConfigBlob.objects.aget(digest=digest)
media_type=MEDIA_TYPE.CONFIG_BLOB ### need to find a better way to identify the media_type
headers = {
"Content-Type": media_type,
"Docker-Content-Digest": digest,
"Docker-Distribution-API-Version": "registry/2.0",
}
return web.Response(text=blob.data,headers=headers)
else:
raise RuntimeError("Only blobs or manifests are supported by the parser.")
elif request.match_info["content"] == "config-blobs":
blob = await ConfigBlob.objects.aget(digest=digest)
media_type=MEDIA_TYPE.CONFIG_BLOB ### need to find a better way to identify the media_type
headers = {
Expand All @@ -321,6 +310,17 @@ async def get_by_digest(self, request):
"Docker-Distribution-API-Version": "registry/2.0",
}
return web.Response(text=blob.data,headers=headers)
else:
raise RuntimeError("Only blobs or manifests are supported by the parser.")
elif request.match_info["content"] == "config-blobs":
blob = await ConfigBlob.objects.aget(digest=digest)
media_type=MEDIA_TYPE.CONFIG_BLOB ### need to find a better way to identify the media_type
headers = {
"Content-Type": media_type,
"Docker-Content-Digest": digest,
"Docker-Distribution-API-Version": "registry/2.0",
}
return web.Response(text=blob.data,headers=headers)
else:
raise PathNotResolved(path)
else:
Expand All @@ -330,6 +330,16 @@ async def get_by_digest(self, request):
else:
return await self._stream_content_artifact(request, web.StreamResponse(), ca)

async def _config_blob_response(self,digest):
blob = await ConfigBlob.objects.aget(digest=digest)
media_type=MEDIA_TYPE.CONFIG_BLOB ### need to find a better way to identify the media_type
headers = {
"Content-Type": media_type,
"Docker-Content-Digest": digest,
"Docker-Distribution-API-Version": "registry/2.0",
}
return web.Response(text=blob.data,headers=headers)

@staticmethod
async def _empty_blob():
# fmt: off
Expand Down Expand Up @@ -432,7 +442,6 @@ async def run_pipeline(self, saved_artifact):
async def init_pending_content(self, digest, manifest_data, media_type, artifact):
if config := manifest_data.get("config", None):
config_digest = config["digest"]

config_blob = await self.save_config_blob(config_digest)
await sync_to_async(self.repository.pending_config_blobs.add)(config_blob)
else:
Expand Down
79 changes: 39 additions & 40 deletions pulp_container/app/registry_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,6 @@ def get(self, request, path, pk):

@RegistryApiCache(base_key=lambda req, cac: find_base_path_cached(req, cac))
def handle_safe_method(self, request, path, pk):

"""Handles safe requests for Blobs."""
distribution, repository, repository_version = self.get_drv_pull(path)
redirects = self.redirects_class(distribution, path, request)
Expand Down Expand Up @@ -1044,45 +1043,45 @@ def handle_safe_method(self, request, path, pk):
return redirects.issue_blob_redirect(blob)


class ConfigBlobs(RedirectsMixin, ContainerRegistryApiMixin, ViewSet):
"""
ViewSet for interacting with ConfigBlobs
"""

renderer_classes = [ContentRenderer]

def head(self, request, path, pk=None):
"""
Responds to HEAD requests about config-blobs
"""
return self.handle_safe_method(request, path, pk=pk)

def get(self, request, path, pk):
"""
Responds to GET requests about config-blobs
"""
return self.handle_safe_method(request, path, pk)

@RegistryApiCache(base_key=lambda req, cac: find_base_path_cached(req, cac))
def handle_safe_method(self, request, path, pk):

"""Handles safe requests for ConfigBlobs."""
distribution, repository, repository_version = self.get_drv_pull(path)
redirects = self.redirects_class(distribution, path, request)

try:
blob = models.ConfigBlob.objects.get(pk=pk)
return redirects.redirect_to_content_app("config-blobs",pk)
except:
pass ###### WIP PENDING FIX THIS
#repository = repository.cast()
try:
blob = repository.pending_config_blobs.get(pk=pk)
blob.touch()
except:
raise BlobNotFound(pk=pk)

return redirects.issue_blob_redirect(blob)
#class ConfigBlobs(RedirectsMixin, ContainerRegistryApiMixin, ViewSet):
# """
# ViewSet for interacting with ConfigBlobs
# """
#
# renderer_classes = [ContentRenderer]
#
# def head(self, request, path, pk=None):
# """
# Responds to HEAD requests about config-blobs
# """
# return self.handle_safe_method(request, path, pk=pk)
#
# def get(self, request, path, pk):
# """
# Responds to GET requests about config-blobs
# """
# return self.handle_safe_method(request, path, pk)
#
# @RegistryApiCache(base_key=lambda req, cac: find_base_path_cached(req, cac))
# def handle_safe_method(self, request, path, pk):
#
# """Handles safe requests for ConfigBlobs."""
# distribution, repository, _ = self.get_drv_pull(path)
# redirects = self.redirects_class(distribution, path, request)
#
# try:
# blob = models.ConfigBlob.objects.get(pk=pk)
# return redirects.redirect_to_content_app("config-blobs",pk)
# except:
# pass ###### WIP PENDING FIX THIS
# #repository = repository.cast()
# try:
# blob = repository.pending_config_blobs.get(pk=pk)
# blob.touch()
# except:
# raise BlobNotFound(pk=pk)
#
# return redirects.issue_blob_redirect(blob)

class Manifests(RedirectsMixin, ContainerRegistryApiMixin, ViewSet):
"""
Expand Down
2 changes: 1 addition & 1 deletion pulp_container/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Blobs,
BlobUploads,
CatalogView,
ConfigBlobs,
#ConfigBlobs,
FlatpakIndexDynamicView,
FlatpakIndexStaticView,
Manifests,
Expand Down

0 comments on commit 5dfe9b0

Please sign in to comment.