Test environment override for secret and url with credentials

This commit is contained in:
Soulou
2016-06-29 13:49:41 +02:00
parent e2c5fac9df
commit aa064b18e8
2 changed files with 30 additions and 0 deletions
+16
View File
@@ -183,6 +183,11 @@ func shouldRedactKey(s string) bool {
return strings.Contains(uppercased, "PASSWORD") || strings.Contains(uppercased, "SECRET")
}
func shouldRedactURLKey(s string) bool {
uppercased := strings.ToUpper(s)
return strings.Contains(uppercased, "DATABASE_URL")
}
func applyEnvVariableOverrides() {
appliedEnvOverrides = make([]string, 0)
for _, section := range Cfg.Sections() {
@@ -197,6 +202,17 @@ func applyEnvVariableOverrides() {
if shouldRedactKey(envKey) {
envValue = "*********"
}
if shouldRedactURLKey(envKey) {
u, _ := url.Parse(envValue)
ui := u.User
if ui != nil {
_, exists := ui.Password()
if exists {
u.User = url.UserPassword(ui.Username(), "-redacted-")
envValue = u.String()
}
}
}
appliedEnvOverrides = append(appliedEnvOverrides, fmt.Sprintf("%s=%s", envKey, envValue))
}
}