Files
knowledge-governance/internal/appconfig/library_target.go
T
姚章浩 7ab2eb1ccf
build / build (push) Successful in 1m47s
fix(library): 按目标身份隔离版本授权与执行历史
2026-10-31 02:15:15 +08:00

42 lines
1.4 KiB
Go

package appconfig
import (
"crypto/sha256"
"encoding/hex"
"encoding/json"
"github.com/jackc/pgx/v5/pgxpool"
)
// LibraryTargetIdentity binds control-plane evidence to the logical deployment
// and data scope, not credentials or the caller's transport. API may use an SSH
// forward while the executor uses the private DB address. Instance/project are
// deployment identities, verified independently by executor admission; reusing
// them for another physical deployment is not a supported target switch.
func (c Config) LibraryTargetIdentity() string {
database := "unconfigured"
if c.LibraryProductionDatabaseURL != "" {
if parsed, err := pgxpool.ParseConfig(c.LibraryProductionDatabaseURL); err == nil {
database = parsed.ConnConfig.Database
} else {
database = "invalid"
}
}
raw, _ := json.Marshal(struct {
Instance string
Project string
Database string
Tenant uint64
InternalKB string
ExternalKB string
Index string
Provider string
ObjectEndpoint string
Bucket string
}{c.LibraryTargetInstance, c.LibraryTargetProject, database, c.LibraryProductionTenantID,
c.LibraryProductionInternalKB, c.LibraryProductionExternalKB, c.LibraryProductionIndex,
c.LibraryProductionS3Provider, c.LibraryProductionS3Endpoint, c.LibraryProductionS3Bucket})
sum := sha256.Sum256(raw)
return hex.EncodeToString(sum[:])
}