Beispiel #1
0
    def create(self, request):
        """@description-title Add a new SSL key
        @description Add a new SSL key to the requesting user's account.

        @param (string) "key" [required=true,formatting=true] An SSL key
        should be provided in the request payload as form data with the name
        'key':

            key: "key data"

        - ``key data``: The contents of a pem file.

        @success (http-status-code) "201" 201
        @success (json) "success-json" A JSON object containing the new key.
        @success-example "success-json" [exkey=ssl-keys-create] placeholder
        text
        """
        form = SSLKeyForm(user=request.user, data=request.data)
        if form.is_valid():
            sslkey = form.save(ENDPOINT.API, request)
            emitter = JSONEmitter(sslkey, typemapper, None,
                                  DISPLAY_SSLKEY_FIELDS)
            stream = emitter.render(request)
            return HttpResponse(
                stream,
                content_type="application/json; charset=utf-8",
                status=int(http.client.CREATED),
            )
        else:
            raise MAASAPIValidationError(form.errors)
Beispiel #2
0
 def test_creates_audit_event_on_save(self):
     user = factory.make_User()
     key_string = get_data("data/test_x509_0.pem")
     form = SSLKeyForm(user=user, data={"key": key_string})
     request = HttpRequest()
     request.user = user
     form.save(factory.pick_choice(ENDPOINT_CHOICES), request)
     event = Event.objects.get(type__level=AUDIT)
     self.assertIsNotNone(event)
     self.assertEqual(event.description, "Created SSL key.")
Beispiel #3
0
 def create(self, params):
     """Create a SSLKey."""
     form = SSLKeyForm(user=self.user, data=params)
     if form.is_valid():
         try:
             request = HttpRequest()
             request.user = self.user
             request.data = params
             obj = form.save(ENDPOINT.UI, request)
         except ValidationError as e:
             try:
                 raise HandlerValidationError(e.message_dict)
             except AttributeError:
                 raise HandlerValidationError({"__all__": e.message})
         return self.full_dehydrate(obj)
     else:
         raise HandlerValidationError(form.errors)
Beispiel #4
0
    def create(self, request):
        """Add a new SSL key to the requesting user's account.

        The request payload should contain the SSL key data in form
        data whose name is "key".
        """
        form = SSLKeyForm(user=request.user, data=request.data)
        if form.is_valid():
            sslkey = form.save()
            emitter = JSONEmitter(sslkey, typemapper, None,
                                  DISPLAY_SSLKEY_FIELDS)
            stream = emitter.render(request)
            return HttpResponse(stream,
                                content_type='application/json; charset=utf-8',
                                status=int(http.client.CREATED))
        else:
            raise MAASAPIValidationError(form.errors)