#!/usr/bin/env python3 """Verify the NET signed health endpoint without exposing authentication.""" import hashlib import hmac import json import os import time import subprocess def main(): group = os.environ["HKDJNET_HEALTH_GROUP_ID"] secret = os.environ["HKDJNET_HEALTH_SECRET"] stamp = int(time.time()) signature = hmac.new(secret.encode(), f"{group}:{stamp}".encode(), hashlib.sha256).hexdigest() response = subprocess.run(["curl", "-fsS", "--max-time", "10", "-H", "Content-Type: application/json", "-d", "@-", "-w", "\n%{http_code}", "http://127.0.0.1:30331/api/app/health/ping"], input=json.dumps({"groupId": group, "timestamp": stamp, "sign": signature}), text=True, capture_output=True, check=True) payload, status = response.stdout.rsplit("\n", 1) assert status == "200" body = json.loads(payload) assert body["code"] == 200 statuses = {name: body["data"][name]["status"] for name in ("redis", "mongodb", "elasticsearch")} assert all(value == "ok" for value in statuses.values()) print(json.dumps({"http_status": 200, "business_code": 200, "dependencies": statuses})) if __name__ == "__main__": try: main() except Exception as exc: print(json.dumps({"ok": False, "error_type": type(exc).__name__})) raise SystemExit(1)