SSO: Use removeSecrets() instead of setting.RedactedValue() (#88180)

* use removeSecrets() instead of setting.RedactedValue()

* replace with redacted value only if secret is not empty
This commit is contained in:
Mihai Doarna 2024-05-28 17:03:54 +03:00 committed by GitHub
parent 60ce523b72
commit 12e4a94d63
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -126,11 +126,7 @@ func (s *Service) GetForProviderWithRedactedSecrets(ctx context.Context, provide
return nil, err return nil, err
} }
for k, v := range storeSettings.Settings { storeSettings.Settings = removeSecrets(storeSettings.Settings)
if strVal, ok := v.(string); ok {
storeSettings.Settings[k] = setting.RedactedValue(k, strVal)
}
}
return storeSettings, nil return storeSettings, nil
} }
@ -177,11 +173,7 @@ func (s *Service) ListWithRedactedSecrets(ctx context.Context) ([]*models.SSOSet
} }
for _, storeSetting := range configurableSettings { for _, storeSetting := range configurableSettings {
for k, v := range storeSetting.Settings { storeSetting.Settings = removeSecrets(storeSetting.Settings)
if strVal, ok := v.(string); ok {
storeSetting.Settings[k] = setting.RedactedValue(k, strVal)
}
}
} }
return configurableSettings, nil return configurableSettings, nil
@ -449,7 +441,8 @@ func (s *Service) isProviderConfigurable(provider string) bool {
func removeSecrets(settings map[string]any) map[string]any { func removeSecrets(settings map[string]any) map[string]any {
result := make(map[string]any) result := make(map[string]any)
for k, v := range settings { for k, v := range settings {
if IsSecretField(k) { val, ok := v.(string)
if ok && val != "" && IsSecretField(k) {
result[k] = setting.RedactedPassword result[k] = setting.RedactedPassword
continue continue
} }