示例#1
0
def ValidateRepositoryPath(repository_path):
    """Validates the repository path.

  Args:
    repository_path: str, The repository path supplied by a user.

  Returns:
    The parsed docker_name.Repository object.

  Raises:
    InvalidImageNameError: If the image name is invalid.
    docker.UnsupportedRegistryError: If the path is valid, but belongs to a
      registry we don't support.
  """
    if IsFullySpecified(repository_path):
        raise InvalidImageNameError(
            'Image names must not be fully-qualified. Remove the tag or digest '
            'and try again.')
    if repository_path.endswith('/'):
        raise InvalidImageNameError('Image name cannot end with \'/\'. '
                                    'Remove the trailing \'/\' and try again.')

    try:
        if repository_path in constants.MIRROR_REGISTRIES:
            repository = docker_name.Registry(repository_path)
        else:
            repository = docker_name.Repository(repository_path)
        if repository.registry not in constants.ALL_SUPPORTED_REGISTRIES:
            raise docker.UnsupportedRegistryError(repository_path)
        return repository
    except docker_name.BadNameException as e:
        # Reraise with the proper base class so the message gets shown.
        raise InvalidImageNameError(six.text_type(e))
示例#2
0
 def __init__(
     self,
     repo,
     namespace,
     creds,
     transport,
     ttl,
     threads=1,
     should_cache=True,
     should_upload=True,
     mount=None,
     use_global=False,
 ):
     super(Registry, self).__init__()
     self._repo = repo
     self._namespace = namespace
     self._creds = creds
     _reg_name = '{base}/{namespace}'.format(
         base=constants.GLOBAL_CACHE_REGISTRY, namespace=self._namespace)
     # TODO(nkubala): default this to true to point builds to global cache
     self._use_global = use_global
     if use_global:
         _reg = docker_name.Registry(_reg_name)
         self._global_creds = docker_creds.DefaultKeychain.Resolve(_reg)
     self._transport = transport
     self._threads = threads
     self._mount = mount or []
     self._should_cache = should_cache
     self._should_upload = should_upload
     self._ttl = ttl