Пример #1
0
    def post(self, account, key):
        """ Add attributes to an account.

        .. :quickref: Attributes; Add account attribute

        :param account: Account identifier.
        :param key: The attribute key.
        :<json string key: The attribute key.
        :<json string value: The attribute value.
        :status 201: Successfully created.
        :status 401: Invalid auth token.
        :status 409: Attribute already exists.
        :status 404: Account not found.
        """
        parameters = json_parameters()
        key = param_get(parameters, 'key')
        value = param_get(parameters, 'value')
        try:
            add_account_attribute(key=key,
                                  value=value,
                                  account=account,
                                  issuer=request.environ.get('issuer'),
                                  vo=request.environ.get('vo'))
        except AccessDenied as error:
            return generate_http_error_flask(401, error)
        except Duplicate as error:
            return generate_http_error_flask(409, error)
        except AccountNotFound as error:
            return generate_http_error_flask(404, error)

        return 'Created', 201
Пример #2
0
    def post(self, account, key):
        """ Add attributes to an account.

        .. :quickref: Attributes; Add account attribute

        :param account: Account identifier.
        :param key: The attribute key.
        :<json string key: The attribute key.
        :<json string value: The attribute value.
        :status 201: Successfully created.
        :status 401: Invalid auth token.
        :status 409: Attribute already exists.
        :status 404: Account not found.
        :status 500: Database Exception.
        """
        json_data = request.data.decode()
        try:
            parameter = loads(json_data)
        except ValueError:
            return generate_http_error_flask(
                400, 'ValueError', 'cannot decode json parameter dictionary')

        try:
            key = parameter['key']
            value = parameter['value']
        except KeyError as error:
            if error.args[0] == 'key' or error.args[0] == 'value':
                return generate_http_error_flask(400, 'KeyError',
                                                 '%s not defined' % str(error))
            raise
        except TypeError:
            return generate_http_error_flask(400, 'TypeError',
                                             'body must be a json dictionary')

        try:
            add_account_attribute(key=key,
                                  value=value,
                                  account=account,
                                  issuer=request.environ.get('issuer'),
                                  vo=request.environ.get('vo'))
        except AccessDenied as error:
            return generate_http_error_flask(401, 'AccessDenied',
                                             error.args[0])
        except Duplicate as error:
            return generate_http_error_flask(409, 'Duplicate', error.args[0])
        except AccountNotFound as error:
            return generate_http_error_flask(404, 'AccountNotFound',
                                             error.args[0])
        except Exception as error:
            print(format_exc())
            return str(error), 500

        return 'Created', 201
Пример #3
0
    def POST(self, account, key):
        """ Add attributes to an account.

        HTTP Success:
            201 Created

        HTTP Error:
            400 Bad Reqeust
            401 Unauthorized
            409 Conflict
            500 Internal Error

        :param account: Account identifier.
        """
        json_data = data()
        try:
            parameter = loads(json_data)
        except ValueError:
            raise generate_http_error(
                400, 'ValueError', 'cannot decode json parameter dictionary')

        try:
            key = parameter['key']
            value = parameter['value']
        except KeyError as error:
            if error.args[0] == 'key' or error.args[0] == 'value':
                raise generate_http_error(400, 'KeyError',
                                          '%s not defined' % str(error))
        except TypeError:
            raise generate_http_error(400, 'TypeError',
                                      'body must be a json dictionary')

        try:
            add_account_attribute(key=key,
                                  value=value,
                                  account=account,
                                  issuer=ctx.env.get('issuer'),
                                  vo=ctx.env.get('vo'))
        except AccessDenied as error:
            raise generate_http_error(401, 'AccessDenied', error.args[0])
        except Duplicate as error:
            raise generate_http_error(409, 'Duplicate', error.args[0])
        except AccountNotFound as error:
            raise generate_http_error(404, 'AccountNotFound', error.args[0])
        except Exception as error:
            print(str(format_exc()))
            raise InternalError(error)

        raise Created()
Пример #4
0
    def post(self, account, key):
        """
        ---
        summary: Create attribute
        description: Create an attribute to an account.
        tags:
          - Account
        parameters:
        - name: account
          in: path
          description: The account identifier.
          schema:
            type: string
          style: simple
        - name: key
          in: path
          description: The key of the account attribute.
          schema:
            type: string
          style: simple
        requestBody:
          content:
            'application/json':
              schema:
                type: object
                required:
                - value
                properties:
                  key:
                    description: The key of the attribute. This would override the key defined in path.
                    type: string
                  value:
                    description: The value of the attribute.
                    type: string
        responses:
          201:
            description: OK
            content:
              application/json:
                schema:
                  type: string
                  enum: ["Created"]
          401:
            description: Invalid Auth Token
          404:
            description: No account found for the given id.
          409:
            description: Attribute already exists
        """
        parameters = json_parameters()
        key = param_get(parameters, 'key', default=key)
        value = param_get(parameters, 'value')
        try:
            add_account_attribute(key=key,
                                  value=value,
                                  account=account,
                                  issuer=request.environ.get('issuer'),
                                  vo=request.environ.get('vo'))
        except AccessDenied as error:
            return generate_http_error_flask(401, error)
        except Duplicate as error:
            return generate_http_error_flask(409, error)
        except AccountNotFound as error:
            return generate_http_error_flask(404, error)

        return 'Created', 201
Пример #5
0
                400, 'ValueError', 'cannot decode json parameter dictionary')

        try:
            key = parameter['key']
            value = parameter['value']
        except KeyError, e:
            if e.args[0] == 'key' or e.args[0] == 'value':
                raise generate_http_error(400, 'KeyError',
                                          '%s not defined' % str(e))
        except TypeError:
            raise generate_http_error(400, 'TypeError',
                                      'body must be a json dictionary')

        try:
            add_account_attribute(key=key,
                                  value=value,
                                  account=account,
                                  issuer=ctx.env.get('issuer'))
        except AccessDenied, e:
            raise generate_http_error(401, 'AccessDenied', e.args[0][0])
        except Duplicate as e:
            raise generate_http_error(409, 'Duplicate', e.args[0][0])
        except AccountNotFound, e:
            raise generate_http_error(404, 'AccountNotFound', e.args[0][0])
        except Exception, e:
            print str(format_exc())
            raise InternalError(e)

        raise Created()

    def DELETE(self, account, key):
        """ disable account with given account name.
Пример #6
0
        try:
            parameter = loads(json_data)
        except ValueError:
            raise generate_http_error(400, 'ValueError', 'cannot decode json parameter dictionary')

        try:
            key = parameter['key']
            value = parameter['value']
        except KeyError, e:
            if e.args[0] == 'key' or e.args[0] == 'value':
                raise generate_http_error(400, 'KeyError', '%s not defined' % str(e))
        except TypeError:
                raise generate_http_error(400, 'TypeError', 'body must be a json dictionary')

        try:
            add_account_attribute(key=key, value=value, account=account, issuer=ctx.env.get('issuer'))
        except AccessDenied, e:
            raise generate_http_error(401, 'AccessDenied', e.args[0][0])
        except Duplicate as e:
            raise generate_http_error(409, 'Duplicate', e.args[0][0])
        except AccountNotFound, e:
            raise generate_http_error(404, 'AccountNotFound', e.args[0][0])
        except Exception, e:
            print str(format_exc())
            raise InternalError(e)

        raise Created()

    def DELETE(self, account, key):
        """ disable account with given account name.