chore: establish project baseline
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
"""FastAPI application factory."""
|
||||
|
||||
import logging
|
||||
from collections.abc import Callable
|
||||
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from .config import settings
|
||||
from .db import SessionLocal, database_is_available
|
||||
from .api import router
|
||||
from .version import GTI_FISCAL_VERSION
|
||||
|
||||
logging.basicConfig(level=getattr(logging, settings.log_level.upper(), logging.INFO))
|
||||
logger = logging.getLogger("gti_fiscal_hub")
|
||||
|
||||
|
||||
def create_app(database_probe: Callable[[], bool] = database_is_available, session_factory=SessionLocal, bootstrap_token: str | None = None) -> FastAPI:
|
||||
app = FastAPI(title="GTI Fiscal Hub", version=GTI_FISCAL_VERSION)
|
||||
if settings.environment == "production" and settings.agent_dev_token:
|
||||
raise RuntimeError("AGENT_DEV_TOKEN must not be set when APP_ENV=production (register real Agents with central/scripts/register_agent.py)")
|
||||
logger.info("starting GTI Fiscal Hub (environment=%s)", settings.environment)
|
||||
|
||||
@app.get("/health")
|
||||
def health() -> dict[str, str]:
|
||||
if not database_probe():
|
||||
logger.warning("health check failed: postgres unavailable")
|
||||
raise HTTPException(status_code=503, detail="postgres unavailable")
|
||||
return {"status": "ok"}
|
||||
|
||||
@app.get("/version")
|
||||
def version() -> dict[str, str]:
|
||||
from .classification import DECISION_VERSION, ENGINE_VERSION
|
||||
from .version import API_COMPAT_MAJOR_MINOR, GTI_FISCAL_VERSION
|
||||
return {"version": GTI_FISCAL_VERSION, "api_compat": API_COMPAT_MAJOR_MINOR, "engine_version": ENGINE_VERSION, "decision_version": DECISION_VERSION}
|
||||
|
||||
app.include_router(router(session_factory, settings.agent_dev_token if bootstrap_token is None else bootstrap_token))
|
||||
return app
|
||||
|
||||
|
||||
app = create_app()
|
||||
Reference in New Issue
Block a user