middleware and respnse models updated

This commit is contained in:
2025-01-27 17:25:49 +03:00
parent e403993d24
commit b88f910a43
54 changed files with 1125 additions and 808 deletions

View File

@@ -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(

View File

@@ -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:
@@ -41,7 +40,9 @@ class ApiConfig(DefaultApiConfig):
# Application Information
APP_NAME = "evyos-auth-api-gateway"
TITLE = "WAG API Auth Api Gateway"
DESCRIPTION = "This api is serves as web auth api gateway only to evyos web services."
DESCRIPTION = (
"This api is serves as web auth api gateway only to evyos web services."
)
APP_URL = "https://www.auth.eys.gen.tr"
# Server Configuration
@@ -65,6 +66,6 @@ class MainConfig:
class LanguageConfig:
SUPPORTED_LANGUAGES = ["en", "tr"]
DEFAULT_LANGUAGE = "tr"

View File

@@ -2,10 +2,15 @@
Route configuration and factory module.
Handles dynamic route creation based on configurations.
"""
from typing import Optional
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: Optional[PrepareRouting] = None

View File

@@ -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: