[0.5.2] /halfapi/acls crash if acl attribute does not exist on a route

This commit is contained in:
Maxime Alves LIRMM 2021-06-07 19:40:04 +02:00
parent 3fb6fb4ded
commit eb68d06ac0
3 changed files with 8 additions and 2 deletions

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
__version__ = '0.5.1' __version__ = '0.5.2'
def version(): def version():
return f'HalfAPI version:{__version__}' return f'HalfAPI version:{__version__}'

View File

@ -6,7 +6,7 @@ lib/domain.py The domain-scoped utility functions
import sys import sys
import importlib import importlib
import logging import logging
from types import ModuleType from types import ModuleType, FunctionType
from typing import Generator, Dict, List from typing import Generator, Dict, List
logger = logging.getLogger("uvicorn.asgi") logger = logging.getLogger("uvicorn.asgi")
@ -188,6 +188,9 @@ def router_acls(route_params: Dict, path: List, m_router: ModuleType) -> Generat
else: else:
for param in params: for param in params:
acl = param.get('acl') acl = param.get('acl')
if not isinstance(acl, FunctionType):
continue
yield acl.__name__, acl yield acl.__name__, acl

View File

@ -169,6 +169,9 @@ def api_acls(request):
for domain, m_domain in domains.items(): for domain, m_domain in domains.items():
res[domain] = {} res[domain] = {}
for acl_name, fct in domain_acls(m_domain, [domain]): for acl_name, fct in domain_acls(m_domain, [domain]):
if not isinstance(fct, FunctionType):
continue
fct_result = fct.__doc__.strip() if doc and fct.__doc__ else fct(request) fct_result = fct.__doc__.strip() if doc and fct.__doc__ else fct(request)
if acl_name in res[domain]: if acl_name in res[domain]:
continue continue