fix environment variable names

This commit is contained in:
nils måsén 2021-01-06 17:25:00 +01:00 committed by nils måsén
parent 859fd0c1c8
commit 909c90a558

View file

@ -330,10 +330,29 @@ Should only be used for testing.`)
} }
// SetDefaults provides default values for environment variables func mustBindEnv(flag string, env string) {
func SetDefaults() { if err := viper.BindEnv(flag, env); err != nil {
day := (time.Hour * 24).Seconds() log.Fatalf("failed to bind env %q to flag %q: %v", env, flag, err)
}
}
// SetEnvBindings binds environment variables to their corresponding config keys
func SetEnvBindings() {
// Using WATCHTOWER as a prefix...
viper.SetEnvPrefix("WATCHTOWER")
// ...and replacing dashes with undescores
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
// ...map all environment variables to corresponding flags in upper case
viper.AutomaticEnv() viper.AutomaticEnv()
// Aliases for non-matching ENV keys (backwards compability)
mustBindEnv("interval", "WATCHTOWER_POLL_INTERVAL")
// Aliases for DOCKER_-prefixed env variables (matching those used for docker cli)
mustBindEnv("host", "DOCKER_HOST")
mustBindEnv("tlsverify", "DOCKER_TLS_VERIFY")
mustBindEnv("api-version", "DOCKER_API_VERSION")
} }
// BindViperFlags binds the cmd PFlags to the viper configuration // BindViperFlags binds the cmd PFlags to the viper configuration