优化结构
This commit is contained in:
@@ -224,7 +224,7 @@ func integrationObject(raw json.RawMessage) map[string]any {
|
||||
func maskIntegrationSecrets(kind, provider string, values map[string]any) {
|
||||
secretFields := integrationSecretFields(kind, provider)
|
||||
for key, value := range values {
|
||||
if secretFields[key] || likelyIntegrationSecret(key) {
|
||||
if secretFields[key] || integrationbiz.IsIntegrationSecretKey(key) {
|
||||
if text, ok := value.(string); ok && text != "" {
|
||||
values[key] = config.MaskedSecret
|
||||
}
|
||||
@@ -239,10 +239,12 @@ func maskIntegrationSecrets(kind, provider string, values map[string]any) {
|
||||
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 secretFields[key] || integrationbiz.IsIntegrationSecretKey(key) {
|
||||
if text, ok := value.(string); ok && text == config.MaskedSecret {
|
||||
if prior, exists := old[key]; exists {
|
||||
values[key] = prior
|
||||
} else {
|
||||
values[key] = ""
|
||||
}
|
||||
}
|
||||
continue
|
||||
@@ -252,6 +254,23 @@ func mergeIntegrationSecrets(kind, provider string, values, old map[string]any)
|
||||
mergeIntegrationSecrets(kind, provider, nested, prior)
|
||||
}
|
||||
}
|
||||
if nested, ok := value.([]any); ok {
|
||||
if prior, ok := old[key].([]any); ok {
|
||||
mergeIntegrationSecretArrays(kind, provider, nested, prior)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func mergeIntegrationSecretArrays(kind, provider string, values, old []any) {
|
||||
for i, item := range values {
|
||||
if nested, ok := item.(map[string]any); ok {
|
||||
if i < len(old) {
|
||||
if prior, ok := old[i].(map[string]any); ok {
|
||||
mergeIntegrationSecrets(kind, provider, nested, prior)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,16 +285,3 @@ func integrationSecretFields(kind, provider string) map[string]bool {
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func likelyIntegrationSecret(key string) bool {
|
||||
normalized := strings.ToLower(strings.ReplaceAll(key, "-", "_"))
|
||||
if strings.Contains(normalized, "secret") || strings.Contains(normalized, "private") || strings.Contains(normalized, "password") || strings.Contains(normalized, "credential") {
|
||||
return true
|
||||
}
|
||||
for _, item := range []string{"key", "token", "access_token", "api_key", "mch_key", "client_key", "certificate", "cert", "p12", "pkcs12", "public_key", "platform_cert", "root_cert"} {
|
||||
if normalized == item || strings.HasSuffix(normalized, "_"+item) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ func (r *mediaRepo) DeleteChunks(ctx context.Context, uploadID uint) error {
|
||||
}
|
||||
func (r *mediaRepo) StaleUploadSessionIDs(ctx context.Context, before time.Time) ([]uint, error) {
|
||||
var ids []uint
|
||||
err := r.data.DB().WithContext(ctx).Model(&uploadSessionPO{}).Where("status = ? AND updated_at < ?", "uploading", before).Pluck("id", &ids).Error
|
||||
err := r.data.DB().WithContext(ctx).Model(&uploadSessionPO{}).Where("status IN ? AND updated_at < ?", []string{"uploading", "failed", "merging"}, before).Pluck("id", &ids).Error
|
||||
return ids, err
|
||||
}
|
||||
func (r *mediaRepo) DeleteUploadData(ctx context.Context, uploadID uint) error {
|
||||
|
||||
Reference in New Issue
Block a user