26 lines
768 B
Python
26 lines
768 B
Python
from fastapi import FastAPI
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from .crypto import SecretBox
|
|
from .db import Database
|
|
from .fileconfig import MASTER_KEY_FILE, load_file_config, load_master_key
|
|
from .health import build_checks, run_checks
|
|
from .settings import SettingsStore
|
|
|
|
|
|
def create_app() -> FastAPI:
|
|
config = load_file_config()
|
|
box = SecretBox(load_master_key(config.config_dir / MASTER_KEY_FILE))
|
|
db = Database(config.db_path)
|
|
store = SettingsStore(db, box)
|
|
|
|
app = FastAPI(title="checkbot")
|
|
app.state.store = store
|
|
|
|
@app.get("/health")
|
|
async def health() -> JSONResponse:
|
|
result = await run_checks(build_checks(store))
|
|
return JSONResponse(result, status_code=200 if result["ok"] else 503)
|
|
|
|
return app
|