From e590bc31fe52847779e31f8107fb0e57b6f3b2a9 Mon Sep 17 00:00:00 2001 From: Maxime Alves LIRMM Date: Wed, 7 Oct 2020 16:13:54 +0200 Subject: [PATCH] [doc] lib/domain, lib/domain_middlware --- halfapi/lib/domain.py | 8 ++++---- halfapi/lib/domain_middleware.py | 11 ++++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/halfapi/lib/domain.py b/halfapi/lib/domain.py index dc7473c..d191464 100644 --- a/halfapi/lib/domain.py +++ b/halfapi/lib/domain.py @@ -108,13 +108,13 @@ def gen_routes(route_params: Dict, path: List, m_router: ModuleType) -> Generato yield f"/{'/'.join([ elt for elt in path if elt ])}", d_res -def gen_router_routes(m_router: ModuleType, path: List[str]): +def gen_router_routes(m_router: ModuleType, path: List[str]) -> Generator: """ Recursive generatore that parses a router (or a subrouter) and yields from gen_routes Parameters: - + - m_router (ModuleType): The currently treated router module - path (List[str]): The current path stack @@ -146,7 +146,7 @@ def gen_router_routes(m_router: ModuleType, path: List[str]): -def gen_domain_routes(domain: str, m_dom: ModuleType): +def gen_domain_routes(domain: str, m_dom: ModuleType) -> Generator: """ Generator that calls gen_router_routes for a domain @@ -162,7 +162,7 @@ def gen_domain_routes(domain: str, m_dom: ModuleType): logger.debug('%s', m_dom) -def d_domains(config): +def d_domains(config) -> Dict[str, ModuleType]: """ Parameters: diff --git a/halfapi/lib/domain_middleware.py b/halfapi/lib/domain_middleware.py index 0287d36..861ba95 100644 --- a/halfapi/lib/domain_middleware.py +++ b/halfapi/lib/domain_middleware.py @@ -23,12 +23,17 @@ class DomainMiddleware(BaseHTTPMiddleware): def __init__(self, app, config): super().__init__(app) self.config = config - - async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: - self.domains = d_domains(self.config) + self.domains = {} self.api = {} self.acl = {} + + async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: + """ + Scans routes and acls of each domain in config + """ + self.domains = d_domains(self.config) + for domain, m_domain in self.domains.items(): self.api[domain], self.acl[domain] = api_routes(m_domain)