forked from luopingyi/xc_agent_platform_demo
- Overlay ModelHub XC Phase1 (health/status, STRATEGY_ID gate, dry-run) - Dockerfile CMD -> python -m src.server; FROM stays platform TCR base - Remove demo main.py and requirements.txt (stdlib only) - Add tests/, scripts/, docs/, Makefile, config/examples (no secrets)
34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
"""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
|