Web service initiated

This commit is contained in:
2025-04-05 14:59:10 +03:00
parent b1c8203a33
commit fa4df11323
76 changed files with 5385 additions and 171 deletions

View File

@@ -9,30 +9,31 @@ class RouteRegisterController:
self.app = app
@staticmethod
def add_router_with_event_to_database(route: APIRouter):
def add_router_with_event_to_database(router: APIRouter):
from Schemas import EndpointRestriction
with EndpointRestriction.new_session() as db_session:
route_path = str(getattr(route, "path"))
route_summary = str(getattr(route, "name")) or ""
operation_id = str(getattr(route, "operation_id")) or ""
if not operation_id:
return
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:
continue
for route_method in [method.lower() for method in getattr(route, "methods")]:
restriction = EndpointRestriction.find_or_create(
**dict(
for route_method in [
method.lower() for method in getattr(route, "methods")
]:
restriction = EndpointRestriction.find_or_create(
endpoint_method=route_method,
endpoint_name=route_path,
endpoint_desc=route_summary.replace("_", " "),
endpoint_function=route_summary,
operation_uu_id=operation_id, # UUID of the endpoint
operation_uu_id=operation_id, # UUID of the endpoint
is_confirmed=True,
db=db_session,
)
)
if not restriction.meta_data.created:
restriction.endpoint_code = f"AR{str(restriction.id).zfill(3)}"
restriction.save(db=db_session)
if restriction.meta_data.created:
restriction.save(db=db_session)
def register_routes(self):
for router in self.router_list:

View File

@@ -1,4 +1,3 @@
class EventCluster:
def __init__(self, endpoint_uu_id: str):
@@ -25,33 +24,39 @@ class EventCluster:
def set_events_to_database(self):
from Schemas import Events, EndpointRestriction
with Events.new_session() as db_session:
with Events.new_session() as db_session:
if to_save_endpoint := EndpointRestriction.filter_one(
EndpointRestriction.uu_id == self.endpoint_uu_id,
EndpointRestriction.operation_uu_id == self.endpoint_uu_id,
db=db_session,
).data:
for event in self.events:
event_obj = Events.find_or_create(
event_to_save_database = Events.find_or_create(
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,
active=True,
db=db_session,
)
event_obj.save()
print(f'UUID: {event_obj.uu_id} event is saved to {to_save_endpoint.uu_id}')
if event_to_save_database.meta_data.created:
event_to_save_database.save(db=db_session)
print(
f"UUID: {event_to_save_database.uu_id} event is saved to {to_save_endpoint.uu_id}"
)
def match_event(self, event_keys: list[str]) -> "Event":
"""
Match an event by its key
"""
print('set(event_keys)', set(event_keys))
print('event.keys', set([event.key for event in self.events]))
intersection_of_key: set[str] = set(event_keys) & set([event.key for event in self.events])
# print('set(event_keys)', set(event_keys))
# print('event.keys', set([event.key for event in self.events]))
intersection_of_key: set[str] = set(event_keys) & set(
[event.key for event in self.events]
)
if not len(intersection_of_key) == 1:
raise ValueError(
f"Event key not found or multiple matches found: {intersection_of_key}"
@@ -75,7 +80,6 @@ class Event:
self.response_validator = response_validator
self.description = description
def event_callable(self):
"""
Example callable method