コード例 #1
0
    async def get_tag(self, request):
        """
        Match the path and stream either Manifest or ManifestList.

        Args:
            request(:class:`~aiohttp.web.Request`): The request to prepare a response for.

        Raises:
            PathNotResolved: The path could not be matched to a published file.
            PermissionError: When not permitted.

        Returns:
            :class:`aiohttp.web.StreamResponse` or :class:`aiohttp.web.FileResponse`: The response
                streamed back to the client.

        """
        path = request.match_info["path"]
        tag_name = request.match_info["tag_name"]
        distribution = self._match_distribution(path)
        self._permit(request, distribution)
        repository_version = distribution.get_repository_version()
        accepted_media_types = get_accepted_media_types(request.headers)

        try:
            tag = Tag.objects.get(pk__in=repository_version.content,
                                  name=tag_name)
        except ObjectDoesNotExist:
            raise PathNotResolved(tag_name)

        # we do not convert OCI to docker
        oci_mediatypes = [MEDIA_TYPE.MANIFEST_OCI, MEDIA_TYPE.INDEX_OCI]
        if (tag.tagged_manifest.media_type in oci_mediatypes and
                tag.tagged_manifest.media_type not in accepted_media_types):
            log.warn(
                "OCI format found, but the client only accepts {accepted_media_types}."
                .format(accepted_media_types=accepted_media_types))
            raise PathNotResolved(tag_name)

        # return schema1 (even in case only oci is requested)
        if tag.tagged_manifest.media_type == MEDIA_TYPE.MANIFEST_V1:
            return_media_type = MEDIA_TYPE.MANIFEST_V1_SIGNED
            response_headers = {
                "Content-Type": return_media_type,
                "Docker-Content-Digest": tag.tagged_manifest.digest,
            }
            return await Registry.dispatch_tag(tag, response_headers)

        # return what was found in case media_type is accepted header (docker, oci)
        if tag.tagged_manifest.media_type in accepted_media_types:
            return_media_type = tag.tagged_manifest.media_type
            response_headers = {
                "Content-Type": return_media_type,
                "Docker-Content-Digest": tag.tagged_manifest.digest,
            }
            return await Registry.dispatch_tag(tag, response_headers)

        # convert if necessary
        return await Registry.dispatch_converted_schema(
            tag, accepted_media_types, path)
コード例 #2
0
ファイル: redirects.py プロジェクト: mdellweg/pulp_container
 def issue_tag_redirect(self, tag):
     """
     Issue a redirect or perform a schema conversion if an accepted media type requires it.
     """
     manifest_media_type = tag.tagged_manifest.media_type
     if manifest_media_type in get_accepted_media_types(
             self.request.headers):
         return self.redirect_to_artifact(tag.name, tag.tagged_manifest,
                                          manifest_media_type)
     elif manifest_media_type == MEDIA_TYPE.MANIFEST_V1:
         return self.redirect_to_artifact(tag.name, tag.tagged_manifest,
                                          MEDIA_TYPE.MANIFEST_V1_SIGNED)
     else:
         # execute the schema conversion
         return self.redirect_to_content_app("manifests", tag.name)