Esempio n. 1
0
    def post(self, request):
        """
        Create a new repo. `id` field in body is required. `display_name` will default to `id`.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest

        :return: Response containing a serialized dict for the created repo.
        :rtype : django.http.HttpResponse
        """
        repo_data = request.body_as_json
        repo_id = repo_data.get('id')

        repo_obj = repo_controller.create_repo(
            repo_id,
            display_name=repo_data.get('display_name', repo_id),
            description=repo_data.get('description'),
            notes=repo_data.get('notes'),
            importer_type_id=repo_data.get('importer_type_id'),
            importer_repo_plugin_config=repo_data.get('importer_config'),
            distributor_list=repo_data.get('distributors')
        )

        repo = serializers.Repository(repo_obj).data
        response = generate_json_response_with_pulp_encoder(repo)
        return generate_redirect_response(response, repo['_href'])
Esempio n. 2
0
    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'])
Esempio n. 3
0
    def post(self, request, repo_id, distributor_id):
        """
        Create a new scheduled publish.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_id: id of the repository
        :type  repo_id: str
        :param distributor_id: id of the distributor
        :type  distributor_id: str

        :return: Response containing a dict for the new scheduled publish
        :rtype : django.http.HttpResponse
        :raises exceptions.UnsupportedValue: if unsupported fields are included in body
        """

        manager = manager_factory.repo_publish_schedule_manager()
        publish_options = {'override_config': request.body_as_json.pop('override_config', {})}
        schedule = request.body_as_json.pop('schedule', None)
        failure_threshold = request.body_as_json.pop('failure_threshold', None)
        enabled = request.body_as_json.pop('enabled', True)
        if request.body_as_json:
            raise exceptions.UnsupportedValue(request.body_as_json.keys())

        schedule = manager.create(repo_id, distributor_id, publish_options,
                                  schedule, failure_threshold, enabled)
        ret = schedule.for_display()
        ret['_href'] = reverse('repo_publish_schedule_resource', kwargs={
            'repo_id': repo_id, 'distributor_id': distributor_id, 'schedule_id': schedule.id
        })
        response = generate_json_response_with_pulp_encoder(ret)
        return generate_redirect_response(response, ret['_href'])
Esempio n. 4
0
    def post(self, request):
        """
        Create a new repo. `id` field in body is required. `display_name` will default to `id`.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest

        :return: Response containing a serialized dict for the created repo.
        :rtype : django.http.HttpResponse
        """
        repo_data = request.body_as_json
        repo_id = repo_data.get('id')

        repo_obj = repo_controller.create_repo(
            repo_id,
            display_name=repo_data.get('display_name', repo_id),
            description=repo_data.get('description'),
            notes=repo_data.get('notes'),
            importer_type_id=repo_data.get('importer_type_id'),
            importer_repo_plugin_config=repo_data.get('importer_config'),
            distributor_list=repo_data.get('distributors')
        )

        repo = serializers.Repository(repo_obj).data
        response = generate_json_response_with_pulp_encoder(repo)
        return generate_redirect_response(response, repo['_href'])
Esempio n. 5
0
    def post(self, request, repo_id, importer_id):
        """
        Create a new scheduled sync.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_id: id of the repository
        :type  repo_id: str
        :param importer_id: create a new scheduled sync for this importer
        :type  importer_id: str

        :return: Response containing a serialized dict of the new  scheduled sync
        :rtype : django.http.HttpResponse
        :raises exceptions.UnsupportedValue: if there are unsupported request body params
        """

        manager = manager_factory.repo_sync_schedule_manager()
        sync_options = {'override_config': request.body_as_json.pop('override_config', {})}
        schedule = request.body_as_json.pop('schedule', None)
        failure_threshold = request.body_as_json.pop('failure_threshold', None)
        enabled = request.body_as_json.pop('enabled', True)
        if request.body_as_json:
            raise exceptions.UnsupportedValue(request.body_as_json.keys())

        scheduled_call = manager.create(repo_id, importer_id, sync_options,
                                        schedule, failure_threshold, enabled)
        display_call = scheduled_call.for_display()
        display_call['_href'] = reverse(
            'repo_sync_schedule_resource',
            kwargs={'repo_id': repo_id, 'importer_id': importer_id,
                    'schedule_id': scheduled_call['id']}
        )
        response = generate_json_response(display_call)
        return generate_redirect_response(response, display_call['_href'])
