Source code for luna_configurator.app.handlers.base_handler

from app.app import ConfiguratorApp, ConfiguratorRequest
from app.handlers.schemas import TAG, TYPE_STR
from configs.configs.configs.services import SettingsConfigurator
from crutches_on_wheels.web.handlers import BaseHandler


[docs]class BaseRequestHandler(BaseHandler): """ Base handler for other handlers. Attributes: apiVersion(int): API version dbContext(DBContext): database context """ def __init__(self, request: ConfiguratorRequest) -> None: """ Init Args: request: Request object """ super().__init__(request) self.apiVersion = request.app.ctx.apiVersion self.dbContext = request.dbContext @property def app(self) -> ConfiguratorApp: """ Get running app Returns: app """ return self.request.app @property def config(self) -> SettingsConfigurator: """ Get app config Returns: app config """ return self.app.ctx.serviceConfig
[docs] async def getSettingSchema(self, settingName: str) -> dict: """ Get validation schema for setting Args: settingName: setting name Returns: validation schema for setting """ validationSchema = { "type": "object", "properties": { "tags": {"type": "array", "items": TAG, "minItems": 0}, "name": {"type": "string", "enum": (await self.dbContext.getAllSettingNames())}, "value": {"type": "unknown"}, "description": TYPE_STR(128), }, "required": ["tags", "name", "value"], "additionalProperties": False, } validationSchema["properties"]["value"] = (await self.dbContext.getLimitation(settingName))["validation_schema"] return validationSchema