mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-03-05 07:46:54 -05:00
allow overwriting a default value by setting an empty envirionment variable
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user