diff --git a/halfapi/conf.py b/halfapi/conf.py index 2003864..5005446 100644 --- a/halfapi/conf.py +++ b/halfapi/conf.py @@ -14,7 +14,7 @@ default_config = { } } -config = ConfigParser() +config = ConfigParser(allow_no_value=True) config.read_dict(default_config) config.read(filenames=['.halfapiconfig']) @@ -40,3 +40,5 @@ with open(config.get('project', 'secret')) as secret_file: PRODUCTION = config.getboolean('project', 'production') BASE_DIR = config.get('project', 'base_dir') + +DOMAINS = [domain for domain in config.get('domains').keys()] diff --git a/halfapi/lib/routes.py b/halfapi/lib/routes.py index 236847f..f60f006 100644 --- a/halfapi/lib/routes.py +++ b/halfapi/lib/routes.py @@ -3,8 +3,8 @@ from functools import wraps import importlib import sys -from halfapi.conf import (PROJECT_NAME, HOST, PORT, - PRODUCTION) +from halfapi.conf import (PROJECT_NAME, DB_NAME, HOST, PORT, + PRODUCTION, DOMAINS) from halfapi.db import ( Domain, @@ -17,6 +17,9 @@ from starlette.exceptions import HTTPException from starlette.routing import Mount, Route from starlette.requests import Request +class DomainNotFoundError(Exception): + pass + def get_routes(domains=None): """ Procedure to mount the registered domains on their prefixes @@ -43,7 +46,12 @@ def get_routes(domains=None): return caller app_routes = [] - for domain in Domain(name=domains).select(): + for domaine_name in DOMAINS: + try: + domain = next(Domain(name=domain_name).select()) + except StopIteration: + raise DomainNotFoundError( + f"Domain '{domain_name}' not found in '{DB_NAME}' database!") domain_acl_mod = importlib.import_module(f'{domain["name"]}.acl') domain_routes = [] for router in APIRouter(domain=domain['name']).select():