allow overwriting a default value by setting an empty envirionment variable

This commit is contained in:
Willy Kloucek
2022-05-30 15:54:21 +02:00
parent d4e0045723
commit 88830425cc
2 changed files with 14 additions and 5 deletions

View File

@@ -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

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
}