Source code for luna_backport3.app.handlers.version_handler

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

Module realize version handler.
"""
from sanic.response import HTTPResponse

from app.handlers.base_handler import BaseHandler
from app.version import VERSION


[docs]class VersionHandler(BaseHandler): """ Handler for getting version """
[docs] @staticmethod def makeVersionBackward(version: dict) -> dict: """ Prepare version response in backward format Args: version: version in current API format Returns: version in backward format """ return {"Version": {key.replace("-", "_"): value for key, value in version.items()}}
[docs] async def get(self) -> HTTPResponse: """ Get version of services, see `spec_get_version`_. .. _spec_get_version: _static/api.html#operation/getVersion Resource is reached by address '/version' """ reply = await self.lunaApiClient.getVersion(raiseError=True) result = reply.json result["luna-backport3"] = VERSION["Version"] return self.success(outputJson=self.makeVersionBackward(result))