Source code for luna_licenses.app.handlers.license_executions_consumption_handler

# -*- coding: utf-8 -*-
"""License Handler

Module realize license handler.
"""

from sanic.response import HTTPResponse

from app.handlers.base_handler import BaseLicensesRequestHandler
from app.handlers.schemas import CONSUME_EXECUTIONS_SCHEMA
from hasplibpybind.hasplib import HaspFeatureEnum


[docs]class ExecutionsHandler(BaseLicensesRequestHandler): """ Handler for consume executions Resource: "/{api_version}/license/executions" """
[docs] async def post(self) -> HTTPResponse: """ Consume executions for the given features, see `spec_post_license_executions`_. .. _spec_post_license_executions: _static/api.html#operation/consumeExecutions """ self.validateJson(self.request.json, CONSUME_EXECUTIONS_SCHEMA, False) result = {} for key, value in self.request.json.items(): feature = dict(liveness=HaspFeatureEnum.PlatformLiveness)[key] executionCount = value["execution_count"] resultError, consumedNumber = self.app.ctx.licensing.consumeBatchOfExecutions(feature, executionCount) result[key] = dict(result=resultError, consumed_executions=consumedNumber) return self.successWithSignature(statusCode=200, outputJson=result)