join tested auth service login/select completed
This commit is contained in:
@@ -5,12 +5,10 @@ from api_initializer.create_app import create_app
|
||||
|
||||
# from prometheus_fastapi_instrumentator import Instrumentator
|
||||
|
||||
|
||||
app = create_app() # Create FastAPI application
|
||||
# Instrumentator().instrument(app=app).expose(app=app) # Setup Prometheus metrics
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Run the application with Uvicorn Server
|
||||
uvicorn_config = uvicorn.Config(**api_config.app_as_dict)
|
||||
uvicorn_config = uvicorn.Config(**api_config.app_as_dict, workers=1) # Run the application with Uvicorn Server
|
||||
uvicorn.Server(uvicorn_config).run()
|
||||
|
||||
@@ -3,34 +3,35 @@ from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import RedirectResponse
|
||||
from event_clusters import RouterCluster, EventCluster
|
||||
from config import api_config
|
||||
from open_api_creator import create_openapi_schema
|
||||
from create_route import RouteRegisterController
|
||||
|
||||
from api_middlewares.token_middleware import token_middleware
|
||||
from endpoints.routes import get_routes
|
||||
import events
|
||||
|
||||
|
||||
cluster_is_set = False
|
||||
|
||||
|
||||
def create_events_if_any_cluster_set():
|
||||
import events
|
||||
|
||||
global cluster_is_set
|
||||
if not events.__all__ or cluster_is_set:
|
||||
return
|
||||
|
||||
router_cluster_stack: list[RouterCluster] = [getattr(events, e, None) for e in events.__all__]
|
||||
for router_cluster in router_cluster_stack:
|
||||
event_cluster_stack: list[EventCluster] = list(router_cluster.event_clusters.values())
|
||||
for event_cluster in event_cluster_stack:
|
||||
try:
|
||||
event_cluster.set_events_to_database()
|
||||
except Exception as e:
|
||||
print(f"Error creating event cluster: {e}")
|
||||
|
||||
cluster_is_set = True
|
||||
|
||||
|
||||
def create_app():
|
||||
from open_api_creator import create_openapi_schema
|
||||
from middlewares.token_middleware import token_middleware
|
||||
from create_route import RouteRegisterController
|
||||
from endpoints.routes import get_routes
|
||||
|
||||
def create_events_if_any_cluster_set():
|
||||
|
||||
global cluster_is_set
|
||||
if not events.__all__ or cluster_is_set:
|
||||
return
|
||||
|
||||
router_cluster_stack: list[RouterCluster] = [getattr(events, e, None) for e in events.__all__]
|
||||
for router_cluster in router_cluster_stack:
|
||||
event_cluster_stack: list[EventCluster] = list(router_cluster.event_clusters.values())
|
||||
for event_cluster in event_cluster_stack:
|
||||
try:
|
||||
event_cluster.set_events_to_database()
|
||||
except Exception as e:
|
||||
print(f"Error creating event cluster: {e}")
|
||||
|
||||
cluster_is_set = True
|
||||
|
||||
application = FastAPI(**api_config.api_info)
|
||||
application.add_middleware(
|
||||
|
||||
@@ -12,44 +12,27 @@ class RouteRegisterController:
|
||||
def add_router_with_event_to_database(router: APIRouter):
|
||||
from schemas import EndpointRestriction
|
||||
|
||||
# Endpoint operation_id is static now if record exits update() record else create()
|
||||
with EndpointRestriction.new_session() as db_session:
|
||||
EndpointRestriction.set_session(db_session)
|
||||
for route in router.routes:
|
||||
route_path = str(getattr(route, "path"))
|
||||
route_summary = str(getattr(route, "name"))
|
||||
operation_id = getattr(route, "operation_id", None)
|
||||
if not operation_id:
|
||||
raise ValueError(f"Route {route_path} operation_id is not found")
|
||||
if not getattr(route, "methods") and isinstance(getattr(route, "methods")):
|
||||
raise ValueError(f"Route {route_path} methods is not found")
|
||||
|
||||
for route_method in [
|
||||
method.lower() for method in getattr(route, "methods")
|
||||
]:
|
||||
methods = [method.lower() for method in getattr(route, "methods")]
|
||||
print('methods count : ', len(methods))
|
||||
print(dict(
|
||||
route_method=route_method,
|
||||
operation_uu_id=operation_id,
|
||||
route_path=route_path,
|
||||
route_summary=route_summary,
|
||||
))
|
||||
# add_or_update_dict = dict(
|
||||
# endpoint_method=route_method,
|
||||
# endpoint_name=route_path,
|
||||
# endpoint_desc=route_summary.replace("_", " "),
|
||||
# endpoint_function=route_summary,
|
||||
# operation_uu_id=operation_id,
|
||||
# is_confirmed=True,
|
||||
# )
|
||||
# endpoint_restriction_found = EndpointRestriction.filter_one_system(
|
||||
# EndpointRestriction.operation_uu_id == operation_id, db=db_session,
|
||||
# ).data
|
||||
# if endpoint_restriction_found:
|
||||
# endpoint_restriction_found.update(**add_or_update_dict, db=db_session)
|
||||
# endpoint_restriction_found.save(db=db_session)
|
||||
# else:
|
||||
# restriction = EndpointRestriction.find_or_create(**add_or_update_dict, db=db_session)
|
||||
# if restriction.meta_data.created:
|
||||
# restriction.save(db=db_session)
|
||||
route_method = [method.lower() for method in getattr(route, "methods")][0]
|
||||
add_or_update_dict = dict(
|
||||
endpoint_method=route_method, endpoint_name=route_path, endpoint_desc=route_summary.replace("_", " "), endpoint_function=route_summary, is_confirmed=True
|
||||
)
|
||||
if to_save_endpoint := EndpointRestriction.query.filter(EndpointRestriction.operation_uu_id == operation_id).first():
|
||||
to_save_endpoint.update(**add_or_update_dict)
|
||||
to_save_endpoint.save()
|
||||
else:
|
||||
created_endpoint = EndpointRestriction.create(**add_or_update_dict, operation_uu_id=operation_id)
|
||||
created_endpoint.save()
|
||||
|
||||
def register_routes(self):
|
||||
for router in self.router_list:
|
||||
|
||||
@@ -39,18 +39,23 @@ class EventCluster:
|
||||
# EndpointRestriction.operation_uu_id == self.endpoint_uu_id,
|
||||
# db=db_session,
|
||||
# ).data:
|
||||
for event in self.events:
|
||||
event_dict_to_save = dict(
|
||||
function_code=event.key,
|
||||
function_class=event.name,
|
||||
description=event.description,
|
||||
endpoint_code=self.endpoint_uu_id,
|
||||
endpoint_id=to_save_endpoint.id,
|
||||
endpoint_uu_id=str(to_save_endpoint.uu_id),
|
||||
is_confirmed=True,
|
||||
db=db_session,
|
||||
)
|
||||
print('event_dict_to_save', event_dict_to_save)
|
||||
Events.set_session(db_session)
|
||||
EndpointRestriction.set_session(db_session)
|
||||
|
||||
if to_save_endpoint := EndpointRestriction.query.filter(EndpointRestriction.operation_uu_id == self.endpoint_uu_id).first():
|
||||
print('to_save_endpoint', to_save_endpoint)
|
||||
for event in self.events:
|
||||
event_dict_to_save = dict(
|
||||
function_code=event.key,
|
||||
function_class=event.name,
|
||||
description=event.description,
|
||||
endpoint_code=self.endpoint_uu_id,
|
||||
endpoint_id=to_save_endpoint.id,
|
||||
endpoint_uu_id=str(to_save_endpoint.uu_id),
|
||||
is_confirmed=True,
|
||||
)
|
||||
print('set_events_to_database event_dict_to_save', event_dict_to_save)
|
||||
|
||||
# event_found = Events.filter_one(
|
||||
# Events.function_code == event_dict_to_save["function_code"],
|
||||
# db=db_session,
|
||||
|
||||
Reference in New Issue
Block a user