Database context¶
- class luna_handlers.db.context.DBContext(logger=None)[source]¶
Handlers DB context.
- async checkVerifier(verifierId, accountId=None)[source]¶
Check verifier existence
- Parameters:
verifierId (
str) – verifier idaccountId (
str|None) – account id
- Return type:
bool- Returns:
True - if verifier exists, otherwise False
- async createHandler(policies, accountId, description='', handlerType=HandlerType.static, lambdaId=None)[source]¶
Create new handler.
- Parameters:
policies (
dict) – set handler policiesaccountId (
str) – account iddescription (
str) – user handler descriptionhandlerType (
HandlerType) – handler typelambdaId (
str|None) – id of lambda handler
- Return type:
str- Returns:
handler id
- async createVerifier(policies, accountId, description='')[source]¶
Create new verifier.
- Parameters:
policies (
dict) – verifier policiesaccountId (
str) – account iddescription (
str) – user verifier description
- Return type:
str- Returns:
verifier id
- async deleteHandler(handlerId, accountId=None)[source]¶
Delete handler by id
- Parameters:
handlerId (
str) – handler idaccountId (
str|None) – account id of the handler
- Return type:
bool- Returns:
True if handler exist otherwise false
- async deleteVerifier(verifierId, accountId=None)[source]¶
Delete verifier by id
- Parameters:
verifierId (
str) – verifier idaccountId (
str|None) – account id
- Return type:
bool- Returns:
True if verifier deleted, otherwise False
- async doesHandlerExist(handlerId, accountId=None)[source]¶
Check a account handler with id=handlerId existence
- Parameters:
handlerId (
str) – handler idaccountId (
str|None) – handler account id
- Return type:
bool- Returns:
true - if handler is exist otherwise false
- async getAbsentHandlersIds(handlerIds)[source]¶
Given list of handlerIds, return those handlerIds that were removed from database. Used for removal of items from cache by cache invalidator.
- Parameters:
handlerIds (
List[str]) – handler ids- Return type:
List[str]- Returns:
List with handlersIds that were removed.
- async getHandler(handlerId, targets=(HandlerTarget.handlerId, HandlerTarget.accountId, HandlerTarget.createTime, HandlerTarget.lastUpdateTime, HandlerTarget.description, HandlerTarget.policies, HandlerTarget.handlerType, HandlerTarget.lambdaId), accountId=None)[source]¶
Get handler by id
- Parameters:
handlerId (
str) – handler idaccountId (
str|None) – handler account idtargets (
Iterable[HandlerTarget]) – handler targets
- Return type:
dict- Returns:
deserialize dict with handler
- Raises:
VLException(Error.HandlerNotFound.format(handlerId), 404, isCriticalError=False) – if handler not found
- async getHandlerCount(accountId=None, description=None, handlerType=None)[source]¶
Get handler count
- Parameters:
accountId (
str|None) – handler account iddescription (
str|None) – handler descriptionhandlerType (
int|None) – handler type
- Returns:
handler count
- async getHandlers(accountId=None, description=None, handlerType=None, handlerIds=None, page=1, pageSize=100)[source]¶
Get handlers by filters
- Parameters:
accountId (
str|None) – handler account iddescription (
str|None) – handler descriptionhandlerType (
int|None) – handler typehandlerIds (
list[str] |None) – list of handler IDs to filter bypage (
int) – pagepageSize (
int) – page size
- Return type:
List[dict]- Returns:
list of deserialize handlers
- async getUpdatedHandlers(handlerIds, lastUpdateTimeGte, targets=None)[source]¶
Get updated handlers by ids. Used for cache invalidation.
- Parameters:
handlerIds (
List[str]) – handler idslastUpdateTimeGte (
datetime) – lower bound of handler update timetargets (
list[HandlerTarget] |None) – handler targets
- Return type:
List[Dict]- Returns:
List with handlers
- async getVerifier(verifierId, accountId=None)[source]¶
Get verifier by id
- Parameters:
verifierId (
str) – verifier idaccountId (
str|None) – verifier account id
- Return type:
Dict- Returns:
deserialized dict with verifier
- Raises:
VLException(Error.VerifierNotFound.format(verifierId), 404, isCriticalError=False) – if verifier not found
- async getVerifierCount(accountId=None, description=None)[source]¶
Get verifier count
- Parameters:
accountId (
str|None) – account iddescription (
str|None) – verifier description
- Returns:
verifier count
- async getVerifiers(accountId=None, description=None, page=1, pageSize=100)[source]¶
Get verifiers by filters
- Parameters:
accountId (
str|None) – account iddescription (
str|None) – verifier descriptionpage (
int) – pagepageSize (
int) – page size
- Return type:
List[dict]- Returns:
list of verifiers
- loadHandlerFromRow(handlerRow, columns)[source]¶
Load handler as dict from raw row.
- Parameters:
handlerRow (
Tuple) – full row from dbcolumns (
ColumnCollection) – columns from sql query
- Return type:
dict[str,Any]- Returns:
handler as dict
- loadVerifierFromRow(verifierRow)[source]¶
Load verifier as dict from raw row.
- Parameters:
verifierRow (
Tuple) – full row from db- Return type:
Dict[str,Any]- Returns:
verifier as dict
- async putHandler(handlerId, policies, accountId, description='', handlerType=0, lambdaId=None)[source]¶
Put handler instead old handler.
- Parameters:
handlerId (
str) – handlerpolicies (
dict) – set handler policiesaccountId (
str) – account iddescription (
str) – user handler descriptionhandlerType (
int) – type of handlerlambdaId (
str|None) – id of lambda handler
Warning
function does not create handler!
- Return type:
bool- Returns:
True if handler exist otherwise false
- async putVerifier(verifierId, policies, accountId, description='')[source]¶
Replace verifier by id.
- Parameters:
verifierId (
str) – verifier idpolicies (
dict) – verifier policiesaccountId (
str) – account iddescription (
str) – user verifier description
Warning
function does not create verifier!
- Return type:
int|None- Returns:
verifier current version if verifier replaced