Esempio n. 6
0
    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: str

        :return: Response containing a dict of the associated distributor
        :rtype : django.http.HttpResponse
        """

        # Validation will occur in the manager
        distributor_type = request.body_as_json.get('distributor_type_id', None)
        distributor_config = request.body_as_json.get('distributor_config', None)
        distributor_id = request.body_as_json.get('distributor_id', None)
        auto_publish = request.body_as_json.get('auto_publish', False)

        distributor_manager = manager_factory.repo_distributor_manager()
        distributor = distributor_manager.add_distributor(
            repo_id, distributor_type, distributor_config, auto_publish, distributor_id
        )
        distributor['_href'] = reverse(
            'repo_distributor_resource',
            kwargs={'repo_id': repo_id, 'distributor_id': distributor['id']}
        )
        response = generate_json_response_with_pulp_encoder(distributor)
        return generate_redirect_response(response, distributor['_href'])
Esempio n. 7
0
    def post(self, request):
        """
        Create a new repo. 'id' field in body is required.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest

        :return: Response containing a serialized dict for the created repo.
        :rtype : django.http.HttpResponse
        """

        # Pull the repo data out of the request body (validation will occur
        # in the manager)
        repo_data = request.body_as_json
        repo_id = repo_data.get('id', None)
        display_name = repo_data.get('display_name', None)
        description = repo_data.get('description', None)
        notes = repo_data.get('notes', None)

        importer_type_id = repo_data.get('importer_type_id', None)
        importer_repo_plugin_config = repo_data.get('importer_config', None)
        distributors = repo_data.get('distributors', None)

        # Creation
        repo_manager = manager_factory.repo_manager()
        args = [repo_id, display_name, description, notes]
        kwargs = {'importer_type_id': importer_type_id,
                  'importer_repo_plugin_config': importer_repo_plugin_config,
                  'distributor_list': distributors}
        repo = repo_manager.create_and_configure_repo(*args, **kwargs)
        repo['_href'] = reverse('repo_resource', kwargs={'repo_id': repo_id})
        response = generate_json_response_with_pulp_encoder(repo)
        return generate_redirect_response(response, repo['_href'])
Esempio n. 8
0
    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
Esempio n. 9
0
    def post(self, request, repo_id, importer_id):
        """
        Create a new scheduled sync.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_id: id of the repository
        :type  repo_id: str
        :param importer_id: create a new scheduled sync for this importer
        :type  importer_id: str

        :return: Response containing a serialized dict of the new  scheduled sync
        :rtype : django.http.HttpResponse
        :raises exceptions.UnsupportedValue: if there are unsupported request body params
        """

        manager = manager_factory.repo_sync_schedule_manager()
        sync_options = {'override_config': request.body_as_json.pop('override_config', {})}
        schedule = request.body_as_json.pop('schedule', None)
        failure_threshold = request.body_as_json.pop('failure_threshold', None)
        enabled = request.body_as_json.pop('enabled', True)
        if request.body_as_json:
            raise exceptions.UnsupportedValue(request.body_as_json.keys())

        scheduled_call = manager.create(repo_id, importer_id, sync_options,
                                        schedule, failure_threshold, enabled)
        display_call = scheduled_call.for_display()
        display_call['_href'] = reverse(
            'repo_sync_schedule_resource',
            kwargs={'repo_id': repo_id, 'importer_id': importer_id,
                    'schedule_id': scheduled_call['id']}
        )
        response = generate_json_response(display_call)
        return generate_redirect_response(response, display_call['_href'])
Esempio n. 10
0
    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'])
Esempio n. 11
0
    def post(self, request, consumer_id):
        """
        Associate a profile with a consumer by content type ID.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest
        :param consumer_id: A consumer ID.
        :type consumer_id: str

        :raises MissingValue: if some parameter were not provided

        :return: Response representing the created profile
        :rtype: django.http.HttpResponse
        """

        body = request.body_as_json
        content_type = body.get('content_type')
        profile = body.get('profile')

        manager = factory.consumer_profile_manager()
        new_profile = manager.create(consumer_id, content_type, profile)
        if content_type is None:
            raise MissingValue('content_type')
        link = add_link_profile(new_profile)
        response = generate_json_response_with_pulp_encoder(new_profile)
        redirect_response = generate_redirect_response(response, link['_href'])
        return redirect_response
Esempio n. 12
0
    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'])
Esempio n. 13
0
    def post(self, request, repo_group_id):
        """
        Asssociate a distributor with a repo group.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_group_id: matching distributors will be associated with this repo group
        :type  repo_group_id: str

        :return: response containing a serialized dict of the distributor association
        :rtype: django.http.HttpResponse
        """
        # Params (validation will occur in the manager)
        params = request.body_as_json
        distributor_type_id = params.get(distributor_constants.DISTRIBUTOR_TYPE_ID_KEY, None)
        distributor_config = params.get(distributor_constants.DISTRIBUTOR_CONFIG_KEY, None)
        distributor_id = params.get(distributor_constants.DISTRIBUTOR_ID_KEY, None)
        distributor_manager = managers_factory.repo_group_distributor_manager()
        created = distributor_manager.add_distributor(repo_group_id, distributor_type_id,
                                                      distributor_config, distributor_id)
        created['_href'] = reverse('repo_group_distributor_resource',
                                   kwargs={'repo_group_id': repo_group_id,
                                           'distributor_id': created['id']})
        response = generate_json_response_with_pulp_encoder(created)
        return generate_redirect_response(response, created['_href'])
Esempio n. 14
0
    def post(self, request, consumer_id):
        """
        Create a schedule.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest
        :param consumer_id: The consumer ID.
        :type consumer_id: str

        :raises UnsupportedValue: if some extra unsupported keys were specified.

        :return: Response containing just created schedule
        :rtype: django.http.HttpResponse
        """

        params = request.body_as_json
        units = params.pop('units', None)
        options = params.pop('options', {})
        schedule = params.pop('schedule', None)
        failure_threshold = params.pop('failure_threshold', None)
        enabled = params.pop('enabled', True)
        if params:
            raise UnsupportedValue(params.keys())
        scheduled_call = self.manager.create_schedule(
            self.ACTION, consumer_id, units, options, schedule, failure_threshold, enabled)

        scheduled_obj = scheduled_unit_management_obj(scheduled_call.for_display())
        link = add_link_schedule(scheduled_obj, self.ACTION, consumer_id)
        response = generate_json_response_with_pulp_encoder(scheduled_obj)
        redirect_response = generate_redirect_response(response, link['_href'])
        return redirect_response
Esempio n. 15
0
    def post(self, request, consumer_id):
        """
        Create a schedule.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest
        :param consumer_id: The consumer ID.
        :type consumer_id: str

        :raises UnsupportedValue: if some extra unsupported keys were specified.

        :return: Response containing just created schedule
        :rtype: django.http.HttpResponse
        """

        params = request.body_as_json
        units = params.pop('units', None)
        options = params.pop('options', {})
        schedule = params.pop('schedule', None)
        failure_threshold = params.pop('failure_threshold', None)
        enabled = params.pop('enabled', True)
        if params:
            raise UnsupportedValue(params.keys())
        scheduled_call = self.manager.create_schedule(self.ACTION, consumer_id,
                                                      units, options, schedule,
                                                      failure_threshold,
                                                      enabled)

        scheduled_obj = scheduled_unit_management_obj(
            scheduled_call.for_display())
        link = add_link_schedule(scheduled_obj, self.ACTION, consumer_id)
        response = generate_json_response_with_pulp_encoder(scheduled_obj)
        redirect_response = generate_redirect_response(response, link['_href'])
        return redirect_response
Esempio n. 16
0
    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
Esempio n. 17
0
    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'])
Esempio n. 18
0
    def post(self, request, repo_group_id):
        """
        Asssociate a distributor with a repo group.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_group_id: matching distributors will be associated with this repo group
        :type  repo_group_id: str

        :return: response containing a serialized dict of the distributor association
        :rtype: django.http.HttpResponse
        """
        # Params (validation will occur in the manager)
        params = request.body_as_json
        distributor_type_id = params.get(
            distributor_constants.DISTRIBUTOR_TYPE_ID_KEY, None)
        distributor_config = params.get(
            distributor_constants.DISTRIBUTOR_CONFIG_KEY, None)
        distributor_id = params.get(distributor_constants.DISTRIBUTOR_ID_KEY,
                                    None)
        distributor_manager = managers_factory.repo_group_distributor_manager()
        created = distributor_manager.add_distributor(repo_group_id,
                                                      distributor_type_id,
                                                      distributor_config,
                                                      distributor_id)
        created['_href'] = reverse('repo_group_distributor_resource',
                                   kwargs={
                                       'repo_group_id': repo_group_id,
                                       'distributor_id': created['id']
                                   })
        response = generate_json_response_with_pulp_encoder(created)
        return generate_redirect_response(response, created['_href'])
Esempio n. 19
0
    def post(self, request, consumer_id):
        """
        Associate a profile with a consumer by content type ID.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest
        :param consumer_id: A consumer ID.
        :type consumer_id: str

        :raises MissingValue: if some parameter were not provided

        :return: Response representing the created profile
        :rtype: django.http.HttpResponse
        """

        body = request.body_as_json
        content_type = body.get('content_type')
        profile = body.get('profile')

        manager = factory.consumer_profile_manager()
        new_profile = manager.create(consumer_id, content_type, profile)
        if content_type is None:
            raise MissingValue('content_type')
        link = add_link_profile(new_profile)
        response = generate_json_response_with_pulp_encoder(new_profile)
        redirect_response = generate_redirect_response(response, link['_href'])
        return redirect_response
Esempio n. 20
0
    def post(self, request, repo_id, distributor_id):
        """
        Create a new scheduled publish.

        :param request: WSGI request object
        :type  request: django.core.handlers.wsgi.WSGIRequest
        :param repo_id: id of the repository
        :type  repo_id: str
        :param distributor_id: id of the distributor
        :type  distributor_id: str

        :return: Response containing a dict for the new scheduled publish
        :rtype : django.http.HttpResponse
        :raises exceptions.UnsupportedValue: if unsupported fields are included in body
        """

        manager = manager_factory.repo_publish_schedule_manager()
        publish_options = {'override_config': request.body_as_json.pop('override_config', {})}
        schedule = request.body_as_json.pop('schedule', None)
        failure_threshold = request.body_as_json.pop('failure_threshold', None)
        enabled = request.body_as_json.pop('enabled', True)
        if request.body_as_json:
            raise exceptions.UnsupportedValue(request.body_as_json.keys())

        schedule = manager.create(repo_id, distributor_id, publish_options,
                                  schedule, failure_threshold, enabled)
        ret = schedule.for_display()
        ret['_href'] = reverse('repo_publish_schedule_resource', kwargs={
            'repo_id': repo_id, 'distributor_id': distributor_id, 'schedule_id': schedule.id
        })
        response = generate_json_response_with_pulp_encoder(ret)
        return generate_redirect_response(response, ret['_href'])
Esempio n. 21
0
 def test_generate_redirect_response(self, mock_iri_to_uri):
     """
     Test HttpResponseRedirect.
     """
     test_content = {'foo': 'bar'}
     href = '/some/url/'
     response = HttpResponse(content=test_content)
     redirect_response = util.generate_redirect_response(response, href)
     self.assertEqual(redirect_response.status_code, 201)
     self.assertEqual(redirect_response.reason_phrase, 'CREATED')
     self.assertEqual(redirect_response._headers['location'][1],
                      str(mock_iri_to_uri.return_value))
     mock_iri_to_uri.assert_called_once_with(href)
Esempio n. 22
0
 def test_generate_redirect_response(self, mock_iri_to_uri):
     """
     Test HttpResponseRedirect.
     """
     test_content = {'foo': 'bar'}
     href = '/some/url/'
     response = HttpResponse(content=test_content)
     redirect_response = util.generate_redirect_response(response, href)
     self.assertEqual(redirect_response.status_code, 201)
     self.assertEqual(redirect_response.reason_phrase, 'CREATED')
     self.assertEqual(redirect_response._headers['location'][1],
                      str(mock_iri_to_uri.return_value))
     mock_iri_to_uri.assert_called_once_with(href)
Esempio n. 23
0
    def post(self, request, *args, **kwargs):
        """
        Initialize an upload and return a serialized dict containing the upload data.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest
        :return : Serialized response containing a url to delete an upload and a unique id.
        :rtype : django.http.HttpResponse
        """
        upload_manager = factory.content_upload_manager()
        upload_id = upload_manager.initialize_upload()
        href = reverse("content_upload_resource", kwargs={"upload_id": upload_id})
        response = generate_json_response({"_href": href, "upload_id": upload_id})
        response_redirect = generate_redirect_response(response, href)
        return response_redirect
Esempio n. 24
0
    def post(self, request, *args, **kwargs):
        """
        Initialize an upload and return a serialized dict containing the upload data.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest
        :return : Serialized response containing a url to delete an upload and a unique id.
        :rtype : django.http.HttpResponse
        """
        upload_manager = factory.content_upload_manager()
        upload_id = upload_manager.initialize_upload()
        href = reverse('content_upload_resource',
                       kwargs={'upload_id': upload_id})
        response = generate_json_response({
            '_href': href,
            'upload_id': upload_id
        })
        response_redirect = generate_redirect_response(response, href)
        return response_redirect
Esempio n. 25
0
    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'])
Esempio n. 26
0
    def post(self, request):
        """
        Create a new role.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest

        :return: Response containing the role
        :rtype: django.http.HttpResponse
        """
        role_data = request.body_as_json
        role_id = role_data.get("role_id", None)
        display_name = role_data.get("display_name", None)
        description = role_data.get("description", None)
        manager = factory.role_manager()
        role = manager.create_role(role_id, display_name, description)
        link = {"_href": reverse("role_resource", kwargs={"role_id": role["id"]})}
        role.update(link)
        response = generate_json_response_with_pulp_encoder(role)
        redirect_response = generate_redirect_response(response, link["_href"])
        return redirect_response
Esempio n. 27
0
    def post(self, request):
        """
        Create a consumer and return a serialized object containing just created consumer.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest

        :raises MissingValue: if ID is not provided

        :return: Response containing the consumer
        :rtype: django.http.HttpResponse
        """

        params = request.body_as_json
        consumer_id = params.get('id')
        if consumer_id is None:
            raise MissingValue(['id'])
        display_name = params.get('display_name')
        description = params.get('description')
        notes = params.get('notes')
        rsa_pub = params.get('rsa_pub')

        manager = factory.consumer_manager()

        consumer, certificate = manager.register(
            consumer_id,
            display_name=display_name,
            description=description,
            notes=notes,
            rsa_pub=rsa_pub)

        link = add_link(consumer)

        document = {
            'consumer': consumer,
            'certificate': certificate
        }
        response = generate_json_response_with_pulp_encoder(document)
        redirect_response = generate_redirect_response(response, link['_href'])
        return redirect_response
Esempio n. 28
0
    def post(self, request):
        """
        Create a consumer and return a serialized object containing just created consumer.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest

        :raises MissingValue: if ID is not provided

        :return: Response containing the consumer
        :rtype: django.http.HttpResponse
        """

        params = request.body_as_json
        consumer_id = params.get('id')
        if consumer_id is None:
            raise MissingValue(['id'])
        display_name = params.get('display_name')
        description = params.get('description')
        notes = params.get('notes')
        rsa_pub = params.get('rsa_pub')

        manager = factory.consumer_manager()

        consumer, certificate = manager.register(
            consumer_id,
            display_name=display_name,
            description=description,
            notes=notes,
            rsa_pub=rsa_pub)

        link = add_link(consumer)

        document = {
            'consumer': consumer,
            'certificate': certificate
        }
        response = generate_json_response_with_pulp_encoder(document)
        redirect_response = generate_redirect_response(response, link['_href'])
        return redirect_response
Esempio n. 29
0
    def post(self, request):
        """
        Create a new role.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest

        :return: Response containing the role
        :rtype: django.http.HttpResponse
        """
        role_data = request.body_as_json
        role_id = role_data.get('role_id', None)
        display_name = role_data.get('display_name', None)
        description = role_data.get('description', None)
        manager = factory.role_manager()
        role = manager.create_role(role_id, display_name, description)
        link = {'_href': reverse('role_resource',
                kwargs={'role_id': role['id']})}
        role.update(link)
        response = generate_json_response_with_pulp_encoder(role)
        redirect_response = generate_redirect_response(response, link['_href'])
        return redirect_response
Esempio n. 30
0
File: users.py Progetto: alanoe/pulp
    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'])
Esempio n. 31
0
    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
        """
        # Pull all the user data
        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 = user_data.pop('name', None)
        if user_data:
            raise pulp_exceptions.InvalidValue(user_data.keys())
        # Creation
        manager = factory.user_manager()
        args = [login]
        kwargs = {'password': password, 'name': name}

        user = manager.create_user(*args, **kwargs)

        # Add the link to the user
        link = _add_link(user)

        # Grant permissions
        permission_manager = factory.permission_manager()
        permission_manager.grant_automatic_permissions_for_resource(
            link['_href'])

        response = generate_json_response_with_pulp_encoder(user)
        return generate_redirect_response(response, link['_href'])
