Expand env vars in Values/StringValues [#34]

This commit is contained in:
Erin Call
2020-01-21 15:37:59 -08:00
parent 713dcd8317
commit e843b26759
3 changed files with 55 additions and 0 deletions

View File

@@ -93,11 +93,31 @@ func NewConfig(stdout, stderr io.Writer) (*Config, error) {
cfg.logDebug()
}
cfg.loadValuesSecrets()
cfg.deprecationWarn()
return &cfg, nil
}
func (cfg *Config) loadValuesSecrets() {
findVar := regexp.MustCompile(`\$\{?(\w+)\}?`)
replacer := func(varName string) string {
sigils := regexp.MustCompile(`[${}]`)
varName = sigils.ReplaceAllString(varName, "")
if value, ok := os.LookupEnv(varName); ok {
return value
}
return ""
}
cfg.Values = findVar.ReplaceAllStringFunc(cfg.Values, replacer)
cfg.StringValues = findVar.ReplaceAllStringFunc(cfg.StringValues, replacer)
}
func (cfg Config) logDebug() {
if cfg.KubeToken != "" {
cfg.KubeToken = "(redacted)"