35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
from databases import EndpointRestriction
|
|
|
|
|
|
def create_endpoints_from_api_functions(api_app):
|
|
|
|
for route in api_app.routes:
|
|
route_path, route_summary = (
|
|
str(getattr(route, "path")),
|
|
str(getattr(route, "name")) or "",
|
|
)
|
|
# if route_path in Config.INSECURE_PATHS:
|
|
# continue
|
|
# print('route_path ', route_path, 'route_summary', route_summary)
|
|
create_dict = dict(
|
|
is_confirmed=True,
|
|
active=True,
|
|
deleted=False,
|
|
is_notification_send=True,
|
|
)
|
|
methods = [method.lower() for method in getattr(route, "methods")]
|
|
for route_method in methods:
|
|
restriction = EndpointRestriction.find_or_create(
|
|
**dict(
|
|
endpoint_method=route_method,
|
|
endpoint_name=route_path,
|
|
endpoint_desc=route_summary.replace("_", " "),
|
|
endpoint_function=route_summary,
|
|
**create_dict,
|
|
)
|
|
)
|
|
if not restriction.is_found:
|
|
restriction.endpoint_code = f"AR{str(restriction.id).zfill(3)}"
|
|
restriction.save()
|
|
return
|