Esempio n. 32
0
    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
        """
        # Pull all the user data
        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 = user_data.pop('name', None)
        if user_data:
            raise pulp_exceptions.InvalidValue(user_data.keys())
        # Creation
        manager = factory.user_manager()
        args = [login]
        kwargs = {'password': password,
                  'name': name}

        user = manager.create_user(*args, **kwargs)

        # Add the link to the user
        link = _add_link(user)

        # Grant permissions
        permission_manager = factory.permission_manager()
        permission_manager.grant_automatic_permissions_for_resource(link['_href'])

        response = generate_json_response_with_pulp_encoder(user)
        return generate_redirect_response(response, link['_href'])
Esempio n. 33
0
    def post(self, request):
        """
        Create a new event listener.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest

        :return: Response containing the event listener
        :rtype: django.http.HttpResponse
        """
        params = request.body_as_json

        notifier_type_id = params.get('notifier_type_id', None)
        notifier_config = params.get('notifier_config', None)
        event_types = params.get('event_types', None)

        manager = factory.event_listener_manager()
        event = manager.create(notifier_type_id, notifier_config, event_types)

        link = add_link(event)

        response = generate_json_response_with_pulp_encoder(event)
        redirect_response = generate_redirect_response(response, link['_href'])
        return redirect_response
Esempio n. 34
0
    def post(self, request):
        """
        Create a new event listener.

        :param request: WSGI request object
        :type request: django.core.handlers.wsgi.WSGIRequest

        :return: Response containing the event listener
        :rtype: django.http.HttpResponse
        """
        params = request.body_as_json

        notifier_type_id = params.get('notifier_type_id', None)
        notifier_config = params.get('notifier_config', None)
        event_types = params.get('event_types', None)

        manager = factory.event_listener_manager()
        event = manager.create(notifier_type_id, notifier_config, event_types)

        link = add_link(event)

        response = generate_json_response_with_pulp_encoder(event)
        redirect_response = generate_redirect_response(response, link['_href'])
        return redirect_response