feat(settings): 知识库绑定按环境一次保存连接与内外库

原「知识库映射 → WeKnora 连接」把地址、文件和绑定分散在多处,页面无法输入密钥,
也看不到候选实例真实可读的库。现在测试 090 / 生产 090 各自一个工作区:草稿填地址
与 API Key,服务器真实分页列库并区分空库/无权限/不可达,选内外库后一次保存连接与
绑定,回读真实生效值。

服务端以修订号 + 行锁 + 单事务写连接、绑定与待入库重排;旧部署无新行时继续使用文件
凭据/默认绑定。密钥只存 AES-256-GCM 密文,主密钥在独立文件;换地址必须重录,旧密钥
不转发、不跨环境取用。消费端(readiness/上传轮询/列库/探活/生产列库)统一从该存储
解析当前连接,避免只保存了页面数据。

验证:go test ./...;前端 606 项;隔离 PostgreSQL 集成用例覆盖保存/冲突/重排/拒错;
make verify 在本提交上执行(结果见交付说明)。
This commit is contained in:
姚章浩
2026-11-19 14:43:51 +08:00
parent df69b278ce
commit ce2a155ebc
53 changed files with 3367 additions and 601 deletions
+20 -10
View File
@@ -45,6 +45,9 @@ type Resolver struct {
LoadBinding func(context.Context) (string, error)
ReadKey func() (string, error)
DefaultKB string
// ResolveConnection 可选:一次解析端点与凭据(例如来自加密存储)。
// 提供时优先于 Endpoint + ReadKey,因为密钥解密需要请求上下文。
ResolveConnection func(context.Context) (baseURL, apiKey string, err error)
}
func (resolver Resolver) Resolve(ctx context.Context) (Target, error) {
@@ -58,19 +61,26 @@ func (resolver Resolver) Resolve(ctx context.Context) (Target, error) {
knowledgeBaseID = stored
}
}
apiKey := ""
if resolver.ReadKey != nil {
value, err := resolver.ReadKey()
baseURL, apiKey := "", ""
if resolver.ResolveConnection != nil {
var err error
baseURL, apiKey, err = resolver.ResolveConnection(ctx)
if err != nil {
return Target{}, fmt.Errorf("读取 WeKnora API 凭据失败")
return Target{}, fmt.Errorf("读取 WeKnora 有效连接失败:%w", err)
}
} else {
if resolver.ReadKey != nil {
value, err := resolver.ReadKey()
if err != nil {
return Target{}, fmt.Errorf("读取 WeKnora API 凭据失败")
}
apiKey = strings.TrimSpace(value)
}
if resolver.Endpoint != nil {
baseURL = strings.TrimSpace(resolver.Endpoint(ctx))
}
apiKey = strings.TrimSpace(value)
}
baseURL := ""
if resolver.Endpoint != nil {
baseURL = strings.TrimSpace(resolver.Endpoint(ctx))
}
return Target{BaseURL: baseURL, KnowledgeBaseID: knowledgeBaseID, APIKey: apiKey}, nil
return Target{BaseURL: strings.TrimSpace(baseURL), KnowledgeBaseID: knowledgeBaseID, APIKey: strings.TrimSpace(apiKey)}, nil
}
type Prober struct {