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 getAccounts(targets, page=1, pageSize=1, login=None, accountType=None, createTimeLt=None, createTimeGte=None, accountId=None, getCount=True)[source]¶
Get accounts with pagination :param targets: targets to get :param page: page :param pageSize: page size :param login: account login :param accountType: account type :param createTimeLt: upper bound of account create time :param createTimeGte: lower bound of account create time :param accountId: account id :param getCount: whether to get account count
- Returns:
accounts or accounts and count
- Return type:
UnionType
[tuple
[list
[dict
],int
],list
[dict
]]
- async getToken(tokenId, permissionTargets=0, accountId=None)[source]¶
Get token :param tokenId: token id :param permissionTargets: permission targets :param accountId: account id
- Returns:
token if exist otherwise None
- Return type:
UnionType
[dict
,None
]
- async getTokens(page, pageSize, permissionTargets=None, accountId=None, createTimeLt=None, createTimeGte=None)[source]¶
Get tokens :param accountId: account id :param page: page :param pageSize: page size :param permissionTargets: permission targets :param createTimeLt: upper bound of token create time :param createTimeGte: lower bound of token create time
- Returns:
tokens list
- Return type:
list
[dict
]
- async classmethod initDBContext(dbSettings, storageTime, **kwargs)[source]¶
Initialize context :param dbSettings: database settings :param storageTime: storage time
- Return type:
None
- classmethod makeOutputAccounts(rows, columns)[source]¶
Make result accounts (from the database reply) proper for user.
- Parameters:
rows – list from db
columns – selected columns
- Returns:
faces with changed fields
- Return type:
list
[dict
[str
,any
]]
- 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 :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, permissionTargets=None)[source]¶
Verify account by JWT token :param token: JWT token :param permissionTargets: target for permissions to return in response
- 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
]