feat: expose deployment build identity
This commit is contained in:
@@ -4,6 +4,8 @@ from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
class Settings(BaseSettings):
|
||||
deployment_environment: str = "development"
|
||||
app_version: str = "0.1.0"
|
||||
app_revision: str = "dev"
|
||||
database_url: str = "postgresql+psycopg://rf4:rf4_local@localhost:5432/rf4_spotter"
|
||||
admin_token: str = "change-me-in-production"
|
||||
s3_endpoint_url: str = "http://localhost:9000"
|
||||
|
||||
@@ -89,7 +89,7 @@ def ready(db: Db) -> JSONResponse:
|
||||
)
|
||||
return JSONResponse(
|
||||
status_code=200 if is_ready else 503,
|
||||
content={"status": "ready" if is_ready else "not_ready", "components": components},
|
||||
content={"status": "ready" if is_ready else "not_ready", "version": settings.app_version, "revision": settings.app_revision, "components": components},
|
||||
)
|
||||
|
||||
|
||||
@@ -257,6 +257,11 @@ def _admin(authorization: Annotated[str | None, Header()] = None) -> str:
|
||||
return "admin"
|
||||
|
||||
|
||||
@app.get("/api/v1/admin/diagnostics")
|
||||
def admin_diagnostics(_: Annotated[str, Depends(_admin)]) -> dict[str, str]:
|
||||
return {"version": settings.app_version, "revision": settings.app_revision, "environment": settings.deployment_environment}
|
||||
|
||||
|
||||
@app.get("/api/v1/imports", response_model=list[ImportRunOut])
|
||||
def imports(db: Db, limit: int = Query(20, ge=1, le=100), offset: int = Query(0, ge=0)) -> list[OfficialRecordImport]:
|
||||
return list(db.scalars(select(OfficialRecordImport).order_by(OfficialRecordImport.started_at.desc(), OfficialRecordImport.id.desc()).offset(offset).limit(limit)))
|
||||
|
||||
@@ -85,6 +85,13 @@ def test_liveness_does_not_probe_dependencies() -> None:
|
||||
assert response.headers["Cross-Origin-Opener-Policy"] == "same-origin"
|
||||
|
||||
|
||||
def test_admin_diagnostics_exposes_build_identity_only_to_admin() -> None:
|
||||
assert client.get("/api/v1/admin/diagnostics").status_code == 401
|
||||
response = client.get("/api/v1/admin/diagnostics", headers={"Authorization": "Bearer change-me-in-production"})
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"version": "0.1.0", "revision": "dev", "environment": "development"}
|
||||
|
||||
|
||||
def test_spot_detail_and_catches() -> None:
|
||||
spot_id = client.get("/api/v1/activity").json()[0]["spot_id"]
|
||||
detail = client.get(f"/api/v1/spots/{spot_id}")
|
||||
|
||||
Reference in New Issue
Block a user