Source code for luna_api.app.handlers.faces_proxy_handler

""" Handler for a certain faces. """
from luna3.common.luna_response import LunaResponse
from sanic.response import HTTPResponse

from app.handlers.base_handler import FacesServiceBaseHandler, ProxyRequest
from crutches_on_wheels.errors.errors import Error
from crutches_on_wheels.errors.exception import VLException


[docs]class FacesHandler(FacesServiceBaseHandler): """ Handler for create new faces. See `spec_faces`_. .. _spec_faces: _static/api.html#tag/faces Resource: "/{api_version}/faces" """ allowedMethods = ("POST", "GET", "DELETE")
[docs] def checkTokenPermissions(self) -> None: """ Description see :func:`~BaseRequestHandler.checkTokenPermissions`. """ self.checkTokenPermissionsDefault(objectName="face")
[docs] async def prepareRequestPost(self) -> ProxyRequest: """ Add account id to new face Returns: proxy request """ proxyRequest = self.prepareRequestCreation() # require to additionally validate `lists` field here to avoid duplicate json body validation if ( self.request.method == "POST" and self.request.credentials.permissions is not None and self.request.json.get("lists") ): if (action := "modification") not in self.request.credentials.permissions.list: raise VLException(Error.ForbiddenByToken.format(action, "list"), 403, False) return proxyRequest
[docs] async def postProcessingPost(self, response: LunaResponse) -> HTTPResponse: """ Update urls in output json and location header Args: response: from faces Returns: response """ return self.success(response.statusCode, outputJson=self.convertIncomingUrls(response))
[docs]class FacesCountHandler(FacesServiceBaseHandler): """ Handler for getting face count. See `spec_get_faces_count`_. .. _spec_get_faces_count: _static/api.html#operation/getFacesCount Resource: "/{api_version}/faces/count" """ allowedMethods = ("GET",)
[docs] def checkTokenPermissions(self) -> None: """ Description see :func:`~BaseRequestHandler.checkTokenPermissions`. """ self.checkTokenPermissionsDefault(objectName="face")
[docs]class FaceHandler(FacesServiceBaseHandler): """ Handler for work with a face. See `spec_face`_. .. _spec_face: _static/api.html#tag/faces Resource: "/{api_version}/faces/{faceId}" """ allowedMethods = ("PATCH", "GET", "DELETE", "HEAD")
[docs] def checkTokenPermissions(self) -> None: """ Description see :func:`~BaseRequestHandler.checkTokenPermissions`. """ self.checkTokenPermissionsDefault(objectName="face")
[docs]class FacesAttributeHandler(FacesServiceBaseHandler): """ Handler for work with a face attributes. See `spec_face_attributes`_. .. _spec_face_attributes: _static/api.html#tag/face-attributes Resource: "/{api_version}/faces/{faceId}/attributes" """ allowedMethods = ("PUT", "GET", "DELETE")
[docs] def checkTokenPermissions(self) -> None: """ Description see :func:`~BaseRequestHandler.checkTokenPermissions`. """ self.checkTokenPermissionsDefault(objectName="face")
[docs]class FacesAttributesCountHandler(FacesServiceBaseHandler): """ Handler for getting count faces with attributes. See `spec_get_face_attribute_count`_. .. _spec_get_face_attribute_count: _static/api.html#operation/getFaceAttributeCount Resource: "/{api_version}/faces/attributes/count" """ allowedMethods = ("GET",)
[docs] def checkTokenPermissions(self) -> None: """ Description see :func:`~BaseRequestHandler.checkTokenPermissions`. """ self.checkTokenPermissionsDefault(objectName="attribute")
[docs]class FacesAttributeSamplesHandler(FacesServiceBaseHandler): """ Handler for work with face attribute samples. See `spec_get_face_attribute_samples`_. .. _spec_get_face_attribute_samples: _static/api.html#operation/getFaceAttributeSamples Resource: "/{api_version}/faces/{faceId}/attributes/samples" """ allowedMethods = ("GET",)
[docs] def checkTokenPermissions(self) -> None: """ Description see :func:`~BaseRequestHandler.checkTokenPermissions`. """ self.checkTokenPermissionsDefault(objectName="faceSample")