Exemplo n.º 1
0
    def get(self, account, rse):
        """
        Return the account usage of the account.

        .. :quickref: UsageHistory; Get account usage history.

        :param account: The account name.
        :param rse: The RSE.
        :resheader Content-Type: application/json
        :status 200: OK.
        :status 401: Invalid auth token.
        :status 404: Account not found.
        :status 406: Not Acceptable.
        :returns: Line separated list of account usages.
        Return the account usage of the account.
        """
        try:
            usage = get_usage_history(account=account,
                                      rse=rse,
                                      issuer=request.environ.get('issuer'),
                                      vo=request.environ.get('vo'))
        except (AccountNotFound, CounterNotFound) as error:
            return generate_http_error_flask(404, error)
        except AccessDenied as error:
            return generate_http_error_flask(401, error)

        for entry in usage:
            for key, value in entry.items():
                if isinstance(value, datetime):
                    entry[key] = value.strftime('%Y-%m-%dT%H:%M:%S')

        return jsonify(usage)
Exemplo n.º 2
0
    def get(self, account, rse):
        """
        Return the account usage of the account.

        .. :quickref: UsageHistory; Get account usage history.

        :param account: The account name.
        :param rse: The RSE.
        :resheader Content-Type: application/json
        :status 200: OK.
        :status 401: Invalid auth token.
        :status 404: Account not found.
        :status 406: Not Acceptable.
        :status 500: Database exception.
        :returns: Line separated list of account usages.
        Return the account usage of the account.
        """
        try:
            return get_usage_history(account=account,
                                     rse=None,
                                     issuer=request.environ.get('issuer'))
        except AccountNotFound as error:
            return generate_http_error_flask(404, 'AccountNotFound',
                                             error.args[0])
        except CounterNotFound as error:
            return generate_http_error_flask(404, 'CounterNotFound',
                                             error.args[0])
        except AccessDenied as error:
            return generate_http_error_flask(401, 'AccessDenied',
                                             error.args[0])
        except Exception as error:
            print(format_exc())
            return error, 500
Exemplo n.º 3
0
    def GET(self, account, rse):
        """
        Return the account usage of the account.

        HTTP Success:
            200 OK

        HTTP Error:
            401 Unauthorized
            404 Not Found
            406 Not Acceptable
            500 Internal Error

        :param account: The account name.
        :param rse:     The rse.
        """
        header('Content-Type', 'application/json')
        try:
            usage = get_usage_history(account=account,
                                      rse=rse,
                                      issuer=ctx.env.get('issuer'),
                                      vo=ctx.env.get('vo'))
        except AccountNotFound as error:
            raise generate_http_error(404, 'AccountNotFound', error.args[0])
        except CounterNotFound as error:
            raise generate_http_error(404, 'CounterNotFound', error.args[0])
        except AccessDenied as error:
            raise generate_http_error(401, 'AccessDenied', error.args[0])
        except Exception as error:
            print(format_exc())
            raise InternalError(error)

        for entry in usage:
            for key, value in entry.items():
                if isinstance(value, datetime):
                    entry[key] = value.strftime('%Y-%m-%dT%H:%M:%S')

        return dumps(usage)
Exemplo n.º 4
0
    def get(self, account, rse):
        """
        ---
        summary: Get account usage history
        description: Returns the account usage history.
        tags:
          - Account
        parameters:
        - name: account
          in: path
          description: The account identifier.
          schema:
            type: string
          style: simple
        - name: rse
          in: path
          description: The rse identifier.
          schema:
            type: string
          style: simple
        responses:
          200:
            description: OK
            content:
              application/json:
                schema:
                  type: array
                  items:
                    type: object
                    properties:
                      bytes:
                        description: The number of bytes used.
                        type: integer
                      files:
                        description: The files.
                        type: string
                      updated_at:
                        description: When the data was provided.
                        type: string
          401:
            description: Invalid Auth Token
          404:
            description: Account not found
          406:
            description: Not acceptable
        """
        try:
            usage = get_usage_history(account=account,
                                      rse=rse,
                                      issuer=request.environ.get('issuer'),
                                      vo=request.environ.get('vo'))
        except (AccountNotFound, CounterNotFound) as error:
            return generate_http_error_flask(404, error)
        except AccessDenied as error:
            return generate_http_error_flask(401, error)

        for entry in usage:
            for key, value in entry.items():
                if isinstance(value, datetime):
                    entry[key] = value.strftime('%Y-%m-%dT%H:%M:%S')

        return jsonify(usage)