Source code for luna_api.app.handlers.version_handler
# -*- coding: utf-8 -*-
"""Version Handler
Module realize version handler.
"""
import asyncio
from typing import Dict
from luna3.common.base_api import BaseHTTPAPI
from app.handlers.base_handler import BaseRequestHandler
from app.platform_version import VERSION as platformVersion
from app.version import VERSION as apiVersion
[docs]class VersionHandler(BaseRequestHandler):
"""
Handler for getting version
"""
[docs] def checkTokenPermissions(self) -> None:
"""
Description see :func:`~BaseRequestHandler.checkTokenPermissions`.
"""
[docs] @staticmethod
async def getVersion(client: BaseHTTPAPI) -> Dict[str, int]:
"""
Get version from a service HTTP client.
Args:
client: HTTP client
Returns:
service version
"""
reply = await client.getVersion(raiseError=True)
return reply.json["Version"]
[docs] async def get(self): # pylint: disable-msg=W0221
"""
Get version of services, see `spec`_
.. _spec:
_static/api.html#operation/getVersion
Resource is reached by address '/version'
"""
(
facesVersion,
faceSamplesVersion,
bodySamplesVersion,
imagesVersion,
handlersVersion,
matcherVersion,
) = await asyncio.gather(
*map(
self.getVersion,
(
self.luna3Client.lunaFaces,
self.luna3Client.lunaFaceSamplesStore,
self.luna3Client.lunaBodySamplesStore,
self.luna3Client.lunaImageOriginStore,
self.luna3Client.lunaHandlers,
self.luna3Client.lunaPythonMatcher,
),
)
)
matcherName = (
"luna-matcher-proxy" if self.config.additionalServicesUsage.lunaMatcherProxy else "luna-python-matcher"
)
result = {
"LUNA PLATFORM": platformVersion["Version"], # must be first
"luna-api": apiVersion["Version"],
"luna-faces": facesVersion,
"luna-handlers": handlersVersion,
"luna-image-store-bodies-samples": bodySamplesVersion,
"luna-image-store-faces-samples": faceSamplesVersion,
"luna-image-store-images": imagesVersion,
matcherName: matcherVersion,
}
if self.config.additionalServicesUsage.lunaEvents:
eventsVersion = await self.getVersion(self.luna3Client.lunaEvents)
result.update({"luna-events": eventsVersion})
if self.config.additionalServicesUsage.lunaTasks:
tasksVersion = await self.getVersion(self.luna3Client.lunaTasks)
result.update({"luna-tasks": tasksVersion})
return self.success(outputJson=result)