新增小红书、XMPP、元宝、Zalo 四个渠道扩展。 小红书渠道扩展主要模块:config, gateway, webhook, outbound, streaming, pairing, security, dedupe, media, status, window XMPP 渠道扩展主要模块:plugin, config, gateway, outbound, streaming, pairing, security, dedupe, accounts, commands, muc, rate_limiter, stanza_utils, status, monitor 元宝渠道扩展主要模块:plugin, client, config_schema, gateway, outbound(chunk/queue/transport), inbound(dispatcher), streaming, pairing, security, accounts, actions, commands, codec(biz/conn), session, shared, utils Zalo 渠道扩展主要模块:api, config, gateway, webhook, outbound, pairing, security, session, polling, monitor, status
41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
SENSITIVE_KEYS = {
|
|
"token", "signature", "app_key", "app_secret", "appKey", "appSecret",
|
|
"access_token", "accessToken", "api_key", "apiKey", "password", "secret",
|
|
}
|
|
|
|
OMIT_KEYS = {"msg_body", "msgBody", "binary_data", "binaryData"}
|
|
|
|
|
|
def sanitize_log(data: dict) -> dict:
|
|
result = {}
|
|
for key, value in data.items():
|
|
if key in OMIT_KEYS:
|
|
result[key] = "<OMITTED>"
|
|
continue
|
|
if key in SENSITIVE_KEYS:
|
|
result[key] = mask_value(value) if isinstance(value, str) else "<MASKED>"
|
|
continue
|
|
if isinstance(value, dict):
|
|
result[key] = sanitize_log(value)
|
|
else:
|
|
result[key] = value
|
|
return result
|
|
|
|
|
|
def mask_value(value: str, visible_start: int = 4, visible_end: int = 4) -> str:
|
|
if len(value) <= visible_start + visible_end:
|
|
return "*" * len(value)
|
|
return value[:visible_start] + "*" * min(len(value) - visible_start - visible_end, 8) + value[-visible_end:]
|
|
|
|
|
|
def is_debug_whitelist(peer_id: str, whitelist: list[str]) -> bool:
|
|
if not whitelist:
|
|
return False
|
|
return peer_id in whitelist or "*" in whitelist
|