From f7879c63889d05106b1665bdeccb9cf7a96bc639 Mon Sep 17 00:00:00 2001 From: Maxime Alves LIRMM Date: Tue, 8 Mar 2022 19:24:21 +0100 Subject: [PATCH] [release] 0.6.10 - Add "x-out" field in HTTP headers when "out" parameters are specified for a route - Add "out" kwarg for not-async functions that specify it - Hide data fields in args_check logs - Fix testing lib for domains (add default secret and debug option) - Domains now need to include the following variables in their __init__.py - __name__ (str, optional) - __id__ (str, optional) - halfapi domain - Mounts domain routers with their ACLs as decorator - Configuration example files for systemd and a system-wide halfapi install - Runs projects - Handles JWT authentication middleware --- CHANGELOG.md | 6 ++++++ halfapi/__init__.py | 2 +- halfapi/half_route.py | 2 ++ halfapi/lib/acl.py | 3 +++ halfapi/lib/domain.py | 4 ++++ halfapi/lib/domain_middleware.py | 5 +++++ 6 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46b17c2..8c62406 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # HalfAPI +## 0.6.10 + +- Add "x-out" field in HTTP headers when "out" parameters are specified for a + route +- Add "out" kwarg for not-async functions that specify it + ## 0.6.9 - Hide data fields in args_check logs diff --git a/halfapi/__init__.py b/halfapi/__init__.py index 7b9c484..21023c9 100644 --- a/halfapi/__init__.py +++ b/halfapi/__init__.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -__version__ = '0.6.9' +__version__ = '0.6.10' def version(): return f'HalfAPI version:{__version__}' diff --git a/halfapi/half_route.py b/halfapi/half_route.py index 77314d8..6011aef 100644 --- a/halfapi/half_route.py +++ b/halfapi/half_route.py @@ -85,6 +85,8 @@ class HalfRoute(Route): 'Args for current route (%s)', param.get('args')) + if 'out' in param: + req.scope['out'] = param['out'].copy() if 'check' in req.query_params: return PlainTextResponse(param['acl'].__name__) diff --git a/halfapi/lib/acl.py b/halfapi/lib/acl.py index 08a124c..8695873 100644 --- a/halfapi/lib/acl.py +++ b/halfapi/lib/acl.py @@ -94,6 +94,9 @@ def args_check(fct): kwargs['data'] = data + if req.scope.get('out'): + kwargs['out'] = req.scope.get('out').copy() + return await fct(req, *args, **kwargs) return caller diff --git a/halfapi/lib/domain.py b/halfapi/lib/domain.py index ad6b4a7..5c87ad7 100644 --- a/halfapi/lib/domain.py +++ b/halfapi/lib/domain.py @@ -64,6 +64,10 @@ def route_decorator(fct: FunctionType, ret_type: str = 'json') -> Coroutine: if 'data' in fct_args_spec: fct_args['data'] = kwargs.get('data') + if 'out' in fct_args_spec: + fct_args['out'] = kwargs.get('out') + + """ If format argument is specified (either by get or by post param) """ ret_type = fct_args.get('data', {}).get('format', 'json') diff --git a/halfapi/lib/domain_middleware.py b/halfapi/lib/domain_middleware.py index f9f82d8..c1f0379 100644 --- a/halfapi/lib/domain_middleware.py +++ b/halfapi/lib/domain_middleware.py @@ -56,6 +56,11 @@ class DomainMiddleware(BaseHTTPMiddleware): response.headers['x-args-optional'] = \ ','.join(request.scope['args']['optional']) + if len(request.scope.get('out', set())): + response.headers['x-out'] = \ + ','.join(request.scope['out']) + + response.headers['x-domain'] = self.domain['name'] return response