auth endpoints added

This commit is contained in:
2025-04-03 14:19:34 +03:00
parent 3583d178e9
commit ee405133be
37 changed files with 976 additions and 570 deletions

View File

@@ -3,10 +3,11 @@ import uvicorn
from config import api_config
from ApiServices.TemplateService.create_app import create_app
# from prometheus_fastapi_instrumentator import Instrumentator
app = create_app() # Create FastAPI application
app = create_app() # Create FastAPI application
# Instrumentator().instrument(app=app).expose(app=app) # Setup Prometheus metrics

View File

@@ -8,9 +8,9 @@ class Configs(BaseSettings):
"""
PATH: str = ""
HOST: str = "",
PORT: int = 0,
LOG_LEVEL: str = "info",
HOST: str = ("",)
PORT: int = (0,)
LOG_LEVEL: str = ("info",)
RELOAD: int = 0
ACCESS_TOKEN_TAG: str = ""
@@ -36,7 +36,7 @@ class Configs(BaseSettings):
"host": self.HOST,
"port": int(self.PORT),
"log_level": self.LOG_LEVEL,
"reload": bool(self.RELOAD)
"reload": bool(self.RELOAD),
}
@property

View File

@@ -17,4 +17,4 @@ def get_safe_endpoint_urls() -> list[tuple[str, str]]:
("/metrics", "GET"),
("/test/template", "GET"),
("/test/template", "POST"),
]
]

View File

@@ -1,5 +1,7 @@
from fastapi import Request, Response
from ApiServices.TemplateService.endpoints.routes import get_safe_endpoint_urls
from fastapi import Request, status
from fastapi.responses import JSONResponse
from ..endpoints.routes import get_safe_endpoint_urls
from ..config import api_config
async def token_middleware(request: Request, call_next):
@@ -9,9 +11,14 @@ async def token_middleware(request: Request, call_next):
if base_url in safe_endpoints:
return await call_next(request)
token = request.headers.get("Authorization")
token = request.headers.get(api_config.ACCESS_TOKEN_TAG, None)
if not token:
return Response(content="Missing token", status_code=400)
return JSONResponse(
content={
"error": "EYS_0002",
},
status_code=status.HTTP_401_UNAUTHORIZED,
)
response = await call_next(request)
return response

View File

@@ -83,9 +83,7 @@ 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:
@@ -115,4 +113,4 @@ def create_openapi_schema(app: FastAPI) -> Dict[str, Any]:
Dict[str, Any]: Complete OpenAPI schema
"""
creator = OpenAPISchemaCreator(app)
return creator.create_schema()
return creator.create_schema()