feat(settings): 页面录入测试/生产 WeKnora 连接与密钥并收敛可达性判定
连接(地址 + 写-only 密钥)从文件引用搬进治理库:AES-GCM 密文 + 独立 0600 主密钥,
页面与接口只回显尾 4 位;测试连接真实列库并区分 地址不可达/密钥无效/无权限/成功,
换地址或换密钥必须测通才能保存(迁移 000083)。
可达性判定收敛为 weknora.HTTPAllowed,客户端与监控探活共用;新增
WEKNORA_ALLOW_PRIVATE_HTTP 只放行 RFC1918/回环/链路本地。生产绑定只保留下拉,
保存后回报冻结/未冻结条数,已冻结目标不被改写。
(cherry picked from commit ad02e8bb9c)
This commit is contained in:
@@ -16,6 +16,10 @@ import (
|
||||
type ProductionBindingStore interface {
|
||||
LoadProductionKBBindings(context.Context) (string, string, string, error)
|
||||
SaveProductionKBBindings(ctx context.Context, internalID, externalID, updatedBy string, now time.Time) error
|
||||
// ProductionExecutionCounts reports frozen vs still re-targetable release
|
||||
// items. A binding change never rewrites a target that was already frozen
|
||||
// when an execution started; the count is how the page says so.
|
||||
ProductionExecutionCounts(ctx context.Context) (frozen int, retargetable int, err error)
|
||||
}
|
||||
|
||||
// ProductionKnowledgeBaseLister enumerates the knowledge bases of the production
|
||||
@@ -33,11 +37,26 @@ type productionBindingView struct {
|
||||
ProductionBaseURL string `json:"production_base_url"`
|
||||
ProductionConnected bool `json:"production_connected"`
|
||||
ProductionMessage string `json:"production_message"`
|
||||
// Frozen / Retargetable describe what a binding change can still affect.
|
||||
Frozen int `json:"frozen"`
|
||||
Retargetable int `json:"retargetable"`
|
||||
}
|
||||
|
||||
// WeKnoraConnectionResolver reads the admin-managed connection for one
|
||||
// environment. When it answers, that endpoint is the only truth.
|
||||
type WeKnoraConnectionResolver interface {
|
||||
Resolve(ctx context.Context, environment string) (endpoint string, apiKey string, ok bool)
|
||||
}
|
||||
|
||||
// productionTargetBaseURL is the production endpoint the picker reads from: the
|
||||
// operator-managed 「服务配置 · 生产地址」 first, the deployment default second.
|
||||
// connection card first, the operator-managed 「服务配置 · 生产地址」 second, the
|
||||
// deployment default last.
|
||||
func (config Config) productionTargetBaseURL(ctx context.Context) string {
|
||||
if config.WeKnoraConnectionResolver != nil {
|
||||
if endpoint, _, ok := config.WeKnoraConnectionResolver.Resolve(ctx, "production"); ok {
|
||||
return endpoint
|
||||
}
|
||||
}
|
||||
if settings, err := config.Store.GetActiveUISettings(ctx); err == nil {
|
||||
if resolved := strings.TrimSpace(settings.ProductionWeKnoraBaseURL); resolved != "" {
|
||||
return resolved
|
||||
@@ -55,7 +74,7 @@ func (config Config) productionKnowledgeBases(ctx context.Context) ([]weknora.Kn
|
||||
}
|
||||
baseURL := config.productionTargetBaseURL(ctx)
|
||||
if baseURL == "" {
|
||||
return nil, "未配置生产地址(系统设置 → 服务配置)"
|
||||
return nil, "未配置生产地址(系统设置 → 生产知识库绑定 → 连接卡)"
|
||||
}
|
||||
bases, err := config.ProductionKnowledgeBases.ListProductionKnowledgeBases(ctx, baseURL)
|
||||
if err != nil {
|
||||
@@ -74,11 +93,16 @@ func (config Config) productionBindingPayload(ctx context.Context) (productionBi
|
||||
for _, base := range bases {
|
||||
names[base.ID] = base.Name
|
||||
}
|
||||
frozen, retargetable := 0, 0
|
||||
if frozenItems, retargetableItems, countsErr := config.ProductionBindings.ProductionExecutionCounts(ctx); countsErr == nil {
|
||||
frozen, retargetable = frozenItems, retargetableItems
|
||||
}
|
||||
return productionBindingView{
|
||||
InternalKBID: storedInternal, ExternalKBID: storedExternal,
|
||||
InternalKBName: names[storedInternal], ExternalKBName: names[storedExternal],
|
||||
UpdatedBy: updatedBy, ProductionBaseURL: config.productionTargetBaseURL(ctx),
|
||||
ProductionConnected: message == "", ProductionMessage: message,
|
||||
Frozen: frozen, Retargetable: retargetable,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user