Source code for luna_api.app.auth.auth_middleware

"""
Authorization middleware
"""

from vlutils.helpers import isUUID

from app.auth.white_resources_list import WHITE_LIST, WHITE_METHODS
from crutches_on_wheels.errors.errors import Error
from crutches_on_wheels.errors.exception import VLException
from crutches_on_wheels.web.request import VLRequest


[docs]async def authMiddleware(request: VLRequest): """ Authorization middleware, check a request account id Args: request: request """ accountId = request.accountId if not accountId: if not (request.method in WHITE_METHODS or request.path in WHITE_LIST): raise VLException(Error.ForbiddenRootRequestFound, 403, isCriticalError=False) elif not isUUID(accountId): raise VLException(Error.BadAccountId, 400, isCriticalError=False)