Add admin panel, WebSocket support, and API versioning
Introduce an admin portal (React + Nginx), WebSocket routing, and API versioning middleware with `/api/v1/` prefix deprecation. Add master API key authentication, new Prometheus metrics for AI token consumption and active WebSockets, and extend S3 config with a public endpoint URL. Update test paths and fixtures to align with the new routing structure.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
"""
|
||||
Middleware de versionnement d'API.
|
||||
|
||||
Ajoute l'en-tête `X-API-Version` aux réponses des routes sous `/api/v1/`
|
||||
et gère un éventuel avertissement de dépréciation via Sunset.
|
||||
"""
|
||||
import logging
|
||||
from typing import Awaitable, Callable
|
||||
|
||||
from fastapi import Request, Response
|
||||
from starlette.middleware.base import BaseHTTPMiddleware
|
||||
|
||||
from app.config import settings
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class APIVersioningMiddleware(BaseHTTPMiddleware):
|
||||
async def dispatch(
|
||||
self, request: Request, call_next: Callable[[Request], Awaitable[Response]]
|
||||
) -> Response:
|
||||
response = await call_next(request)
|
||||
|
||||
# Appliquer X-API-Version seulement aux routes versionnées (ex: /api/v1/)
|
||||
path = request.url.path
|
||||
if path.startswith("/api/v1/"):
|
||||
response.headers["X-API-Version"] = "v1"
|
||||
|
||||
# Si une date de fin de support est configurée, l'ajouter en en-tête
|
||||
if settings.API_V1_SUNSET_DATE:
|
||||
response.headers["Sunset"] = settings.API_V1_SUNSET_DATE
|
||||
# Logger un avertissement si on l'utilise
|
||||
logger.warning("api.v1_sunset_warning", extra={
|
||||
"client": request.client.host if request.client else "unknown",
|
||||
"path": path,
|
||||
"sunset": settings.API_V1_SUNSET_DATE
|
||||
})
|
||||
|
||||
return response
|
||||
Reference in New Issue
Block a user