Esempio n. 1
0
def _ValidateAndGetDockerVersion(version_or_tag):
    """Validates a version_or_tag and returns the validated DockerVersion object.

  Args:
    version_or_tag: a docker version or a docker tag.

  Returns:
    a DockerVersion object.

  Raises:
    ar_exceptions.InvalidInputValueError if version_or_tag is not valid.
  """
    try:
        if isinstance(version_or_tag, DockerVersion):
            # We have all the information about the docker digest.
            # Call the API to make sure it exists.
            ar_requests.GetVersion(ar_requests.GetClient(),
                                   ar_requests.GetMessages(),
                                   version_or_tag.GetVersionName())
            return version_or_tag
        elif isinstance(version_or_tag, DockerTag):
            digest = ar_requests.GetVersionFromTag(ar_requests.GetClient(),
                                                   ar_requests.GetMessages(),
                                                   version_or_tag.GetTagName())
            docker_version = DockerVersion(version_or_tag.image, digest)
            return docker_version
        else:
            raise ar_exceptions.InvalidInputValueError(
                _INVALID_DOCKER_IMAGE_ERROR)
    except api_exceptions.HttpNotFoundError:
        raise ar_exceptions.InvalidInputValueError(_DOCKER_IMAGE_NOT_FOUND)
Esempio n. 2
0
def _GetDockerDigest(version_or_tag):
    """Retrieves the docker digest information.

  Args:
    version_or_tag: an object of DockerVersion or DockerTag

  Returns:
    A dictionary of information about the given docker image.
  """
    docker_version = version_or_tag
    try:
        if isinstance(version_or_tag, DockerVersion):
            # We have all the information about the docker digest.
            # Call the API to make sure it exists.
            ar_requests.GetVersion(ar_requests.GetClient(),
                                   ar_requests.GetMessages(),
                                   version_or_tag.GetVersionName())
        elif isinstance(version_or_tag, DockerTag):
            digest = ar_requests.GetVersionFromTag(ar_requests.GetClient(),
                                                   ar_requests.GetMessages(),
                                                   version_or_tag.GetTagName())
            docker_version = DockerVersion(version_or_tag.image, digest)
        else:
            raise ar_exceptions.InvalidInputValueError(
                _INVALID_DOCKER_IMAGE_ERROR)
    except api_exceptions.HttpNotFoundError:
        raise ar_exceptions.InvalidInputValueError(_DOCKER_IMAGE_NOT_FOUND)
    return {
        "digest":
        docker_version.digest,
        "fully_qualified_digest":
        docker_version.GetDockerString(),
        "registry":
        "{}-docker.pkg.dev".format(docker_version.image.docker_repo.location),
        "repository":
        docker_version.image.docker_repo.repo,
    }