feat: add API key authentication and health endpoint
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
from fastapi import Header, HTTPException
|
||||
|
||||
from src.backend.config import settings
|
||||
|
||||
|
||||
async def verify_api_key(x_api_key: str | None = Header(default=None)):
|
||||
if x_api_key is None or x_api_key != settings.api_key:
|
||||
raise HTTPException(status_code=403, detail="API key non valida")
|
||||
@@ -0,0 +1,11 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from src.backend.api.dependencies import verify_api_key
|
||||
from src.backend.models.api import ok
|
||||
|
||||
router = APIRouter(dependencies=[Depends(verify_api_key)])
|
||||
|
||||
|
||||
@router.get("/health", summary="Health check", tags=["system"])
|
||||
async def health():
|
||||
return ok({"status": "running"})
|
||||
@@ -0,0 +1,17 @@
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
from src.backend.api.routes.health import router as health_router
|
||||
from src.backend.db.database import init_db
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
await init_db()
|
||||
yield
|
||||
|
||||
|
||||
app = FastAPI(title="OpusAgent", version="0.1.0", lifespan=lifespan)
|
||||
|
||||
app.include_router(health_router, prefix="/api")
|
||||
Reference in New Issue
Block a user