Files
knowledge-governance/internal/serviceverify/production_bases.go
T
狐友 GXXP & LEN aac8538372
build / build (push) Successful in 1m48s
fix(settings): 绑定留档名称并按旧目标重指向待入库
- 迁移 000084 保存对内/对外绑定名称快照;清除密钥后仍显示已绑定库,不再只显示裸 ID
- 测试/生产换绑只重指向同一侧的旧目标,避免测试保存误改另一环境的待入库
- 已保存连接但没有可用密钥时拒绝改绑定,禁止静默回落文件 Key
- 生产换绑返回重指向/退休数量,页面提示与测试侧一致

验证:make verify(含隔离 PostgreSQL 集成用例)15/15 通过
2026-11-23 12:47:22 +08:00

48 lines
2.0 KiB
Go

package serviceverify
import (
"context"
"errors"
"knowledge-governance/internal/platform/weknora"
)
// ListProductionKnowledgeBases enumerates the bases a release could be written
// into. It asks the operator-managed production endpoint with the production
// credential file, so the settings page can offer real bases instead of asking
// the operator to paste an id. A missing endpoint or credential is an error the
// caller reports honestly rather than a silently empty picker.
func (verifier *Verifier) ListProductionKnowledgeBases(ctx context.Context, baseURL string) ([]weknora.KnowledgeBase, error) {
// The admin-managed connection wins: the page is where operators record the
// endpoint and key, and a second (file) source would silently disagree.
if verifier.config.ConnectionResolver != nil {
if endpoint, apiKey, ok := verifier.config.ConnectionResolver.Resolve(ctx, "production"); ok {
client, err := verifier.clientWithPolicy(endpoint, apiKey, verifier.config.ProductionAllowDockerHTTP, verifier.config.ProductionAllowPrivateHTTP)
if err != nil {
return nil, err
}
return client.ListKnowledgeBases(ctx)
}
configured, err := verifier.config.ConnectionResolver.Configured(ctx, "production")
if err != nil {
return nil, err
}
if configured {
return nil, errors.New("production WeKnora connection has no usable API key; re-enter it instead of falling back to the file")
}
}
resolved := firstNonEmpty(baseURL, verifier.config.ProductionBaseURLFallback)
if resolved == "" {
return nil, errors.New("production WeKnora endpoint is not configured")
}
apiKey := verifier.apiKey(verifier.config.ProductionAPIKeyFile)
if apiKey == "" {
return nil, errors.New("production WeKnora API key file is not available")
}
client, err := verifier.clientWithPolicy(resolved, apiKey, verifier.config.ProductionAllowDockerHTTP, verifier.config.ProductionAllowPrivateHTTP)
if err != nil {
return nil, err
}
return client.ListKnowledgeBases(ctx)
}