47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
import os
|
|
|
|
from flask import Flask, request
|
|
|
|
from webapi.blueprints.cacu import cacu_bp
|
|
from webapi.blueprints.cama import cama_bp
|
|
from webapi.blueprints.tea import tea_bp
|
|
|
|
|
|
def parse_auth_lite_enabled(value: str | None) -> bool:
|
|
if value is None or value == "false":
|
|
return False
|
|
if value == "true":
|
|
return True
|
|
raise ValueError("AUTH_LITE_ENABLED must be exactly 'true' or 'false'")
|
|
|
|
|
|
def create_app() -> Flask:
|
|
app = Flask(__name__)
|
|
|
|
@app.get("/health")
|
|
def health():
|
|
return {"status": "ok"}
|
|
|
|
app.register_blueprint(cacu_bp, url_prefix="/cacu")
|
|
app.register_blueprint(cama_bp, url_prefix="/cama")
|
|
app.register_blueprint(tea_bp, url_prefix="/tea")
|
|
|
|
if parse_auth_lite_enabled(os.environ.get("AUTH_LITE_ENABLED")):
|
|
from webapi.auth_token import validate_auth_storage
|
|
from webapi.blueprints.auth import auth_bp
|
|
|
|
secret = os.environ.get("AUTH_LITE_SECRET_KEY")
|
|
if not secret or not secret.strip():
|
|
raise ValueError("AUTH_LITE_SECRET_KEY is required when Auth-Lite is enabled")
|
|
validate_auth_storage()
|
|
app.config["AUTH_LITE_SECRET_KEY"] = secret
|
|
app.register_blueprint(auth_bp, url_prefix="/auth")
|
|
|
|
@app.after_request
|
|
def auth_no_store(response):
|
|
if request.path == "/auth" or request.path.startswith("/auth/"):
|
|
response.headers["Cache-Control"] = "no-store"
|
|
return response
|
|
|
|
return app
|