优化结构
This commit is contained in:
@@ -10,24 +10,3 @@ func cloneAdminConfig(value *config.Admin) *config.Admin {
|
||||
}
|
||||
return config.CloneAdmin(value)
|
||||
}
|
||||
|
||||
func maskStorageSecrets(storage *config.Storage) {
|
||||
if storage == nil {
|
||||
return
|
||||
}
|
||||
if storage.Qiniu != nil && storage.Qiniu.SecretKey != "" {
|
||||
storage.Qiniu.SecretKey = "******"
|
||||
}
|
||||
for _, item := range []*config.ObjectStore{
|
||||
storage.AliyunOSS,
|
||||
storage.HuaweiOBS,
|
||||
storage.TencentCOS,
|
||||
storage.AWSS3,
|
||||
storage.CloudflareR2,
|
||||
storage.Minio,
|
||||
} {
|
||||
if item != nil && item.SecretKey != "" {
|
||||
item.SecretKey = "******"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"kra/internal/config"
|
||||
"kra/internal/integration/runtimeconfig"
|
||||
|
||||
"gorm.io/gorm"
|
||||
@@ -158,7 +159,7 @@ func maskIntegrationSecrets(kind, provider string, values map[string]any) {
|
||||
for key, value := range values {
|
||||
if secretFields[key] || likelyIntegrationSecret(key) {
|
||||
if text, ok := value.(string); ok && text != "" {
|
||||
values[key] = "******"
|
||||
values[key] = config.MaskedSecret
|
||||
}
|
||||
continue
|
||||
}
|
||||
@@ -172,7 +173,7 @@ func mergeIntegrationSecrets(kind, provider string, values, old map[string]any)
|
||||
secretFields := integrationSecretFields(kind, provider)
|
||||
for key, value := range values {
|
||||
if secretFields[key] || likelyIntegrationSecret(key) {
|
||||
if text, ok := value.(string); ok && text == "******" {
|
||||
if text, ok := value.(string); ok && text == config.MaskedSecret {
|
||||
if prior, exists := old[key]; exists {
|
||||
values[key] = prior
|
||||
}
|
||||
|
||||
@@ -157,11 +157,11 @@ func TestMaskStorageSecretsLeavesUnconfiguredProvidersEmpty(t *testing.T) {
|
||||
AliyunOSS: &config.ObjectStore{SecretKey: "configured-secret"},
|
||||
Minio: &config.ObjectStore{},
|
||||
}
|
||||
maskStorageSecrets(storage)
|
||||
config.MaskStorageSecrets(storage)
|
||||
if storage.Qiniu.SecretKey != "" || storage.Minio.SecretKey != "" {
|
||||
t.Fatalf("empty provider secrets were masked: %#v", storage)
|
||||
}
|
||||
if storage.AliyunOSS.SecretKey != "******" {
|
||||
if storage.AliyunOSS.SecretKey != config.MaskedSecret {
|
||||
t.Fatalf("configured secret was not masked: %q", storage.AliyunOSS.SecretKey)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user