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.schemas.verifier import VerifierModel
from crutches_on_wheels.errors.errors import Error
from crutches_on_wheels.errors.exception import VLException
from crutches_on_wheels.web.query_getters import uuidGetter
[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=str(newVerifier.accountId),
)
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()
accountId = self.getQueryParam("account_id", uuidGetter)
description = self.getQueryParam("description")
verifiers = await self.dbContext.getVerifiers(
accountId=accountId, description=description, pageSize=pageSize, page=page
)
return self.success(200, outputJson=verifiers)