updated docs
This commit is contained in:
@@ -18,14 +18,12 @@ from .auth_middleware import MiddlewareModule
|
||||
from Schemas import Events
|
||||
|
||||
|
||||
|
||||
class EventFunctions:
|
||||
|
||||
def __init__(self, endpoint: str, request: Request):
|
||||
self.endpoint = endpoint
|
||||
self.request = request
|
||||
|
||||
|
||||
def match_endpoint_with_accesiable_event(self) -> Optional[Dict[str, Any]]:
|
||||
"""
|
||||
Match an endpoint with accessible events.
|
||||
@@ -221,6 +219,7 @@ class TokenEventMiddleware:
|
||||
# # First apply authentication
|
||||
# authenticated_func = MiddlewareModule.auth_required(func)
|
||||
authenticated_func = func
|
||||
|
||||
@wraps(authenticated_func)
|
||||
async def wrapper(request: Request, *args, **kwargs) -> Dict[str, Any]:
|
||||
|
||||
@@ -233,9 +232,11 @@ class TokenEventMiddleware:
|
||||
loc=get_line_number_for_error(),
|
||||
sys_msg="Function code not found",
|
||||
)
|
||||
|
||||
|
||||
# Make handler available to all functions in the chain
|
||||
func.func_code = EventFunctions(endpoint_url, request).match_endpoint_with_accesiable_event()
|
||||
func.func_code = EventFunctions(
|
||||
endpoint_url, request
|
||||
).match_endpoint_with_accesiable_event()
|
||||
# Call the authenticated function
|
||||
if inspect.iscoroutinefunction(authenticated_func):
|
||||
return await authenticated_func(request, *args, **kwargs)
|
||||
@@ -243,7 +244,6 @@ class TokenEventMiddleware:
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
@staticmethod
|
||||
def validation_required(
|
||||
func: Callable[..., Dict[str, Any]]
|
||||
@@ -268,7 +268,9 @@ class TokenEventMiddleware:
|
||||
request: Request, *args: Any, **kwargs: Any
|
||||
) -> Union[Dict[str, Any], BaseModel]:
|
||||
# Handle both async and sync functions
|
||||
endpoint_asked = getattr(kwargs.get("data", None), "data", None).get("endpoint", None)
|
||||
endpoint_asked = getattr(kwargs.get("data", None), "data", None).get(
|
||||
"endpoint", None
|
||||
)
|
||||
if not endpoint_asked:
|
||||
raise HTTPExceptionApi(
|
||||
error_code="",
|
||||
@@ -276,7 +278,9 @@ class TokenEventMiddleware:
|
||||
loc=get_line_number_for_error(),
|
||||
sys_msg="Endpoint not found",
|
||||
)
|
||||
wrapper.validation_code = EventFunctions(endpoint_asked, request).retrieve_function_dict()
|
||||
wrapper.validation_code = EventFunctions(
|
||||
endpoint_asked, request
|
||||
).retrieve_function_dict()
|
||||
if inspect.iscoroutinefunction(authenticated_func):
|
||||
result = await authenticated_func(request, *args, **kwargs)
|
||||
else:
|
||||
@@ -289,4 +293,5 @@ class TokenEventMiddleware:
|
||||
if inspect.iscoroutine(result):
|
||||
result = await result
|
||||
return result
|
||||
|
||||
return wrapper
|
||||
|
||||
Reference in New Issue
Block a user