Merge pull request #3892 from wkloucek/env-allow-empty-override

allow overwriting a default value by setting an empty envirionment variable
This commit is contained in:
Willy Kloucek
2022-05-31 07:41:04 +02:00
committed by GitHub
2 changed files with 14 additions and 5 deletions
@@ -0,0 +1,8 @@
Bugfix: Allow empty environment variables
We've fixed the behavior for empty environment variables, that previously would
not have overwritten default values. Therefore it had the same effect like not
setting the environment variable. We now check if the environment variable is
set at all and if so, we also allow to override a default value with an empty value.
https://github.com/owncloud/ocis/pull/3892
+6 -5
View File
@@ -149,10 +149,11 @@ func decode(target interface{}, strict bool) (int, error) {
overrides := strings.Split(parts[0], `;`)
var env string
var envSet bool
for _, override := range overrides {
v := os.Getenv(override)
if v != "" {
if v, set := os.LookupEnv(override); set {
env = v
envSet = true
}
}
@@ -176,13 +177,13 @@ func decode(target interface{}, strict bool) (int, error) {
if required && hasDefault {
panic(`envdecode: "default" and "required" may not be specified in the same annotation`)
}
if env == "" && required {
if !envSet && required {
return 0, fmt.Errorf("the environment variable \"%s\" is missing", parts[0])
}
if env == "" {
if !envSet {
env = defaultValue
}
if env == "" {
if !envSet && env == "" {
continue
}