feat:对接中心平台,完善接口鉴权
This commit is contained in:
@@ -79,7 +79,32 @@ class Settings:
|
||||
default_factory=lambda: int(os.getenv("MONGODB_CHECKPOINT_TTL", "604800"))
|
||||
)
|
||||
|
||||
# 用户中心:请求携带的 token 交给它校验,换回 user_id
|
||||
user_center_url: str = field(
|
||||
default_factory=lambda: (
|
||||
os.getenv("USER_CENTER_URL") or "http://127.0.0.1:8100"
|
||||
).rstrip("/")
|
||||
)
|
||||
user_center_timeout_seconds: float = field(
|
||||
default_factory=lambda: float(os.getenv("USER_CENTER_TIMEOUT_SECONDS", "5"))
|
||||
)
|
||||
# 关闭后不校验 token,所有请求视为同一个本地调试用户,仅用于开发
|
||||
auth_enabled: bool = field(
|
||||
default_factory=lambda: (
|
||||
os.getenv("AUTH_ENABLED", "true").strip().lower()
|
||||
not in ("false", "0", "no", "off")
|
||||
)
|
||||
)
|
||||
# token 校验结果缓存时长(秒),登出或禁用后最多延迟这么久失效,0 表示不缓存
|
||||
auth_cache_ttl_seconds: int = field(
|
||||
default_factory=lambda: int(os.getenv("AUTH_CACHE_TTL_SECONDS", "30"))
|
||||
)
|
||||
|
||||
def __post_init__(self):
|
||||
if self.user_center_timeout_seconds <= 0:
|
||||
raise ValueError("USER_CENTER_TIMEOUT_SECONDS 必须是正数")
|
||||
if self.auth_cache_ttl_seconds < 0:
|
||||
raise ValueError("AUTH_CACHE_TTL_SECONDS 必须是非负整数")
|
||||
if self.mongodb_checkpoint_ttl < 0:
|
||||
raise ValueError("MONGODB_CHECKPOINT_TTL 必须是非负整数")
|
||||
if self.conversation_empty_ttl <= 0:
|
||||
|
||||
Reference in New Issue
Block a user