Database context¶
- class luna_accounts.db.context.DBContext(dbSettings, storageTime, ecdsaKeyString=None, ecdsaKeyPassword=None)[source]¶
Accounts DB context.
- async bulkUpdateTokensPermissions(tokenIds, permissions, accountId=None)[source]¶
Bulk update permissions of several tokens. Fully replaces permissions for all found tokens in a single transaction and reissues their JWTs.
- Parameters:
tokenIds (
list[str]) – list of token idspermissions (
Permissions) – full resulting permissions set to apply to every found tokenaccountId (
str|None) – account id
- Return type:
dict- Returns:
dict with summary (total/succeeded/failed) and per-token results in the order of tokenIds
- async createAccount(account, accountId=None)[source]¶
Create new account :type account:
Account:param account: account to create :type accountId:str|None:param accountId: account id to create- Return type:
str- Returns:
unique account id
- Raises:
VLException(Error.AccountAlreadyExist.format(account.login), 409, False) if account with the same login – already exists
- async createToken(token, accountId)[source]¶
Create new token :type token:
Token:param token: token to create :type accountId:str:param accountId: account id- Return type:
tuple[str,str]- Returns:
tuple with unique token and its’ id
- Raises:
VLException(Error.AccountNotFound.format(accountId), 400, False) if specified account id not found –
- async deleteAccount(accountId)[source]¶
Delete account by account id :type accountId:
str:param accountId: id of account- Return type:
bool- Returns:
True if account was deleted otherwise False
- async deleteToken(tokenId, accountId)[source]¶
Delete token by id :type tokenId:
str:param tokenId: token id :type accountId:str:param accountId: account id- Return type:
bool- Returns:
True if token was removed, False if token was not found
- async getAccounts(targets, page=1, pageSize=1, login=None, accountType=None, createTimeLt=None, createTimeGte=None, accountId=None, getCount=True)[source]¶
Get accounts with pagination :type targets:
list[str] :param targets: targets to get :type page:int:param page: page :type pageSize:int:param pageSize: page size :type login:str|None:param login: account login :type accountType:AccountType|None:param accountType: account type :type createTimeLt:datetime|None:param createTimeLt: upper bound of account create time :type createTimeGte:datetime|None:param createTimeGte: lower bound of account create time :type accountId:str|None:param accountId: account id :type getCount:bool:param getCount: whether to get account count- Return type:
tuple[list[dict],int] |list[dict]- Returns:
accounts or accounts and count
- async getToken(tokenId, permissionTargets=0, accountId=None)[source]¶
Get token :type tokenId:
str:param tokenId: token id :type permissionTargets:int:param permissionTargets: permission targets :type accountId:str|None:param accountId: account id- Return type:
dict|None- Returns:
token if exist otherwise None
- async getTokens(page, pageSize, permissionTargets=None, accountId=None, createTimeLt=None, createTimeGte=None)[source]¶
Get tokens :type accountId:
str|None:param accountId: account id :type page:int:param page: page :type pageSize:int:param pageSize: page size :type permissionTargets:PermissionsTargets|None:param permissionTargets: permission targets :type createTimeLt:datetime|None:param createTimeLt: upper bound of token create time :type createTimeGte:datetime|None:param createTimeGte: lower bound of token create time- Return type:
list[dict]- Returns:
tokens list
- makeOutputAccounts(rows, columns)[source]¶
Make result accounts (from the database reply) proper for user.
- Parameters:
rows (
list[tuple]) – list from dbcolumns (
Iterable[str]) – selected columns
- Return type:
list[dict[str,any]]- Returns:
faces with changed fields
- makeOutputToken(rowFromDB, permissionTargets=None)[source]¶
Make dict with token from row from db
- Return type:
dict
- async patchAccount(accountId, accountOverride)[source]¶
Patch account by account id :type accountId:
str:param accountId: id of account :type accountOverride:AccountForPatch:param accountOverride: account for patch model- Return type:
bool- Returns:
True if account was updated otherwise False
- async probe()[source]¶
Ensure provided config is valid. Create new connection. Can be used without initialization
- Return type:
bool
- async replaceToken(tokenId, token, accountId=None)[source]¶
Replace existing token using specified token id :type tokenId:
str:param tokenId: token id :type accountId:str|None:param accountId: account id :type token:Token:param token: token- Return type:
str- Returns:
token
- Raises:
VLException(Error.TokenNotFoundById.format(tokenId), 404, False) if token not found –
- async verifyAccountByAccountId(accountId)[source]¶
Verify account by account id :type accountId:
str:param accountId: accountId- Return type:
str- Returns:
account type if account found otherwise None
- async verifyAccountByLoginPassword(login, password)[source]¶
Verify account by login and password :type login:
str:param login: login :type password:str:param password: password- Return type:
tuple[str,str]- Returns:
account type and account id
- Raises:
VLException(Error.AccountLoginPasswordIncorrect, 400, isCriticalError=False) if account not found or – password doesn’t match
- async verifyToken(token, permissionTargets=None)[source]¶
Verify account by JWT token :type token:
str:param token: JWT token :type permissionTargets:int|None:param permissionTargets: target for permissions to return in response- Return type:
tuple[str,dict] |None- 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 –