diff --git a/halfapi/lib/acl.py b/halfapi/lib/acl.py index b276a81..0e6e91d 100644 --- a/halfapi/lib/acl.py +++ b/halfapi/lib/acl.py @@ -16,12 +16,9 @@ def connected(fct=public): """ @wraps(fct) def caller(req, *args, **kwargs): - print(fct) - print(req.user) if (not hasattr(req, 'user') or isinstance(req.user, UnauthenticatedUser) or not hasattr(req.user, 'is_authenticated')): - print('Connected is false') return False return fct(req, **{**kwargs, **req.path_params}) diff --git a/halfapi/lib/domain.py b/halfapi/lib/domain.py index bc4fc65..9431e54 100644 --- a/halfapi/lib/domain.py +++ b/halfapi/lib/domain.py @@ -158,11 +158,13 @@ def gen_domain_routes(domain: str, m_dom: ModuleType) -> Generator: If not, it is considered as empty """ + m_router = None try: m_router = importlib.import_module('.routers', domain) except ImportError: logger.warning('Domain **%s** has no **routers** module', domain) logger.debug('%s', m_dom) + m_router = importlib.import_module('.routers', f'.{domain}') if m_router: yield from gen_router_routes(m_router, [domain]) diff --git a/halfapi/lib/domain_middleware.py b/halfapi/lib/domain_middleware.py index 861ba95..1d95616 100644 --- a/halfapi/lib/domain_middleware.py +++ b/halfapi/lib/domain_middleware.py @@ -1,7 +1,9 @@ """ DomainMiddleware """ +import logging +from starlette.datastructures import URL from starlette.middleware.base import (BaseHTTPMiddleware, RequestResponseEndpoint) from starlette.requests import Request @@ -10,6 +12,9 @@ from starlette.types import Scope, Send, Receive from .routes import api_routes from .domain import d_domains +from ..conf import config_dict + +logger = logging.getLogger('uvicorn.asgi') class DomainMiddleware(BaseHTTPMiddleware): """ @@ -41,6 +46,18 @@ class DomainMiddleware(BaseHTTPMiddleware): scope_['domains'] = self.domains scope_['api'] = self.api scope_['acl'] = self.acl + + cur_path = URL(scope=scope).path + if cur_path[0] == '/': + current_domain = cur_path[1:].split('/')[0] + else: + current_domain = cur_path.split('/')[0] + + if len(current_domain): + config_section = self.config.items(current_domain) + scope_['config'] = dict(config_section) + + request = Request(scope_, receive) response = await self.dispatch(request, self.call_next) await response(scope_, receive, send)