middleware and respnse models updated
This commit is contained in:
@@ -12,7 +12,10 @@ from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from ApiLayers.ErrorHandlers.Exceptions.api_exc import HTTPExceptionApi
|
||||
from ApiLayers.Middleware.auth_middleware import RequestTimingMiddleware, LoggerTimingMiddleware
|
||||
from ApiLayers.Middleware.auth_middleware import (
|
||||
RequestTimingMiddleware,
|
||||
LoggerTimingMiddleware,
|
||||
)
|
||||
|
||||
|
||||
def setup_cors_middleware(app: FastAPI) -> None:
|
||||
@@ -55,7 +58,9 @@ def setup_exception_handlers(app: FastAPI) -> None:
|
||||
Args:
|
||||
app: FastAPI application instance
|
||||
"""
|
||||
from ApiLayers.ErrorHandlers.ErrorHandlers.api_exc_handler import HTTPExceptionApiHandler
|
||||
from ApiLayers.ErrorHandlers.ErrorHandlers.api_exc_handler import (
|
||||
HTTPExceptionApiHandler,
|
||||
)
|
||||
|
||||
custom_exception_handler = HTTPExceptionApiHandler(response_model=JSONResponse)
|
||||
app.add_exception_handler(
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class DefaultApiConfig:
|
||||
app: str
|
||||
host: str
|
||||
@@ -9,12 +8,12 @@ class DefaultApiConfig:
|
||||
@classmethod
|
||||
def as_dict(cls):
|
||||
return {
|
||||
"app": cls.app,
|
||||
"host": cls.host,
|
||||
"port": int(cls.port),
|
||||
"log_level": cls.log_level,
|
||||
"reload": bool(cls.reload),
|
||||
}
|
||||
"app": cls.app,
|
||||
"host": cls.host,
|
||||
"port": int(cls.port),
|
||||
"log_level": cls.log_level,
|
||||
"reload": bool(cls.reload),
|
||||
}
|
||||
|
||||
|
||||
class ApiStatic:
|
||||
@@ -32,12 +31,13 @@ class ApiStatic:
|
||||
return cls.BLACKLIST_LINK + record_id
|
||||
|
||||
|
||||
|
||||
class ApiConfig(DefaultApiConfig):
|
||||
# Api configuration
|
||||
APP_NAME = "evyos-event-api-gateway"
|
||||
TITLE = "WAG API Event Api Gateway"
|
||||
DESCRIPTION = "This api is serves as web event api gateway only to evyos web services."
|
||||
DESCRIPTION = (
|
||||
"This api is serves as web event api gateway only to evyos web services."
|
||||
)
|
||||
APP_URL = "https://www.event.eys.gen.tr"
|
||||
|
||||
# Uvicorn server configuration
|
||||
@@ -57,4 +57,3 @@ class MainConfig:
|
||||
DEFAULT_TIMEZONE = "GMT+3" # Default timezone for the application
|
||||
SYSTEM_TIMEZONE = "GMT+0" # System timezone (used for internal operations)
|
||||
SUPPORTED_TIMEZONES = ["GMT+0", "GMT+3"] # List of supported timezones
|
||||
|
||||
|
||||
@@ -5,7 +5,11 @@ Handles dynamic route creation based on configurations.
|
||||
|
||||
from fastapi import Request
|
||||
from Events.Engine.set_defaults.run import get_cluster_controller_group
|
||||
from Events.Engine.set_defaults.setClusters import PrepareRouting, SetItems2Redis, PrepareEvents
|
||||
from Events.Engine.set_defaults.setClusters import (
|
||||
PrepareRouting,
|
||||
SetItems2Redis,
|
||||
PrepareEvents,
|
||||
)
|
||||
|
||||
routers = None
|
||||
|
||||
|
||||
@@ -32,7 +32,11 @@ class OpenAPISchemaCreator:
|
||||
"""
|
||||
self.app = app
|
||||
self.cluster = get_all_routers()
|
||||
self.safe_endpoint_list = self.cluster.safe_endpoints if hasattr(self.cluster, 'safe_endpoints') else []
|
||||
self.safe_endpoint_list = (
|
||||
self.cluster.safe_endpoints
|
||||
if hasattr(self.cluster, "safe_endpoints")
|
||||
else []
|
||||
)
|
||||
|
||||
def _create_security_schemes(self) -> Dict[str, Any]:
|
||||
"""
|
||||
@@ -42,6 +46,7 @@ class OpenAPISchemaCreator:
|
||||
Dict[str, Any]: Security scheme configurations
|
||||
"""
|
||||
from ApiLayers.AllConfigs.Token.config import Auth
|
||||
|
||||
return {
|
||||
"BearerAuth": {
|
||||
"type": "apiKey",
|
||||
@@ -191,12 +196,12 @@ class OpenAPISchemaCreator:
|
||||
|
||||
# Check if endpoint is in safe list
|
||||
endpoint_path = f"{path}:{method}"
|
||||
if endpoint_path not in [f"{e.URL}:{e.METHOD.lower()}" for e in self.safe_endpoint_list]:
|
||||
if endpoint_path not in [
|
||||
f"{e.URL}:{e.METHOD.lower()}" for e in self.safe_endpoint_list
|
||||
]:
|
||||
if "security" not in schema["paths"][path][method]:
|
||||
schema["paths"][path][method]["security"] = []
|
||||
schema["paths"][path][method]["security"].append(
|
||||
{"BearerAuth": []}
|
||||
)
|
||||
schema["paths"][path][method]["security"].append({"BearerAuth": []})
|
||||
|
||||
def create_schema(self) -> Dict[str, Any]:
|
||||
"""
|
||||
@@ -216,8 +221,10 @@ class OpenAPISchemaCreator:
|
||||
if "components" not in openapi_schema:
|
||||
openapi_schema["components"] = {}
|
||||
|
||||
openapi_schema["components"]["securitySchemes"] = self._create_security_schemes()
|
||||
|
||||
openapi_schema["components"][
|
||||
"securitySchemes"
|
||||
] = self._create_security_schemes()
|
||||
|
||||
# Configure route security and responses
|
||||
for route in self.app.routes:
|
||||
if isinstance(route, APIRoute) and route.include_in_schema:
|
||||
|
||||
Reference in New Issue
Block a user