def post(self, request): """ Create a consumer group and return a serialized object containing just created group. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :return: Response containing the consumer group :rtype: django.http.HttpResponse :raises: MissingValue if group ID is not provided :raises: InvalidValue if some parameters are invalid """ params = request.body_as_json group_id = params.pop('id', None) if group_id is None: raise pulp_exceptions.MissingValue(['id']) display_name = params.pop('display_name', None) description = params.pop('description', None) consumer_ids = params.pop('consumer_ids', None) notes = params.pop('notes', None) if params: raise pulp_exceptions.InvalidValue(params.keys()) manager = factory.consumer_group_manager() group = manager.create_consumer_group(group_id, display_name, description, consumer_ids, notes) link = {"_href": reverse('consumer_group_resource', kwargs={'consumer_group_id': group['id']})} group.update(link) response = generate_json_response_with_pulp_encoder(group) response_redirect = generate_redirect_response(response, link['_href']) return response_redirect
def create_sync_schedule(self, repo_id, importer_id, sync_options, schedule_data): """ Create a new sync schedule for a given repository using the given importer. @param repo_id: @param importer_id: @param sync_options: @param schedule_data: @return: """ # validate the input self._validate_importer(repo_id, importer_id) schedule_utils.validate_keys(sync_options, _SYNC_OPTION_KEYS) if 'schedule' not in schedule_data: raise pulp_exceptions.MissingValue(['schedule']) # build the sync call request args = [repo_id] kwargs = {'overrides': sync_options['override_config']} call_request = CallRequest(sync_with_auto_publish_itinerary, args, kwargs, weight=0) # schedule the sync scheduler = dispatch_factory.scheduler() schedule_id = scheduler.add(call_request, **schedule_data) importer_manager = managers_factory.repo_importer_manager() importer_manager.add_sync_schedule(repo_id, schedule_id) return schedule_id
def POST(self, repo_id): # Params params = self.params() query = params.get('criteria', None) repo_query_manager = manager_factory.repo_query_manager() repo = repo_query_manager.find_by_id(repo_id) if repo is None: raise exceptions.MissingResource(repo_id=repo_id) if query is None: raise exceptions.MissingValue(['criteria']) try: criteria = UnitAssociationCriteria.from_client_input(query) except: _logger.error('Error parsing association criteria [%s]' % query) raise exceptions.PulpDataException(), None, sys.exc_info()[2] # Data lookup manager = manager_factory.repo_unit_association_query_manager() if criteria.type_ids is not None and len(criteria.type_ids) == 1: type_id = criteria.type_ids[0] units = manager.get_units_by_type(repo_id, type_id, criteria=criteria) else: units = manager.get_units_across_types(repo_id, criteria=criteria) return self.ok(units)
def POST(self, repo_id): # Params (validation will occur in the manager) params = self.params() importer_type = params.get('importer_type_id', None) importer_config = params.get('importer_config', None) if importer_type is None: _logger.error( 'Missing importer type adding importer to repository [%s]' % repo_id) raise exceptions.MissingValue(['importer_type']) # Note: If an importer exists, it's removed, so no need to handle 409s. # Note: If the plugin raises an exception during initialization, let it # bubble up and be handled like any other 500. task_tags = [ tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, repo_id), tags.action_tag('add_importer') ] async_result = set_importer.apply_async_with_reservation( tags.RESOURCE_REPOSITORY_TYPE, repo_id, [repo_id, importer_type], {'repo_plugin_config': importer_config}, tags=task_tags) raise exceptions.OperationPostponed(async_result)
def post(self, request, repo_group_id): """ Dispatch a task to publish content from the repo group using the distributor specified by the params. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :param repo_group_id: repo group to publish :type repo_group_id: str :raises pulp_exceptions.MissingValue if 'id' is not passed in the body :raises pulp_exceptions.OperationPosponed: dispatch a task """ params = request.body_as_json distributor_id = params.get('id', None) overrides = params.get('override_config', None) if distributor_id is None: raise pulp_exceptions.MissingValue(['id']) # If a repo group does not exist, get_group raises a MissingResource exception manager = managers_factory.repo_group_query_manager() manager.get_group(repo_group_id) task_tags = [ tags.resource_tag(tags.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id), tags.resource_tag(tags.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE, distributor_id), tags.action_tag('publish') ] async_result = repo_group_publish.apply_async_with_reservation( tags.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id, args=[repo_group_id, distributor_id], kwargs={'publish_config_override': overrides}, tags=task_tags) raise pulp_exceptions.OperationPostponed(async_result)
def post(self, request): """ Create a repo group from the data passed in the body. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :return: Response containing a serialized dict of the new repo group :rtype: django.http.HttpResponse :raises pulp_exceptions.MissingValue: if required values are not passed into the body :raises pulp_exceptions.InvalidValue: if invalid values are passed into the body """ group_data = request.body_as_json 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) repo_ids = group_data.pop('repo_ids', None) notes = group_data.pop('notes', None) distributors = group_data.pop('distributors', None) if group_data: raise pulp_exceptions.InvalidValue(group_data.keys()) # Create the repo group manager = managers_factory.repo_group_manager() args = [group_id, display_name, description, repo_ids, notes] kwargs = {'distributor_list': distributors} group = manager.create_and_configure_repo_group(*args, **kwargs) group = _add_group_link(group) group['distributors'] = distributors or [] response = generate_json_response_with_pulp_encoder(group) return generate_redirect_response(response, group['_href'])
def create_publish_schedule(self, repo_id, distributor_id, publish_options, schedule_data): """ Create a new scheduled publish for the given repository and distributor. @param repo_id: @param distributor_id: @param publish_options: @param schedule_data: @return: """ # validate the input self._validate_distributor(repo_id, distributor_id) schedule_utils.validate_keys(publish_options, _PUBLISH_OPTION_KEYS) if 'schedule' not in schedule_data: raise pulp_exceptions.MissingValue(['schedule']) # build the publish call args = [repo_id, distributor_id] kwargs = {'overrides': publish_options['override_config']} call_request = CallRequest(publish_itinerary, args, kwargs, weight=0) # schedule the publish scheduler = dispatch_factory.scheduler() schedule_id = scheduler.add(call_request, **schedule_data) distributor_manager = managers_factory.repo_distributor_manager() distributor_manager.add_publish_schedule(repo_id, distributor_id, schedule_id) return schedule_id
def put(self, request, repo_group_id, distributor_id): """ Change information about a single repo group distributor association. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :param repo_group_id: repo group the distributor is associated with :type repo_group_id: str :param distributor_id: distributor to update :type distributor_id: str :return: response containing a serialized dict of the modified distributor association :rtype: django.http.HttpResponse :raises pulp_exceptions.MissingValue: if param 'distributor_config' is not in the body """ params = request.body_as_json distributor_config = params.get('distributor_config', None) if distributor_config is None: raise pulp_exceptions.MissingValue(['distributor_config']) distributor_manager = managers_factory.repo_group_distributor_manager() result = distributor_manager.update_distributor_config( repo_group_id, distributor_id, distributor_config) result['_href'] = reverse('repo_group_distributor_resource', kwargs={ 'repo_group_id': repo_group_id, 'distributor_id': distributor_id }) return generate_json_response_with_pulp_encoder(result)
def POST(self, repo_id): # Params (validation will occur in the manager) params = self.params() importer_type = params.get('importer_type_id', None) importer_config = params.get('importer_config', None) if importer_type is None: _LOG.error( 'Missing importer type adding importer to repository [%s]' % repo_id) raise exceptions.MissingValue(['importer_type']) # Note: If an importer exists, it's removed, so no need to handle 409s. # Note: If the plugin raises an exception during initialization, let it # bubble up and be handled like any other 500. importer_manager = manager_factory.repo_importer_manager() weight = pulp_config.config.getint('tasks', 'create_weight') tags = [ resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id), action_tag('add_importer') ] call_request = CallRequest(importer_manager.set_importer, [repo_id, importer_type], {'repo_plugin_config': importer_config}, weight=weight, tags=tags, kwarg_blacklist=['repo_plugin_config']) call_request.updates_resource( dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id) return execution.execute_sync_created(self, call_request, 'importer')
def PUT(self, repo_group_id, distributor_id): params = self.params() distributor_config = params.get('distributor_config', None) if distributor_config is None: raise pulp_exceptions.MissingValue(['distributor_config']) distributor_manager = managers_factory.repo_group_distributor_manager() resources = { dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE : {repo_group_id : dispatch_constants.RESOURCE_UPDATE_OPERATION}, dispatch_constants.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE : {distributor_id : dispatch_constants.RESOURCE_UPDATE_OPERATION}, } tags = [resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_TYPE, repo_group_id), resource_tag(dispatch_constants.RESOURCE_REPOSITORY_GROUP_DISTRIBUTOR_TYPE, distributor_id), action_tag('update_distributor') ] call_request = CallRequest(distributor_manager.update_distributor_config, args=[repo_group_id, distributor_id, distributor_config], resources=resources, tags=tags, archive=True) result = execution.execute(call_request) href = serialization.link.current_link_obj() result.update(href) return self.ok(result)
def PUT(self, repo_id, importer_id): # Params (validation will occur in the manager) params = self.params() importer_config = params.get('importer_config', None) if importer_config is None: _LOG.error( 'Missing configuration updating importer for repository [%s]' % repo_id) raise exceptions.MissingValue(['importer_config']) importer_manager = manager_factory.repo_importer_manager() tags = [ resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id), resource_tag(dispatch_constants.RESOURCE_REPOSITORY_IMPORTER_TYPE, importer_id), action_tag('update_importer') ] call_request = CallRequest(importer_manager.update_importer_config, [repo_id], {'importer_config': importer_config}, tags=tags, archive=True, kwarg_blacklist=['importer_config']) call_request.updates_resource( dispatch_constants.RESOURCE_REPOSITORY_TYPE, repo_id) call_request.updates_resource( dispatch_constants.RESOURCE_REPOSITORY_IMPORTER_TYPE, importer_id) result = execution.execute(call_request) return self.ok(result)
def post(self, request): """ Dispatch a task to regenerate content applicability data for repositories that match the criteria passed in the body. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :raises exceptions.MissingValue: if repo_critera is not a body parameter :raises exceptions.InvalidValue: if repo_critera (dict) has unsupported keys, the manager will raise an InvalidValue for the specific keys. Here, we create a parent exception for repo_criteria and include the specific keys as child exceptions. :raises exceptions.OperationPostponed: dispatch a task """ class GroupCallReport(dict): def serialize(self): return self repo_criteria_body = request.body_as_json.get('repo_criteria', None) if repo_criteria_body is None: raise exceptions.MissingValue('repo_criteria') try: repo_criteria = Criteria.from_client_input(repo_criteria_body) except exceptions.InvalidValue, e: invalid_criteria = exceptions.InvalidValue('repo_criteria') invalid_criteria.add_child_exception(e) raise invalid_criteria
def PUT(self, repo_id, importer_id): # Raise a MissingResource exception if the repo or the importer doesn't exist importer_manager = manager_factory.repo_importer_manager() importer = importer_manager.get_importer(repo_id) if importer['id'] != importer_id: raise exceptions.MissingResource(importer_id=importer_id) if not plugin_api.is_valid_importer(importer_id): raise exceptions.PulpCodedValidationException( error_code=error_codes.PLP1008) params = self.params() importer_config = params.get('importer_config', None) if importer_config is None: _logger.error( 'Missing configuration updating importer for repository [%s]' % repo_id) raise exceptions.MissingValue(['importer_config']) task_tags = [ tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, repo_id), tags.resource_tag(tags.RESOURCE_REPOSITORY_IMPORTER_TYPE, importer_id), tags.action_tag('update_importer') ] async_result = update_importer_config.apply_async_with_reservation( tags.RESOURCE_REPOSITORY_TYPE, repo_id, [repo_id], {'importer_config': importer_config}, tags=task_tags) raise exceptions.OperationPostponed(async_result)
def post(self, request, repo_id): """ Associate a distributor with a repository. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :param repo_id: The id of the repository to associate with :type repo_id: basestring :return: Response containing the serialized distributor :rtype : django.http.HttpResponse """ distributor_type = request.body_as_json.get('distributor_type_id') if distributor_type is None: raise exceptions.MissingValue('distributor_type_id') distributor_config = request.body_as_json.get('distributor_config') distributor_id = request.body_as_json.get('distributor_id') auto_publish = request.body_as_json.get('auto_publish', False) distributor = dist_controller.add_distributor(repo_id, distributor_type, distributor_config, auto_publish, distributor_id) serialized = model.Distributor.serializer(distributor).data response = generate_json_response_with_pulp_encoder(serialized) return generate_redirect_response(response, serialized['_href'])
def put(self, request, repo_id, importer_id): """ Associate an importer to a repository. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :param repo_id: The id of the repository :type repo_id: str :param importer_id: The id of the importer to associate :type importer_id: str :raises exceptions.MissingValue: if required param importer_config is not in the body :raises exceptions.MissingResource: if importer does not match the repo's importer :raises exceptions.OperationPostponed: dispatch a task """ importer_controller.get_valid_importer(repo_id, importer_id) importer_config = request.body_as_json.get('importer_config', None) if importer_config is None: raise exceptions.MissingValue(['importer_config']) async_result = importer_controller.queue_update_importer_config(repo_id, importer_id, importer_config) raise exceptions.OperationPostponed(async_result)
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() weight = pulp_config.config.getint('tasks', 'create_weight') tags = [ resource_tag(dispatch_constants.RESOURCE_CONSUMER_GROUP_TYPE, group_id) ] call_request = CallRequest( manager.create_consumer_group, [group_id, display_name, description, consumer_ids, notes], weight=weight, tags=tags) call_request.creates_resource( dispatch_constants.RESOURCE_CONSUMER_GROUP_TYPE, group_id) group = execution.execute_sync(call_request) group.update(serialization.link.child_link_obj(group['id'])) return self.created(group['_href'], group)
def post(self, request, dest_repo_id): """ Associate units matching the criteria into the given repository :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :param dest_repo_id: id of the repository content will be copied to :type dest_repo_id: str :raises exceptions.MissingValue: if required param source_repo_id is not passed :raises exceptions.InvalidValue: if source_repo_id is not found or if criteria params cannot be parsed :raises exceptions.OperationPostponed: dispatch a publish repo task """ model.Repository.objects.get_repo_or_missing_resource(dest_repo_id) criteria_body = request.body_as_json.get('criteria', {}) overrides = request.body_as_json.get('override_config', None) source_repo_id = request.body_as_json.get('source_repo_id', None) if source_repo_id is None: raise exceptions.MissingValue(['source_repo_id']) # Catch MissingResource because this is body data, raise 400 rather than 404 try: model.Repository.objects.get_repo_or_missing_resource(source_repo_id) except exceptions.MissingResource: raise exceptions.InvalidValue(['source_repo_id']) try: criteria = UnitAssociationCriteria.from_client_input(criteria_body) except exceptions.InvalidValue, e: invalid_criteria = exceptions.InvalidValue('criteria') invalid_criteria.add_child_exception(e) raise invalid_criteria
def POST(self, dest_repo_id): # Params params = self.params() source_repo_id = params.get('source_repo_id', None) overrides = params.get('override_config', None) if source_repo_id is None: raise exceptions.MissingValue(['source_repo_id']) # A 404 only applies to things in the URL, so the destination repo # check allows the MissingResource to bubble up, but if the source # repo doesn't exist, it's considered bad data. repo_query_manager = manager_factory.repo_query_manager() repo_query_manager.get_repository(dest_repo_id) try: repo_query_manager.get_repository(source_repo_id) except exceptions.MissingResource: raise exceptions.InvalidValue(['source_repo_id']) criteria = params.get('criteria', None) if criteria is not None: try: criteria = UnitAssociationCriteria.from_client_input(criteria) except: _LOG.error('Error parsing association criteria [%s]' % criteria) raise exceptions.PulpDataException(), None, sys.exc_info()[2] association_manager = manager_factory.repo_unit_association_manager() tags = [ resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, dest_repo_id), resource_tag(dispatch_constants.RESOURCE_REPOSITORY_TYPE, source_repo_id), action_tag('associate') ] call_request = CallRequest( association_manager.associate_from_repo, [source_repo_id, dest_repo_id], { 'criteria': criteria, 'import_config_override': overrides }, tags=tags, archive=True, kwarg_blacklist=['criteria', 'import_config_override']) call_request.reads_resource( dispatch_constants.RESOURCE_REPOSITORY_TYPE, source_repo_id) call_request.updates_resource( dispatch_constants.RESOURCE_REPOSITORY_TYPE, dest_repo_id) return execution.execute_async(self, call_request)
def PUT(self, repo_id, distributor_id): params = self.params() # validate manager = manager_factory.repo_distributor_manager() manager.get_distributor(repo_id, distributor_id) config = params.get('distributor_config') if config is None: _LOG.error( 'Missing configuration when updating distributor [%s] on repository [%s]', distributor_id, repo_id) raise exceptions.MissingValue(['distributor_config']) # update call_requests = distributor_update_itinerary(repo_id, distributor_id, config) execution.execute_multiple(call_requests)
def _validate_params(params): """ Raise MissingValue if any of the required params are None. :param params: parameters to be checked :type: dict :raises: MissingValue if some params are None """ missing_values = [] for key, value in params.items(): if value is None: missing_values.append(key) if missing_values: raise pulp_exceptions.MissingValue(missing_values)
def post(self, request, *args, **kwargs): """ Search for objects using an HTTP POST request. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :return: HttpReponse containing a list of objects that were matched by the request :rtype: django.http.HttpResponse :raises MissingValue: if required param `criteria` is not passed in the body. """ search_params, options = self._parse_args(request.body_as_json) query = search_params.get('criteria') if query is None: raise exceptions.MissingValue(['criteria']) return self._generate_response(query, options, *args, **kwargs)
def PUT(self, repo_group_id, distributor_id): params = self.params() distributor_config = params.get('distributor_config', None) if distributor_config is None: raise pulp_exceptions.MissingValue(['distributor_config']) distributor_manager = managers_factory.repo_group_distributor_manager() result = distributor_manager.update_distributor_config(repo_group_id, distributor_id, distributor_config) href = serialization.link.current_link_obj() result.update(href) return self.ok(result)
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)
def post(self, request, repo_id): """ Import an uploaded unit into the given repository. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :param repo_id: The id of the repository the upload should be imported into :type repo_id: str :raises exceptions.OperationPostponed: dispatch a importy_uploaded_unit task """ try: upload_id = request.body_as_json['upload_id'] unit_type_id = request.body_as_json['unit_type_id'] unit_key = request.body_as_json['unit_key'] except KeyError, e: raise exceptions.MissingValue(e.args[0])
def post(self, request): """ Search for objects using an HTTP POST request. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :return: HttpReponse containing a list of objects that were matched by the request :rtype: django.http.HttpResponse :raises MissingValue: if required param `criteria` is not passed in the body. """ try: # Retrieve the criteria from the POST data query = request.body_as_json['criteria'] except KeyError: raise exceptions.MissingValue(['criteria']) return self._generate_response(query)
def POST(self, dest_repo_id): # Params params = self.params() source_repo_id = params.get('source_repo_id', None) overrides = params.get('override_config', None) if source_repo_id is None: raise exceptions.MissingValue(['source_repo_id']) # A 404 only applies to things in the URL, so the destination repo # check allows the MissingResource to bubble up, but if the source # repo doesn't exist, it's considered bad data. repo_query_manager = manager_factory.repo_query_manager() repo_query_manager.get_repository(dest_repo_id) try: repo_query_manager.get_repository(source_repo_id) except exceptions.MissingResource: raise exceptions.InvalidValue(['source_repo_id']) criteria = params.get('criteria', None) if criteria is not None: try: criteria = UnitAssociationCriteria.from_client_input(criteria) except: _logger.error('Error parsing association criteria [%s]' % criteria) raise exceptions.PulpDataException(), None, sys.exc_info()[2] task_tags = [ tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, dest_repo_id), tags.resource_tag(tags.RESOURCE_REPOSITORY_TYPE, source_repo_id), tags.action_tag('associate') ] async_result = associate_from_repo.apply_async_with_reservation( tags.RESOURCE_REPOSITORY_TYPE, dest_repo_id, [source_repo_id, dest_repo_id], { 'criteria': criteria, 'import_config_override': overrides }, tags=task_tags) raise exceptions.OperationPostponed(async_result)
def _get_query_results_from_post(self, is_user_search=False): """ Looks for a Criteria passed as a POST parameter on ket 'criteria', and returns the results of a search based on that Criteria. @return: list of documents from the DB that match the given criteria for the collection associated with this controller @rtype: list """ try: criteria_param = self.params()['criteria'] except KeyError: raise exceptions.MissingValue(['criteria']) criteria = Criteria.from_client_input(criteria_param) if criteria.fields: if not is_user_search and 'id' not in criteria.fields and u'id' not in criteria.fields: criteria.fields.append('id') if is_user_search and 'login' not in criteria.fields and u'login' not in criteria.fields: criteria.fields.append('login') return list(self.query_method(criteria))
def post(self, request, repo_id): """ Dispatch a task to publish a repository. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :param repo_id: id of the repository to publish :type repo_id: str :raises exceptions.MissingResource: if repo does not exist :raises exceptions.MissingValue: if required param id is not passed :raises exceptions.OperationPostponed: dispatch a publish repo task """ model.Repository.objects.get_repo_or_missing_resource(repo_id) distributor_id = request.body_as_json.get('id', None) if distributor_id is None: raise exceptions.MissingValue('id') overrides = request.body_as_json.get('override_config', None) async_result = repo_controller.queue_publish(repo_id, distributor_id, overrides) raise exceptions.OperationPostponed(async_result)
def post(self, request): """ Create a new user. :param request: WSGI request object :type request: django.core.handlers.wsgi.WSGIRequest :return: Response containing the user :rtype: django.http.HttpResponse :raises: MissingValue if login field is missing :raises: InvalidValue if some parameters are invalid """ user_data = request.body_as_json login = user_data.pop('login', None) if login is None: raise pulp_exceptions.MissingValue(['login']) password = user_data.pop('password', None) # name defaults to login name = user_data.pop('name', login) # Raise if extra data is passed if user_data: raise pulp_exceptions.InvalidValue(user_data.keys()) new_user = user_controller.create_user(login, password=password, name=name) serialized_user = model.User.SERIALIZER(new_user).data # For backwards compatability. See https://pulp.plan.io/issues/1125 serialized_user['id'] = str(serialized_user['_id']) # Grant permissions permission_manager = factory.permission_manager() permission_manager.grant_automatic_permissions_for_resource( serialized_user['_href']) response = generate_json_response_with_pulp_encoder(serialized_user) return generate_redirect_response(response, serialized_user['_href'])
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) repo_ids = group_data.pop('repo_ids', None) notes = group_data.pop('notes', None) distributors = group_data.pop('distributors', None) if group_data: raise pulp_exceptions.InvalidValue(group_data.keys()) # Create the repo group manager = managers_factory.repo_group_manager() args = [group_id, display_name, description, repo_ids, notes] kwargs = {'distributor_list': distributors} group = manager.create_and_configure_repo_group(*args, **kwargs) group.update(serialization.link.child_link_obj(group['id'])) group['distributors'] = distributors or [] return self.created(group['_href'], group)