Skip to content

Tokens

MQP-Database-Access Token module

TokenError

Bases: Exception

The TokenError is a base class for all token related errors.

TokenExistsError

Bases: TokenError

This exception occurs when a identity attempts to create a token with the same name.

TokenExpirationAfterMaximum

Bases: TokenError

This exception occurs when a token is created with an expiration that is before now.

TokenExpirationBeforeNow

Bases: TokenError

This exception occurs when a token is created with an expiration that is before now.

TokenNotFound

Bases: TokenError

This exception occurs when a identity attempts to find a token which doesn't exist.

TooManyTokensError

Bases: TokenError

This exception occurs when a identity attempts to create too many tokens.

add_new_token

add_new_token(
    name: str,
    owner: str,
    token: str,
    expiration: datetime,
    max_budget_usage: int,
    max_jobs: int,
) -> None

Add a new token for a given identity to the database with an expiration.

fetch_active_tokens_of_identity

fetch_active_tokens_of_identity(owner: str) -> list[Token]

Fetch all tokens

revoke_token_by_name_and_identity

revoke_token_by_name_and_identity(
    name: str, owner: str
) -> None

Revoke a given token by name and identity.

verify_token

verify_token(token: str) -> Optional[Token]

This function verifies that a received token exists in the database and then returns the related user.