[acls] /halfapi/acls posé
This commit is contained in:
parent
360f59b6ba
commit
79210e503e
@ -16,8 +16,8 @@ from halfapi.conf import HOST, PORT, DB_NAME, SECRET, PRODUCTION, DOMAINS, DOMAI
|
|||||||
from halfapi.lib.jwt_middleware import JWTAuthenticationBackend
|
from halfapi.lib.jwt_middleware import JWTAuthenticationBackend
|
||||||
|
|
||||||
from halfapi.lib.responses import *
|
from halfapi.lib.responses import *
|
||||||
from halfapi.lib.routes import gen_starlette_routes
|
from halfapi.lib.routes import gen_starlette_routes, api_routes
|
||||||
from halfapi.lib.schemas import get_api_routes, schema_json
|
from halfapi.lib.schemas import get_api_routes, schema_json, get_acls
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -34,7 +34,8 @@ if not PRODUCTION:
|
|||||||
ORJSONResponse({'user':request.user.json})
|
ORJSONResponse({'user':request.user.json})
|
||||||
if type(request.user) != UnauthenticatedUser
|
if type(request.user) != UnauthenticatedUser
|
||||||
else ORJSONResponse({'user': None})),
|
else ORJSONResponse({'user': None})),
|
||||||
Route('/halfapi/schema', schema_json)
|
Route('/halfapi/schema', schema_json),
|
||||||
|
Route('/halfapi/acls', get_acls)
|
||||||
]
|
]
|
||||||
|
|
||||||
for domain, m_domain in DOMAINSDICT.items():
|
for domain, m_domain in DOMAINSDICT.items():
|
||||||
@ -42,6 +43,12 @@ for domain, m_domain in DOMAINSDICT.items():
|
|||||||
routes.append(route)
|
routes.append(route)
|
||||||
|
|
||||||
|
|
||||||
|
d_api = {}
|
||||||
|
d_acl = {}
|
||||||
|
for domain, m_domain in DOMAINSDICT.items():
|
||||||
|
d_api[domain], d_acl[domain] = api_routes(m_domain)
|
||||||
|
|
||||||
|
|
||||||
application = Starlette(
|
application = Starlette(
|
||||||
debug=not PRODUCTION,
|
debug=not PRODUCTION,
|
||||||
routes=routes,
|
routes=routes,
|
||||||
|
@ -107,7 +107,6 @@ def gen_router_routes(m_router, path=None):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def gen_domain_routes(domain):
|
def gen_domain_routes(domain):
|
||||||
m_router = importlib.import_module('.routers', domain)
|
m_router = importlib.import_module('.routers', domain)
|
||||||
|
|
||||||
|
@ -101,18 +101,22 @@ def api_routes(m_dom: ModuleType) -> Generator:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
m_dom_acl = importlib.import_module('.acl', m_dom.__name__)
|
m_dom_acl = importlib.import_module('.acl', m_dom.__name__)
|
||||||
|
d_acls = {}
|
||||||
def pop_acl(r):
|
|
||||||
if 'acl' in r.keys():
|
|
||||||
r.pop('acl')
|
|
||||||
return r
|
|
||||||
|
|
||||||
def str_acl(params):
|
def str_acl(params):
|
||||||
l_params = []
|
l_params = []
|
||||||
|
access = None
|
||||||
|
|
||||||
for param in params:
|
for param in params:
|
||||||
if 'acl' not in param.keys():
|
if 'acl' not in param.keys():
|
||||||
continue
|
continue
|
||||||
l_params.append({'acl': param['acl'].__name__})
|
|
||||||
|
l_params.append(param.copy())
|
||||||
|
l_params[-1]['acl'] = param['acl'].__name__
|
||||||
|
|
||||||
|
if param['acl'] not in d_acls.keys():
|
||||||
|
d_acls[param['acl'].__name__] = param['acl']
|
||||||
|
|
||||||
return l_params
|
return l_params
|
||||||
|
|
||||||
d_res = {}
|
d_res = {}
|
||||||
@ -124,4 +128,16 @@ def api_routes(m_dom: ModuleType) -> Generator:
|
|||||||
continue
|
continue
|
||||||
d_res[path][verb] = str_acl(d_route[verb]['params'])
|
d_res[path][verb] = str_acl(d_route[verb]['params'])
|
||||||
|
|
||||||
return d_res
|
return d_res, d_acls
|
||||||
|
|
||||||
|
|
||||||
|
def api_acls(request):
|
||||||
|
from .. import app
|
||||||
|
res = {}
|
||||||
|
for domain in app.d_acl.keys():
|
||||||
|
res[domain] = {}
|
||||||
|
for acl_name, fct in app.d_acl[domain].items():
|
||||||
|
print( fct(request) )
|
||||||
|
res[domain][acl_name] = fct(request)
|
||||||
|
|
||||||
|
return res
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
from ..conf import DOMAINSDICT
|
from ..conf import DOMAINSDICT
|
||||||
from .routes import gen_starlette_routes, api_routes
|
from .routes import gen_starlette_routes
|
||||||
from .responses import *
|
from .responses import *
|
||||||
|
from .jwt_middleware import UnauthenticatedUser, JWTUser
|
||||||
from starlette.schemas import SchemaGenerator
|
from starlette.schemas import SchemaGenerator
|
||||||
from starlette.routing import Router
|
from starlette.routing import Router
|
||||||
SCHEMAS = SchemaGenerator(
|
SCHEMAS = SchemaGenerator(
|
||||||
@ -38,11 +39,9 @@ async def get_api_routes(request, *args, **kwargs):
|
|||||||
description: Returns the current API routes description (HalfAPI 0.2.1)
|
description: Returns the current API routes description (HalfAPI 0.2.1)
|
||||||
as a JSON object
|
as a JSON object
|
||||||
"""
|
"""
|
||||||
#TODO: LADOC
|
from .. import app
|
||||||
d_api = {}
|
|
||||||
for domain, m_domain in DOMAINSDICT.items():
|
return ORJSONResponse(app.d_api)
|
||||||
d_api[domain] = api_routes(m_domain)
|
|
||||||
return ORJSONResponse(d_api)
|
|
||||||
|
|
||||||
|
|
||||||
async def schema_json(request, *args, **kwargs):
|
async def schema_json(request, *args, **kwargs):
|
||||||
@ -73,3 +72,16 @@ def schema_dict_dom(m_domain: ModuleType) -> Dict:
|
|||||||
routes = [
|
routes = [
|
||||||
elt for elt in gen_starlette_routes(m_domain) ]
|
elt for elt in gen_starlette_routes(m_domain) ]
|
||||||
return SCHEMAS.get_schema(routes=routes)
|
return SCHEMAS.get_schema(routes=routes)
|
||||||
|
|
||||||
|
|
||||||
|
async def get_acls(request, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: A dictionnary of the domains and their acls, with the
|
||||||
|
result of the acls functions
|
||||||
|
"""
|
||||||
|
|
||||||
|
from .routes import api_acls
|
||||||
|
return ORJSONResponse(api_acls(request))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user