Esempio n. 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)
Esempio n. 2
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)
Esempio n. 3
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)