Esempio n. 1
0
    def post(self):
        """
        Create a new Lifetime Model exception.

        .. :quickref: LifetimeException; Create new exception.

        :<json string dids: The list of dids.
        :<json string pattern: The pattern.
        :<json string comments: The comment for the exception.
        :<json string expires_at: The expiration date for the exception.
        :resheader Content-Type: application/json
        :status 201: Created.
        :status 400: Cannot decode json parameter list.
        :status 401: Invalid Auth Token.
        :status 409: Lifetime Exception already exists.
        :status 500: Internal Error.
        :returns: The id for the newly created execption.
        """
        json_data = request.data
        dids, pattern, comments, expires_at = [], None, None, None
        try:
            params = loads(json_data)
            if 'dids' in params:
                dids = params['dids']
            if 'pattern' in params:
                pattern = params['pattern']
            if 'comments' in params:
                comments = params['comments']
            if 'expires_at' in params:
                expires_at = params['expires_at']
        except ValueError:
            return generate_http_error_flask(
                400, 'ValueError', 'Cannot decode json parameter list')

        try:
            exception_id = add_exception(dids=dids,
                                         account=request.environ.get('issuer'),
                                         vo=request.environ.get('vo'),
                                         pattern=pattern,
                                         comments=comments,
                                         expires_at=expires_at)
        except InvalidObject as error:
            return generate_http_error_flask(400, 'InvalidObject',
                                             error.args[0])
        except AccessDenied as error:
            return generate_http_error_flask(401, 'AccessDenied',
                                             error.args[0])
        except LifetimeExceptionDuplicate as error:
            return generate_http_error_flask(409, 'LifetimeExceptionDuplicate',
                                             error.args[0])
        except RucioException as error:
            return generate_http_error_flask(500, error.__class__.__name__,
                                             error.args[0])
        except Exception as error:
            print(format_exc())
            return str(error), 500
        return Response(dumps(exception_id),
                        status=201,
                        content_type="application/json")
Esempio n. 2
0
    def POST(self):
        """
        Create a new Lifetime Model exception.

        HTTP Success:
            201 Created

        HTTP Error:
            400 Bad Request
            401 Unauthorized
            409 Conflict
            500 Internal Error
        """
        json_data = data()
        dids, pattern, comments, expires_at = [], None, None, None
        try:
            params = loads(json_data)
            if 'dids' in params:
                dids = params['dids']
            if 'pattern' in params:
                pattern = params['pattern']
            if 'comments' in params:
                comments = params['comments']
            if 'expires_at' in params:
                expires_at = params['expires_at']
        except ValueError:
            raise generate_http_error(400, 'ValueError',
                                      'Cannot decode json parameter list')

        try:
            exception_id = add_exception(dids=dids,
                                         account=ctx.env.get('issuer'),
                                         vo=ctx.env.get('vo'),
                                         pattern=pattern,
                                         comments=comments,
                                         expires_at=expires_at)
        except InvalidObject as error:
            raise generate_http_error(400, 'InvalidObject', error.args[0])
        except AccessDenied as error:
            raise generate_http_error(401, 'AccessDenied', error.args[0])
        except LifetimeExceptionDuplicate as error:
            raise generate_http_error(409, 'LifetimeExceptionDuplicate',
                                      error.args[0])
        except RucioException as error:
            raise generate_http_error(500, error.__class__.__name__,
                                      error.args[0])
        except Exception as error:
            raise InternalError(error)
        raise Created(dumps(exception_id))
Esempio n. 3
0
    def post(self):
        """
        Create a new Lifetime Model exception.

        .. :quickref: LifetimeException; Create new exception.

        :<json string dids: The list of dids.
        :<json string pattern: The pattern.
        :<json string comments: The comment for the exception.
        :<json string expires_at: The expiration date for the exception.
        :resheader Content-Type: application/json
        :status 201: Created.
        :status 400: Cannot decode json parameter list.
        :status 401: Invalid Auth Token.
        :status 409: Lifetime Exception already exists.
        :returns: The id for the newly created execption.
        """
        parameters = json_parameters()
        try:
            exception_id = add_exception(
                dids=param_get(parameters, 'dids', default=[]),
                account=request.environ.get('issuer'),
                vo=request.environ.get('vo'),
                pattern=param_get(parameters, 'pattern', default=None),
                comments=param_get(parameters, 'comments', default=None),
                expires_at=param_get(parameters, 'expires_at', default=None),
            )
        except InvalidObject as error:
            return generate_http_error_flask(400, error)
        except AccessDenied as error:
            return generate_http_error_flask(401, error)
        except LifetimeExceptionDuplicate as error:
            return generate_http_error_flask(409, error)

        return Response(dumps(exception_id),
                        status=201,
                        content_type="application/json")
Esempio n. 4
0
    def post(self):
        """
        ---
        summary: Create Exception
        description: Creates a Lifetime Exception.
        tags:
            - Lifetime Exceptions
        requestBody:
          content:
            application/json:
              schema:
                type: object
                properties:
                  dids:
                    description: List of dids associated with the lifetime exception.
                    type: array
                    items:
                      description: A did
                      type: object
                      properties:
                        name:
                          description: The name of the did.
                          type: string
                  pattern:
                    description: The pattern of the lifetime exception.
                    type: string
                  comments:
                    description: The comment for the lifetime exception.
                    type: string
                  expires_at:
                    description: The expiration date for the lifetime exception.
                    type: string
        responses:
          201:
            description: OK
            content:
              application/json:
                schema:
                  description: The exception id.
                  type: string
          401:
            description: Invalid Auth Token
          400:
            description: Cannot decode json parameter list.
          409:
            description: Lifetime exception already exists.
        """
        parameters = json_parameters()
        try:
            exception_id = add_exception(
                dids=param_get(parameters, 'dids', default=[]),
                account=request.environ.get('issuer'),
                vo=request.environ.get('vo'),
                pattern=param_get(parameters, 'pattern', default=None),
                comments=param_get(parameters, 'comments', default=None),
                expires_at=param_get(parameters, 'expires_at', default=None),
            )
        except InvalidObject as error:
            return generate_http_error_flask(400, error)
        except AccessDenied as error:
            return generate_http_error_flask(401, error)
        except LifetimeExceptionDuplicate as error:
            return generate_http_error_flask(409, error)

        return Response(dumps(exception_id),
                        status=201,
                        content_type="application/json")