From 17261f7da916364342518f375ca291c08de522f4 Mon Sep 17 00:00:00 2001 From: Maxime Alves LIRMM Date: Tue, 7 Jul 2020 12:59:52 +0200 Subject: [PATCH] =?UTF-8?q?[middleware]=C2=A0pass=20domain's=20acl=20modul?= =?UTF-8?q?e=20as=20parameter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- halfapi/lib/acl_middleware.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/halfapi/lib/acl_middleware.py b/halfapi/lib/acl_middleware.py index 5f1bc3c..6109622 100644 --- a/halfapi/lib/acl_middleware.py +++ b/halfapi/lib/acl_middleware.py @@ -4,6 +4,10 @@ from starlette.exceptions import HTTPException from starlette.middleware.base import BaseHTTPMiddleware class AclMiddleware(BaseHTTPMiddleware): + def __init__(self, app, acl_module): + super().__init__(app) + self.acl_module = acl_module + async def dispatch(self, request: Request, call_next): """ Checks the "acls" key in the scope and applies the corresponding functions in the current module's acl lib. @@ -12,10 +16,10 @@ class AclMiddleware(BaseHTTPMiddleware): """ print(f'Hit acl {__name__} middleware') - for acl_fnct_name in request.scope['acls']: - print(f'Will apply {acl_fnct_name}') + for acl_fct_name in request.scope['acls']: + print(f'Will apply {acl_fct_name}') try: - fct = getattr(acl, acl_fct_name) + fct = getattr(self.acl_module, acl_fct_name) if fct(request) is True: print(f'{fct} : {fct(request)}\n')