[doc] lib/domain, lib/domain_middlware

This commit is contained in:
Maxime Alves LIRMM 2020-10-07 16:13:54 +02:00
parent 3959e6d614
commit e590bc31fe
2 changed files with 12 additions and 7 deletions

View File

@ -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 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) Recursive generatore that parses a router (or a subrouter)
and yields from gen_routes and yields from gen_routes
Parameters: Parameters:
- m_router (ModuleType): The currently treated router module - m_router (ModuleType): The currently treated router module
- path (List[str]): The current path stack - 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 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) logger.debug('%s', m_dom)
def d_domains(config): def d_domains(config) -> Dict[str, ModuleType]:
""" """
Parameters: Parameters:

View File

@ -23,12 +23,17 @@ class DomainMiddleware(BaseHTTPMiddleware):
def __init__(self, app, config): def __init__(self, app, config):
super().__init__(app) super().__init__(app)
self.config = config self.config = config
self.domains = {}
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
self.domains = d_domains(self.config)
self.api = {} self.api = {}
self.acl = {} 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(): for domain, m_domain in self.domains.items():
self.api[domain], self.acl[domain] = api_routes(m_domain) self.api[domain], self.acl[domain] = api_routes(m_domain)