Source code for luna_handlers.app.handlers.verifiers_handler

""" Verifiers handler. """
from sanic.response import HTTPResponse

from app.handlers.base_handler import BaseHandler
from app.version import VERSION
from classes.query_schemas.verifiers import VerifiersQueries
from classes.schemas.verifier import VerifierModel
from crutches_on_wheels.cow.errors.errors import Error
from crutches_on_wheels.cow.errors.exception import VLException


[docs]class VerifiersHandler(BaseHandler): """ Handler for working with verifiers. Resource: "/{api_version}/verifiers" """
[docs] async def post(self) -> HTTPResponse: """ Create new verifier. See `spec_create_verifier`_. .. _spec_create_verifier: _static/api.html#operation/createVerifier Raises: VLException(Error.BadContentType, 400, isCriticalError=False) if content type is unsupported Returns: response with verifier id and verifier location """ if self.request.content_type == "application/json": newVerifier = self.loadDataFromJson(self.request.json, VerifierModel) verifierId = await self.dbContext.createVerifier( policies=newVerifier.policies.asDict(), description=newVerifier.description, accountId=self.getAccountIdFromHeader(), ) else: raise VLException(Error.BadContentType, 400, isCriticalError=False) location = f"/{VERSION['Version']['api']}/verifiers/{verifierId}" self.respHeaders["Location"] = location return self.success(outputJson={"verifier_id": verifierId, "url": location}, statusCode=201)
[docs] async def get(self) -> HTTPResponse: """ Get verifiers by filters. See `spec_get_verifiers`_. .. _spec_get_verifiers: _static/api.html#operation/getVerifiers Returns: response with list of verifiers """ page, pageSize = self.getPagination() queries: VerifiersQueries = self.loadDataFromQuery(VerifiersQueries) verifiers = await self.dbContext.getVerifiers( accountId=queries.accountId, description=queries.description, pageSize=pageSize, page=page ) return self.success(200, outputJson=verifiers)