コード例 #1
0
ファイル: util.py プロジェクト: Guliux10/bchacks_deepbreath
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 ValidateImageUrl(image_url, services):
    """Check the user-provided image URL.

  Ensures that:
  - it is consistent with the services being deployed (there must be exactly
    one)
  - it is an image in a supported Docker registry

  Args:
    image_url: str, the URL of the image to deploy provided by the user
    services: list, the services to deploy

  Raises:
    MultiDeployError: if image_url is provided and more than one service is
      being deployed
    docker.UnsupportedRegistryError: if image_url is provided and does not point
      to one of the supported registries
  """
    # Validate the image url if provided, and ensure there is a single service
    # being deployed.
    if image_url is None:
        return
    if len(services) != 1:
        raise exceptions.MultiDeployError()
    for registry in constants.ALL_SUPPORTED_REGISTRIES:
        if image_url.startswith(registry):
            return
    raise docker.UnsupportedRegistryError(image_url)