[lib.acl] args_check doesn't check required/optional arguments if "args" is not specified in request, if the target function is not async
This commit is contained in:
parent
aa4c309778
commit
e208728d7e
|
@ -66,7 +66,8 @@ def args_check(fct):
|
||||||
return ', '.join(array)
|
return ', '.join(array)
|
||||||
|
|
||||||
|
|
||||||
args_d = kwargs.get('args', {})
|
args_d = kwargs.get('args', None)
|
||||||
|
if args_d is not None:
|
||||||
required = args_d.get('required', set())
|
required = args_d.get('required', set())
|
||||||
|
|
||||||
missing = []
|
missing = []
|
||||||
|
@ -86,6 +87,10 @@ def args_check(fct):
|
||||||
for key in optional:
|
for key in optional:
|
||||||
if key in data_:
|
if key in data_:
|
||||||
data[key] = data_[key]
|
data[key] = data_[key]
|
||||||
|
else:
|
||||||
|
""" Unsafe mode, without specified arguments
|
||||||
|
"""
|
||||||
|
data = data_
|
||||||
|
|
||||||
kwargs['data'] = data
|
kwargs['data'] = data
|
||||||
|
|
||||||
|
|
|
@ -6,16 +6,33 @@ lib/domain.py The domain-scoped utility functions
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import importlib
|
import importlib
|
||||||
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
from types import ModuleType, FunctionType
|
from types import ModuleType, FunctionType
|
||||||
from typing import Generator, Dict, List
|
from typing import Callable, Generator, Dict, List
|
||||||
|
|
||||||
from halfapi.lib import acl
|
from halfapi.lib import acl
|
||||||
|
from halfapi.lib.responses import ORJSONResponse
|
||||||
|
|
||||||
logger = logging.getLogger("uvicorn.asgi")
|
logger = logging.getLogger("uvicorn.asgi")
|
||||||
|
|
||||||
VERBS = ('GET', 'POST', 'PUT', 'PATCH', 'DELETE')
|
VERBS = ('GET', 'POST', 'PUT', 'PATCH', 'DELETE')
|
||||||
|
|
||||||
|
|
||||||
|
def route_decorator(fct: Callable = None, ret_type: str = 'json'):
|
||||||
|
""" Returns an async function that can be mounted on a router
|
||||||
|
"""
|
||||||
|
if ret_type == 'json':
|
||||||
|
@acl.args_check
|
||||||
|
async def wrapped(request, *args, **kwargs):
|
||||||
|
return ORJSONResponse(
|
||||||
|
fct(**request.path_params, data=kwargs.get('data')))
|
||||||
|
else:
|
||||||
|
raise Exception('Return type not available')
|
||||||
|
|
||||||
|
return wrapped
|
||||||
|
|
||||||
|
|
||||||
def get_fct_name(http_verb: str, path: str) -> str:
|
def get_fct_name(http_verb: str, path: str) -> str:
|
||||||
"""
|
"""
|
||||||
Returns the predictable name of the function for a route
|
Returns the predictable name of the function for a route
|
||||||
|
@ -107,6 +124,9 @@ def gen_routes(route_params: Dict, path: List, m_router: ModuleType) -> Generato
|
||||||
logger.error('%s is not defined in %s', fct_name, m_router.__name__)
|
logger.error('%s is not defined in %s', fct_name, m_router.__name__)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if not inspect.iscoroutinefunction(fct):
|
||||||
|
fct = route_decorator(fct)
|
||||||
|
|
||||||
d_res[verb] = {'fct': fct, 'params': params}
|
d_res[verb] = {'fct': fct, 'params': params}
|
||||||
|
|
||||||
if len(d_res.keys()) > 1:
|
if len(d_res.keys()) > 1:
|
||||||
|
|
Loading…
Reference in New Issue