def get_tag(self, image_name: ImageName):
        """
        Retrieves a repository tag for a given image.

        Args:
            image_name: The image for which to assign the tag

        Returns:
            The repository tag, or None.
        """
        image = ArchiveChangeset.normalize_tags([image_name.image])[0]
        return self.get_json().get(image, {}).get(image_name.resolve_tag(),
                                                  None)
    def set_tag(self, image_name: ImageName, digests: FormattedSHA256):
        """
        Assigns a repository tag.

        Args:
            image_name: The image for which to assign the tag
            digests: The value to be assigned to the tag
        """
        _json = self.get_json()
        image = ArchiveChangeset.normalize_tags([image_name.image])[0]
        if not image in _json:
            _json[image] = {}
        _json[image][image_name.resolve_tag()] = digests.sha256
        self._set_json(_json)
Example #3
0
async def replicate_manifest_lists(
        docker_registry_secure: DockerRegistrySecure):
    """Replicates manifests lists to the secure docker registry for testing."""
    # pylint: disable=protected-access
    LOGGER.debug("Replicating manifest lists into %s ...",
                 docker_registry_secure.service_name)
    async with DockerRegistryClientAsync() as docker_registry_client_async:
        for image in get_test_data_registryv2():
            if "tag_resolves_to_manifest_list" not in image:
                continue

            digest = image["digests"][
                DockerMediaTypes.DISTRIBUTION_MANIFEST_LIST_V2]
            image_name = ImageName(image["image"],
                                   digest=digest,
                                   tag=image["tag"])
            LOGGER.debug("- %s", image_name)

            scope = DockerAuthentication.SCOPE_REPOSITORY_PULL_PATTERN.format(
                image_name.image)
            auth_header_src = await docker_registry_client_async._get_request_headers(
                image_name, scope=scope)
            if not auth_header_src:
                LOGGER.warning(
                    "Unable to retrieve authentication headers for: %s",
                    image_name)

            pdrf_image_name = PDRFImageName(
                image_name.resolve_image(),
                digest=image_name.resolve_digest(),
                endpoint=image_name.resolve_endpoint(),
                tag=image_name.resolve_tag(),
            )
            try:
                replicate_manifest_list(
                    pdrf_image_name,
                    docker_registry_secure.endpoint,
                    auth_header_dest=docker_registry_secure.auth_header,
                    auth_header_src=auth_header_src,
                    ssl_context_dest=docker_registry_secure.ssl_context,
                )
            except Exception as exception:  # pylint: disable=broad-except
                LOGGER.warning(
                    "Unable to replicate manifest list '%s': %s",
                    image_name,
                    exception,
                    exc_info=True,
                )