[cli][domain] update_db is now run with a string as argument
This commit is contained in:
parent
cdcf8d034d
commit
976ba9b808
|
@ -39,14 +39,11 @@ def list_routes(domain):
|
||||||
#################
|
#################
|
||||||
# domain update #
|
# domain update #
|
||||||
#################
|
#################
|
||||||
def update_db(domains):
|
def update_db():
|
||||||
|
|
||||||
def add_domain(domain):
|
def add_domain():
|
||||||
"""
|
"""
|
||||||
Inserts Domain into database
|
Inserts Domain into database
|
||||||
|
|
||||||
Parameters:
|
|
||||||
- domain (str): The domain's name
|
|
||||||
"""
|
"""
|
||||||
new_domain = Domain(name=domain)
|
new_domain = Domain(name=domain)
|
||||||
if len(new_domain) == 0:
|
if len(new_domain) == 0:
|
||||||
|
@ -54,7 +51,7 @@ def update_db(domains):
|
||||||
new_domain.insert()
|
new_domain.insert()
|
||||||
|
|
||||||
|
|
||||||
def add_router(name, domain):
|
def add_router(name):
|
||||||
"""
|
"""
|
||||||
Inserts Router into database
|
Inserts Router into database
|
||||||
|
|
||||||
|
@ -69,13 +66,12 @@ def update_db(domains):
|
||||||
router.insert()
|
router.insert()
|
||||||
|
|
||||||
|
|
||||||
def add_acl_fct(fct, domain):
|
def add_acl_fct(fct):
|
||||||
"""
|
"""
|
||||||
Inserts ACL function into database
|
Inserts ACL function into database
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
- fct (Callable): The ACL function reference
|
- fct (Callable): The ACL function reference
|
||||||
- domain (str): The Domain's name
|
|
||||||
"""
|
"""
|
||||||
acl = AclFunction()
|
acl = AclFunction()
|
||||||
acl.domain = domain
|
acl.domain = domain
|
||||||
|
@ -161,7 +157,7 @@ def update_db(domains):
|
||||||
return '_'.join(fct_name)
|
return '_'.join(fct_name)
|
||||||
|
|
||||||
|
|
||||||
def add_route(http_verb, path, router, domain, acls):
|
def add_route(http_verb, path, router, acls):
|
||||||
"""
|
"""
|
||||||
Inserts Route into database
|
Inserts Route into database
|
||||||
|
|
||||||
|
@ -169,7 +165,6 @@ def update_db(domains):
|
||||||
- http_verb (str): The Route's HTTP method (GET, POST, ...)
|
- http_verb (str): The Route's HTTP method (GET, POST, ...)
|
||||||
- path (str): A path beginning by '/' for the route
|
- path (str): A path beginning by '/' for the route
|
||||||
- router (str): The Route's Router name
|
- router (str): The Route's Router name
|
||||||
- domain (str): The Domain's name
|
|
||||||
- acls (List[Callable]): The list of ACL functions for this Route
|
- acls (List[Callable]): The list of ACL functions for this Route
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -191,63 +186,62 @@ def update_db(domains):
|
||||||
|
|
||||||
sys.path.insert(0, BASE_DIR)
|
sys.path.insert(0, BASE_DIR)
|
||||||
|
|
||||||
for domain in domains:
|
# Reset Domain relations
|
||||||
# Reset Domain relations
|
delete_domain(domain)
|
||||||
delete_domain(domain)
|
|
||||||
|
|
||||||
acl_set = set()
|
acl_set = set()
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Module retrieval
|
||||||
|
dom_mod = importlib.import_module(domain)
|
||||||
|
except ImportError:
|
||||||
|
# Domain is not available in current PYTHONPATH
|
||||||
|
click.echo(f"Can't import *{domain}*", err=True)
|
||||||
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
|
add_domain(domain)
|
||||||
|
except Exception as e:
|
||||||
|
# Could not insert Domain
|
||||||
|
# @TODO : Insertion exception handling
|
||||||
|
click.echo(e)
|
||||||
|
click.echo(f"Could not insert *{domain}*", err=True)
|
||||||
|
continue
|
||||||
|
|
||||||
|
# add sub routers
|
||||||
|
try:
|
||||||
|
ROUTERS = dom_mod.ROUTERS
|
||||||
|
except AttributeError:
|
||||||
|
# No ROUTERS variable in current domain, check domain/__init__.py
|
||||||
|
click.echo(f'The domain {domain} has no *ROUTERS* variable', err=True)
|
||||||
|
|
||||||
|
for router_name in dom_mod.ROUTERS:
|
||||||
try:
|
try:
|
||||||
# Module retrieval
|
router_mod = getattr(dom_mod.routers, router_name)
|
||||||
dom_mod = importlib.import_module(domain)
|
except AttributError:
|
||||||
except ImportError:
|
# Missing router, continue
|
||||||
# Domain is not available in current PYTHONPATH
|
click.echo(f'The domain {domain} has no *{router_name}* router', err=True)
|
||||||
click.echo(f"Can't import *{domain}*", err=True)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
add_domain(domain)
|
add_router(router_name, domain)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Could not insert Domain
|
# Could not insert Router
|
||||||
# @TODO : Insertion exception handling
|
# @TODO : Insertion exception handling
|
||||||
click.echo(e)
|
print(e)
|
||||||
click.echo(f"Could not insert *{domain}*", err=True)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# add sub routers
|
|
||||||
try:
|
|
||||||
ROUTERS = dom_mod.ROUTERS
|
|
||||||
except AttributeError:
|
|
||||||
# No ROUTERS variable in current domain, check domain/__init__.py
|
|
||||||
click.echo(f'The domain {domain} has no *ROUTERS* variable', err=True)
|
|
||||||
|
|
||||||
for router_name in dom_mod.ROUTERS:
|
for route_path, route_params in router_mod.ROUTES.items():
|
||||||
try:
|
for http_verb, acls in route_params.items():
|
||||||
router_mod = getattr(dom_mod.routers, router_name)
|
try:
|
||||||
except AttributError:
|
# Insert a route and it's ACLS
|
||||||
# Missing router, continue
|
add_route(http_verb, route_path, router_name, domain, acls)
|
||||||
click.echo(f'The domain {domain} has no *{router_name}* router', err=True)
|
except Exception as e:
|
||||||
continue
|
# Could not insert route
|
||||||
|
# @TODO : Insertion exception handling
|
||||||
try:
|
print(e)
|
||||||
add_router(router_name, domain)
|
continue
|
||||||
except Exception as e:
|
|
||||||
# Could not insert Router
|
|
||||||
# @TODO : Insertion exception handling
|
|
||||||
print(e)
|
|
||||||
continue
|
|
||||||
|
|
||||||
|
|
||||||
for route_path, route_params in router_mod.ROUTES.items():
|
|
||||||
for http_verb, acls in route_params.items():
|
|
||||||
try:
|
|
||||||
# Insert a route and it's ACLS
|
|
||||||
add_route(http_verb, route_path, router_name, domain, acls)
|
|
||||||
except Exception as e:
|
|
||||||
# Could not insert route
|
|
||||||
# @TODO : Insertion exception handling
|
|
||||||
print(e)
|
|
||||||
continue
|
|
||||||
|
|
||||||
|
|
||||||
#################
|
#################
|
||||||
|
|
Loading…
Reference in New Issue