fix: 增强代理密码脱敏策略并补充异常日志

- 密码脱敏阈值从 4 提升至 8,短密码全部遮蔽
- 为系统代理获取、proxy_node 解析、代理 URL 构建添加 warning 日志
This commit is contained in:
fawney19
2026-02-07 14:37:44 +08:00
parent db96c9a46e
commit 02906dad0e
2 changed files with 8 additions and 5 deletions

View File

@@ -27,10 +27,10 @@ pipeline = ApiRequestPipeline()
def _mask_password(password: str | None) -> str | None:
"""脱敏密码仅显示前2位和后2位"""
"""脱敏密码仅显示前2位和后2位(长度不足 8 时全部遮蔽)"""
if not password:
return None
if len(password) <= 4:
if len(password) < 8:
return "****"
return password[:2] + "****" + password[-2:]

View File

@@ -142,7 +142,8 @@ def get_system_proxy_config() -> dict[str, Any] | None:
result = None
_system_proxy_cache = (result, now + _SYSTEM_PROXY_CACHE_TTL)
return result
except Exception:
except Exception as exc:
logger.warning("获取系统默认代理配置失败: {}", exc)
_system_proxy_cache = (None, now + _SYSTEM_PROXY_CACHE_TTL)
return None
finally:
@@ -170,7 +171,8 @@ def resolve_ops_proxy(connector_config: dict[str, Any] | None) -> str | None:
if isinstance(node_id, str) and node_id.strip():
try:
return build_proxy_url({"node_id": node_id.strip(), "enabled": True})
except Exception:
except Exception as exc:
logger.warning("解析 proxy_node_id={} 失败,回退到直连: {}", node_id, exc)
return None
# 旧格式:直接返回 proxy URL 字符串
@@ -183,7 +185,8 @@ def resolve_ops_proxy(connector_config: dict[str, Any] | None) -> str | None:
if system_proxy:
try:
return build_proxy_url(system_proxy)
except Exception:
except Exception as exc:
logger.warning("构建系统默认代理 URL 失败: {}", exc)
return None
return None