feat: 从黄果 NET hgdjnet-server 9bfbafe 导入 HKDJ 官网后端
来源:hgdjnet-server 9bfbafe10d417deea959bd53117bc88a10e60a83 项目身份 HKDJ / JHA-216,独立官网仓库,Jenkins 守卫键 hkdjnet 测试目录 /server/hkdj_net,App/Web API 30331/30332 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
#!/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)
|
||||
Reference in New Issue
Block a user