Exemple #1
0
def repository_args(repo_type, **kwargs):
    """
    Validate that the combination of arguments for a
    :class:`nexuscli.repository.model.Repository` is valid.

    Raises:
        :class:`ValueError`
            If the value of a given argument is invalid or unsupported, or if
            unrecognised keyword arguments are given.
        :class:`TypeError`
            If the type of a given argument has the wrong object type.
        :class:`NotImplementedError`
            If the combination of arguments isn't yet supported.

    :param repo_type: as given to
        :py:meth:`nexuscli.nexus_repository.Repository.create()
    :param kwargs: as given to
        :py:meth:`nexuscli.nexus_repository.Repository.create()
    """
    if not validate_strings(repo_type):
        raise TypeError('repo_type ({}) must be of string type'.format(
            type(repo_type)))
    is_target_supported('repo_type', repo_type, KNOWN_TYPES, SUPPORTED_TYPES)

    try:
        remaining_args = _check_common_args(**kwargs)
        remaining_args = _check_type_args(repo_type, **remaining_args)
    except KeyError as e:
        raise KeyError('Missing required keyword argument: {}'.format(e))

    ignore_extra = remaining_args.pop('ignore_extra_kwargs', False)
    if remaining_args and not ignore_extra:
        raise ValueError('Unrecognised keyword arguments: {}'.format(
            remaining_args.keys()))
Exemple #2
0
def _check_common_args(**kwargs):
    name = kwargs.pop('name')
    format_ = kwargs.pop('format')
    if not validate_strings(name, format_):
        raise TypeError(
            'name ({0}) and format ({1}) must all be of string type'.format(
                *map(type, [name, format_])))
    is_target_supported('format', format_, KNOWN_FORMATS, SUPPORTED_FORMATS)

    blob_store_name = kwargs.pop('blob_store_name')
    # TODO: validate that blob_store_name exists on server
    assert blob_store_name

    strict_content_type_v = kwargs.pop('strict_content_type_validation')
    if not isinstance(strict_content_type_v, bool):
        raise TypeError(
            'strict_content_type_validation ({}) must be bool'.format(
                type(strict_content_type_v)))

    remaining_args = _check_format_args(format_, **kwargs)
    return remaining_args