Database context

class luna_handlers.db.context.DBContext(logger=None)[source]

Handlers DB context.

async checkVerifier(verifierId, accountId=None)[source]

Check verifier existence

Return type:

bool

Parameters:
  • verifierId – verifier id

  • accountId – account id

Returns:

True - if verifier exists, otherwise False

async createHandler(policies, accountId, description='', handlerType=HandlerType.static, lambdaId=None)[source]

Create new handler.

Return type:

str

Parameters:
  • policies – set handler policies

  • accountId – account id

  • description – user handler description

  • handlerType – handler type

  • lambdaId – id of lambda handler

Returns:

handler id

async createVerifier(policies, accountId, description='')[source]

Create new verifier.

Return type:

str

Parameters:
  • policies – verifier policies

  • accountId – account id

  • description – user verifier description

Returns:

verifier id

async deleteHandler(handlerId, accountId=None)[source]

Delete handler by id

Return type:

bool

Parameters:
  • handlerId – handler id

  • accountId – account id of the handler

Returns:

True if handler exist otherwise false

async deleteVerifier(verifierId, accountId=None)[source]

Delete verifier by id

Return type:

bool

Parameters:
  • verifierId – verifier id

  • accountId – account id

Returns:

True if verifier deleted, otherwise False

async doesHandlerExist(handlerId, accountId=None)[source]

Check a account handler with id=handlerId existence

Return type:

bool

Parameters:
  • handlerId – handler id

  • accountId – handler account id

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.

Return type:

List[str]

Parameters:

handlerIds – handler ids

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

Return type:

dict

Parameters:
  • handlerId – handler id

  • accountId – handler account id

  • targets – handler targets

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 – handler account id

  • description – handler description

  • handlerType – handler type

Returns:

handler count

async getHandlers(accountId=None, description=None, handlerType=None, page=1, pageSize=100)[source]

Get handlers by filters

Return type:

List[dict]

Parameters:
  • accountId – handler account id

  • description – handler description

  • handlerType – handler type

  • page – page

  • pageSize – page size

Returns:

list of deserialize handlers

async getUpdatedHandlers(handlerIds, lastUpdateTimeGte, targets=None)[source]

Get updated handlers by ids. Used for cache invalidation.

Return type:

List[Dict]

Parameters:
  • handlerIds – handler ids

  • lastUpdateTimeGte – lower bound of handler update time

  • targets – handler targets

Returns:

List with handlers

async getVerifier(verifierId, accountId=None)[source]

Get verifier by id

Return type:

Dict

Parameters:
  • verifierId – verifier id

  • accountId – verifier account id

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 – account id

  • description – verifier description

Returns:

verifier count

async getVerifiers(accountId=None, description=None, page=1, pageSize=100)[source]

Get verifiers by filters

Return type:

List[dict]

Parameters:
  • accountId – account id

  • description – verifier description

  • page – page

  • pageSize – page size

Returns:

list of verifiers

loadHandlerFromRow(handlerRow, selectColumns)[source]

Load handler as dict from raw row.

Return type:

dict[str, Any]

Parameters:
  • handlerRow – full row from db

  • selectColumns – columns from sql query

Returns:

handler as dict

loadVerifierFromRow(verifierRow)[source]

Load verifier as dict from raw row.

Return type:

Dict[str, Any]

Parameters:

verifierRow – full row from db

Returns:

verifier as dict

async putHandler(handlerId, policies, accountId, description='', handlerType=0, lambdaId=None)[source]

Put handler instead old handler.

Return type:

bool

Parameters:
  • handlerId – handler

  • policies – set handler policies

  • accountId – account id

  • description – user handler description

  • handlerType – type of handler

  • lambdaId – id of lambda handler

Warning

function does not create handler!

Returns:

True if handler exist otherwise false

async putVerifier(verifierId, policies, accountId, description='')[source]

Replace verifier by id.

Return type:

Optional[int]

Parameters:
  • verifierId – verifier id

  • policies – verifier policies

  • accountId – account id

  • description – user verifier description

Warning

function does not create verifier!

Returns:

verifier current version if verifier replaced