Source code for luna_api.app.handlers.liveness_handler

from typing import Optional

from sanic.views import HTTPMethodView

from classes.token import Permissions
from crutches_on_wheels.errors.errors import Error
from crutches_on_wheels.errors.exception import VLException

from ..app import ApiRequest
from .liveness_v1_handler import LivenessV1Handler
from .liveness_v2_handler import LivenessV2Handler


[docs]class LivenessHandler(HTTPMethodView): """ Liveness handler. """
[docs] @staticmethod def checkTokenPermissions(permissions: Optional[Permissions] = None) -> None: """ Check token permissions if specified """ if permissions is not None: if (resource := "liveness") not in permissions.resources: raise VLException(Error.ResourceForbiddenByToken.format(resource), 403, False)
[docs] def post(self, request: ApiRequest): """ Process post request according to service settings. """ self.checkTokenPermissions(request.credentials.permissions) if not request.app.ctx.licenseChecker.licenseState.liveness.value: raise VLException(Error.LicenseProblem.format("Liveness feature disabled"), 403, False) if request.config.additionalServicesUsage.liveness: if request.app.ctx.licenseChecker.licenseState.liveness.value != 1: raise VLException( Error.LicenseProblem.format("Liveness v.1 feature disabled"), 403, False, ) reply = LivenessV1Handler(request).post() else: if request.app.ctx.licenseChecker.licenseState.liveness.value != 2: raise VLException( Error.LicenseProblem.format("Liveness v.2 feature disabled"), 403, False, ) reply = LivenessV2Handler(request).post() return reply