新增 Google Chat 对接的全套工具模块,包括: - 会话线程管理、消息解析与格式化 - Pub/Sub 消息解码、提及和命令识别 - 权限审批、目录管理和审计日志 - 消息缓存、媒体上传下载和 SSFR 防护 - 策略配置、卡片构建和流式回复支持
55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from yuxi.utils.logging_config import logger
|
|
|
|
_SECRET_CONTRACTS: dict[str, dict[str, Any]] = {
|
|
"serviceAccount": {
|
|
"name": "serviceAccount",
|
|
"description": "Google Chat service account JSON credentials (inline)",
|
|
"required": True,
|
|
"sensitive": True,
|
|
"validate": "_validate_service_account_json",
|
|
},
|
|
"serviceAccountFile": {
|
|
"name": "serviceAccountFile",
|
|
"description": "Path to Google Chat service account JSON key file",
|
|
"required": False,
|
|
"sensitive": True,
|
|
},
|
|
"serviceAccountRef": {
|
|
"name": "serviceAccountRef",
|
|
"description": "Secret reference to Google Chat service account credentials",
|
|
"required": False,
|
|
"sensitive": True,
|
|
},
|
|
"webhookSecret": {
|
|
"name": "webhookSecret",
|
|
"description": "Webhook secret for Pub/Sub push endpoint (if applicable)",
|
|
"required": False,
|
|
"sensitive": True,
|
|
},
|
|
}
|
|
|
|
|
|
def get_secret_contracts() -> dict[str, dict[str, Any]]:
|
|
return dict(_SECRET_CONTRACTS)
|
|
|
|
|
|
def register_secret_contract(name: str, contract: dict[str, Any]) -> None:
|
|
_SECRET_CONTRACTS[name] = contract
|
|
logger.debug(f"Registered secret contract: {name}")
|
|
|
|
|
|
def get_required_secrets() -> list[str]:
|
|
return [name for name, contract in _SECRET_CONTRACTS.items() if contract.get("required")]
|
|
|
|
|
|
def get_sensitive_fields() -> set[str]:
|
|
return {name for name, contract in _SECRET_CONTRACTS.items() if contract.get("sensitive")}
|
|
|
|
|
|
def is_sensitive_field(field_name: str) -> bool:
|
|
return field_name in get_sensitive_fields() or field_name.endswith("_key") or field_name.endswith("_secret")
|