Database context¶
- class luna_accounts.db.context.DBContext(logger)[source]¶
Accounts DB context.
- async createAccount(account, accountId=None)[source]¶
Create new account :param account: account to create :param accountId: account id to create
- Returns:
unique account id
- Raises:
VLException(Error.AccountAlreadyExist.format(account.login), 409, False) if account with the same login – already exists
- Return type:
str
- async createToken(token, accountId)[source]¶
Create new token :param token: token to create :param accountId: account id
- Returns:
tuple with unique token and its’ id
- Raises:
VLException(Error.AccountNotFound.format(accountId), 400, False) if specified account id not found –
- Return type:
tuple
[str
,str
]
- async deleteAccount(accountId)[source]¶
Delete account by account id :param accountId: id of account
- Returns:
True if account was deleted otherwise False
- Return type:
bool
- async deleteToken(tokenId, accountId)[source]¶
Delete token by id :param tokenId: token id :param accountId: account id
- Returns:
True if token was removed, False if token was not found
- Return type:
bool
- async getAccount(accountId)[source]¶
Get account by account id :param accountId: id of account
- Returns:
account if exists otherwise None
- Return type:
Optional
[dict
,None
]
- async getAccounts(page, pageSize, login=None, accountType=None)[source]¶
Get accounts with pagination :param page: page :param pageSize: page size :param login: account login :param accountType: account type
- Returns:
accounts
- Return type:
tuple
[list
[dict
],int
]
- async getToken(tokenId, accountId=None)[source]¶
Get token :param tokenId: token id :param accountId: account id
- Returns:
token if exist otherwise None
- Return type:
Optional
[dict
,None
]
- async getTokens(page, pageSize, accountId=None)[source]¶
Get tokens :param accountId: account id :param page: page :param pageSize: page size
- Returns:
tokens list
- Return type:
list
[dict
]
- async patchAccount(accountId, accountOverride)[source]¶
Patch account by account id :param accountId: id of account :param accountOverride: account for patch model
- Returns:
True if account was updated otherwise False
- Return type:
bool
- async replaceToken(tokenId, token, accountId=None)[source]¶
Replace existing token using specified token id :param tokenId: token id :param accountId: account id :param token: token
- Returns:
token
- Raises:
VLException(Error.TokenNotFoundById.format(tokenId), 404, False) if token not found –
- Return type:
str
- async verifyAccountByAccountId(accountId)[source]¶
Verify account by account id :param accountId: accountId
- Returns:
account type if account found otherwise None
- Return type:
str
- async verifyAccountByLoginPassword(login, password)[source]¶
Verify account by login and password :param login: login :param password: password
- Returns:
account type and account id
- Raises:
VLException(Error.AccountLoginPasswordIncorrect, 400, isCriticalError=False) if account not found or – password doesn’t match
- Return type:
tuple
[str
,str
]
- async verifyToken(token)[source]¶
Verify account by JWT token :param token: JWT token
- Returns:
tuple with account type and permissions if account found otherwise None
- Raises:
VLException(Error.JWTTokenNotFound, 400, isCriticalError=False) if token not found or unexpected format –
VLException(Error.TokenExpired, 400, False) if token expired –
- Return type:
Optional
[tuple
[str
,dict
],None
]