"""Health and status HTTP handlers. Never echo secrets.""" from __future__ import annotations import json from typing import Any, Dict, Tuple from .strategy import external_service_token_present, strategy_id_present def health_payload() -> Dict[str, str]: return {"status": "ok"} def status_payload() -> Dict[str, Any]: """Booleans only — never include STRATEGY_ID or token values.""" return { "strategy_id_present": strategy_id_present(), "external_service_token_present": external_service_token_present(), } def handle_get(path: str) -> Tuple[int, Dict[str, str], bytes]: """Return (status_code, headers, body) for GET paths.""" headers = {"Content-Type": "application/json; charset=utf-8"} if path == "/health" or path.startswith("/health?"): body = json.dumps(health_payload(), ensure_ascii=False).encode("utf-8") return 200, headers, body if path == "/status" or path.startswith("/status?"): body = json.dumps(status_payload(), ensure_ascii=False).encode("utf-8") return 200, headers, body body = json.dumps({"error": "not_found"}, ensure_ascii=False).encode("utf-8") return 404, headers, body