How to use the pulp.server.exceptions.InvalidValue function in PuLP

To help you get started, we’ve selected a few PuLP examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pulp / pulpcore / platform / src / pulp / server / managers / repo / group / distributor.py View on Github external
query_manager = manager_factory.repo_group_query_manager()

        # Validation
        group = query_manager.get_group(repo_group_id) # will raise MissingResource

        if not plugin_api.is_valid_group_distributor(distributor_type_id):
            raise InvalidValue(['distributor_type_id'])

        # Determine the ID for the distributor on this repo
        if distributor_id is None:
            distributor_id = str(uuid.uuid4())
        else:
            # Validate if one was passed in
            if not is_distributor_id_valid(distributor_id):
                raise InvalidValue(['distributor_id'])

        distributor_instance, plugin_config = plugin_api.get_group_distributor_by_id(distributor_type_id)

        # Convention is that a value of None means unset. Remove any keys that
        # are explicitly set to None so the plugin will default them.
        clean_config = None
        if group_plugin_config is not None:
            clean_config = dict([(k, v) for k, v in group_plugin_config.items() if v is not None])

        # Let the plugin validate the configuration
        call_config = PluginCallConfiguration(plugin_config, clean_config)
        transfer_group = common_utils.to_transfer_repo_group(group)
        transfer_group.working_dir = common_utils.distributor_working_dir(distributor_type_id, repo_group_id)

        config_conduit = RepoConfigConduit(distributor_type_id)
github pulp / pulpcore / server / pulp / server / controllers / distributor.py View on Github external
:rtype pulp.server.async.tasks.TaskResult
    """
    repo = model.Repository.objects.get_repo_or_missing_resource(repo_id)
    distributor = model.Distributor.objects.get_or_404(repo_id=repo_id, distributor_id=dist_id)

    for k, v in config.iteritems():
        if v is None:
            distributor.config.pop(k, None)
        else:
            distributor.config[k] = v

    auto_publish = delta.get('auto_publish') if delta else None
    if isinstance(auto_publish, bool):
        distributor.auto_publish = auto_publish
    elif not isinstance(auto_publish, type(None)):
        raise exceptions.InvalidValue(['auto_publish'])

    # Let the distributor plugin verify the configuration
    distributor_instance, plugin_config = plugin_api.get_distributor_by_id(
        distributor.distributor_type_id)
    call_config = PluginCallConfiguration(plugin_config, distributor.config)
    transfer_repo = repo.to_transfer_repo()
    config_conduit = RepoConfigConduit(distributor.distributor_type_id)

    result = distributor_instance.validate_config(transfer_repo, call_config,
                                                  config_conduit)

    # For backward compatibility with plugins that don't yet return the tuple
    if isinstance(result, bool):
        valid_config = result
        message = None
    else:
github pulp / pulp / server / pulp / server / managers / auth / permission / cud.py View on Github external
    @staticmethod
    def delete_permission(resource_uri):
        """
        Deletes the given permission.
        :param resource_uri: identifies the resource URI of the permission being deleted
        :type  resource_uri: str

        :raises MissingResource: if permission for a given resource does not exist
        :raises InvalidValue: if resource URI is invalid
        """

        # Raise exception if resource is invalid
        if resource_uri is None or not isinstance(resource_uri, basestring):
            raise InvalidValue(['resource_uri'])

        # Check whether the permission exists
        found = Permission.get_collection().find_one({'resource' : resource_uri})
        if found is None:
            raise MissingResource(resource_uri)

        Permission.get_collection().remove({'resource' : resource_uri}, safe=True)
github pulp / pulpcore / server / pulp / server / webservices / controllers / consumer_groups.py View on Github external
def POST(self):
        group_data = self.params()
        group_id = group_data.pop('id', None)
        if group_id is None:
            raise pulp_exceptions.MissingValue(['id'])
        display_name = group_data.pop('display_name', None)
        description = group_data.pop('description', None)
        consumer_ids = group_data.pop('consumer_ids', None)
        notes = group_data.pop('notes', None)
        if group_data:
            raise pulp_exceptions.InvalidValue(group_data.keys())
        manager = managers_factory.consumer_group_manager()

        group = manager.create_consumer_group(group_id, display_name, description, consumer_ids,
                                              notes)
        group.update(serialization.link.child_link_obj(group['id']))
        return self.created(group['_href'], group)
github pulp / pulp / server / pulp / server / managers / auth / user / cud.py View on Github external
existing_user = User.get_collection().find_one({'login': login})
        if existing_user is not None:
            raise DuplicateResource(login)

        invalid_values = []

        if login is None or _USER_LOGIN_REGEX.match(login) is None:
            invalid_values.append('login')
        if invalid_type(name, basestring):
            invalid_values.append('name')
        if invalid_type(roles, list):
            invalid_values.append('roles')

        if invalid_values:
            raise InvalidValue(invalid_values)

        # Use the login for name of the user if one was not specified
        name = name or login
        roles = roles or None

        # Encode plain-text password
        hashed_password = None
        if password:
            hashed_password = factory.password_manager().hash_password(password)

        # Creation
        create_me = User(login=login, password=hashed_password, name=name, roles=roles)
        User.get_collection().save(create_me, safe=True)

        # Grant permissions
        permission_manager = factory.permission_manager()
github pulp / pulpcore / server / pulp / server / managers / auth / permission / cud.py View on Github external
    @staticmethod
    def delete_permission(resource_uri):
        """
        Deletes the given permission.
        :param resource_uri: identifies the resource URI of the permission being deleted
        :type  resource_uri: str

        :raises MissingResource: if permission for a given resource does not exist
        :raises InvalidValue: if resource URI is invalid
        """

        # Raise exception if resource is invalid
        if resource_uri is None or not isinstance(resource_uri, basestring):
            raise InvalidValue(['resource_uri'])

        # Check whether the permission exists
        found = Permission.get_collection().find_one({'resource' : resource_uri})
        if found is None:
            raise MissingResource(resource_uri)

        Permission.get_collection().remove({'resource' : resource_uri}, safe=True)
github pulp / pulpcore / platform / src / pulp / server / webservices / controllers / permissions.py View on Github external
def _check_invalid_params(params):
    # Raise InvalidValue if any of the params are None
    
    invalid_values = []
    for key, value in params.items():
        if value is None:
            invalid_values.append(key)

    if invalid_values:
        raise exceptions.InvalidValue(invalid_values)
github pulp / pulp / server / pulp / server / managers / auth / permission / cud.py View on Github external
    @staticmethod
    def delete_permission(resource_uri):
        """
        Deletes the given permission.
        :param resource_uri: identifies the resource URI of the permission being deleted
        :type  resource_uri: str

        :raises MissingResource: if permission for a given resource does not exist
        :raises InvalidValue: if resource URI is invalid
        """

        # Raise exception if resource is invalid
        if resource_uri is None or not isinstance(resource_uri, basestring):
            raise InvalidValue(['resource_uri'])

        # Check whether the permission exists
        found = Permission.get_collection().find_one({'resource': resource_uri})
        if found is None:
            raise MissingResource(resource_uri)

        Permission.get_collection().remove({'resource': resource_uri})
github pulp / pulp / server / pulp / server / db / model / __init__.py View on Github external
def set_password(self, plain_password):
        """
        Sets the user's password to a hashed version of the plain_password. This does not save the
        object.

        :param plain_password: plain password, not hashed.
        :type  plain_password: str

        :raises pulp_exceptions.InvalidValue: if password is not a string
        """
        if plain_password is not None and not isinstance(plain_password, basestring):
            raise exceptions.InvalidValue('password')
        self.password = self._hash_password(plain_password)