chore(security): 摘除 knowledge_service 硬编码默认 DeepSeek Key(缺 env 抛明确错误/503)
- knowledge_service: 移除 os.getenv 默认值占位,改 _require_deepseek_key() 必填,缺 env 抛 DeepSeekKeyMissing
- knowledge API: generate/{daily,weekly,monthly} 缺 Key 返回 503(可观测,不再静默走模板兜底)
- finance_bot / verify_zxt_vouchers_json / bot_bridge_push: 凭据改 env 优先(CMA_BOT_KEY_* / CMA_BOT_API_KEYS / CMA_BRIDGE_TOKEN),历史共享键仅作兼容期兜底并告警
- tests: 新增 5 例回归(缺 Key 服务层抛错、API 503;有 Key 正常 200)
(cherry picked from commit 859bd8276d7c5aad4bf10ee3399b6cccc188f064)
This commit is contained in:
committed by
Hermes CI Fix
parent
885cfddbff
commit
a9dcbf22bc
@@ -47,7 +47,28 @@ def override_get_db():
|
||||
app.dependency_overrides[get_db] = override_get_db
|
||||
client = TestClient(app)
|
||||
|
||||
HDR = {"X-BOT-KEY": "cma-bot-admin-2026"}
|
||||
# 凭据来源:CMA_BOT_KEY_ADMIN → CMA_BOT_API_KEYS(role=ceo/admin) → 兼容期历史共享键(P3 待轮换)
|
||||
_LEGACY_ADMIN_KEY = "cma-bot-admin-2026"
|
||||
|
||||
|
||||
def _resolve_admin_key() -> str:
|
||||
key = (os.getenv("CMA_BOT_KEY_ADMIN") or "").strip()
|
||||
if key:
|
||||
return key
|
||||
raw = (os.getenv("CMA_BOT_API_KEYS") or "").strip()
|
||||
if raw:
|
||||
try:
|
||||
import json as _json
|
||||
for k, v in _json.loads(raw).items():
|
||||
if isinstance(v, dict) and v.get("role") in ("ceo", "admin"):
|
||||
return k
|
||||
except Exception:
|
||||
pass
|
||||
return _LEGACY_ADMIN_KEY
|
||||
|
||||
|
||||
HDR = {"X-BOT-KEY": _resolve_admin_key()}
|
||||
|
||||
|
||||
def check(name, cond, detail=""):
|
||||
print(("PASS " if cond else "FAIL ") + name + (" | " + detail if detail else ""))
|
||||
|
||||
Reference in New Issue
Block a user