Merge branch 'database_url' of https://github.com/Scalingo/grafana into Scalingo-database_url

This commit is contained in:
bergquist
2016-08-19 13:15:44 +02:00
4 changed files with 60 additions and 7 deletions

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))
}
}