commit dae897d94b988517da6194f6f418edef1212b35e
parent da1e27820a1ef0097e36e6c6ef74730af25b6a03
Author: Sean Enck <sean@ttypty.com>
Date: Sat, 29 Jul 2023 09:45:27 -0400
allow setting expansion in the env file itself too
Diffstat:
3 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/internal/config/core.go b/internal/config/core.go
@@ -348,7 +348,14 @@ func ExpandParsed(inputs map[string]string) (map[string]string, error) {
if len(inputs) == 0 {
return inputs, nil
}
- cycles, err := envConfigExpands.Get()
+ var err error
+ var cycles int
+ possibleCycles, ok := inputs[envConfigExpands.key]
+ if ok {
+ cycles, err = strconv.Atoi(possibleCycles)
+ } else {
+ cycles, err = envConfigExpands.Get()
+ }
if err != nil {
return nil, err
}
diff --git a/internal/config/core_test.go b/internal/config/core_test.go
@@ -176,9 +176,15 @@ func TestExpandParsed(t *testing.T) {
if err == nil || err.Error() != "strconv.Atoi: parsing \"a\": invalid syntax" {
t.Errorf("invalid error: %v", err)
}
- os.Setenv("LOCKBOX_ENV_EXPANDS", "0")
+ ins["LOCKBOX_ENV_EXPANDS"] = "1"
r, err = config.ExpandParsed(ins)
- if err != nil || len(r) != 1 || r["TEST"] != "$TEST_ABC" {
+ if err != nil || len(r) != 2 || r["TEST"] != "1" {
+ t.Errorf("invalid expand: %v", r)
+ }
+ delete(ins, "LOCKBOX_ENV_EXPANDS")
+ os.Setenv("LOCKBOX_ENV_EXPANDS", "1")
+ r, err = config.ExpandParsed(ins)
+ if err != nil || len(r) != 1 || r["TEST"] != "1" {
t.Errorf("invalid expand: %v", r)
}
os.Setenv("LOCKBOX_ENV_EXPANDS", "1")
diff --git a/internal/config/vars.go b/internal/config/vars.go
@@ -82,7 +82,7 @@ var (
EnvConfig = EnvironmentString{environmentBase: environmentBase{key: prefixKey + "ENV", desc: fmt.Sprintf("Allows setting a specific file of environment variables for lockbox\nto read and use as configuration values (an '.env' file). The keyword\n'%s' will disable this functionality the keyword '%s' will search\nfor a file in the following paths in user's home directory matching\nthe first file found.\n\ndefault search paths:\n%v\n\nNote that this setting is not output as part of the environment.", noEnvironment, detectEnvironment, detectEnvironmentPaths)}, canDefault: true, defaultValue: detectEnvironment, allowed: []string{detectEnvironment, fileExample, noEnvironment}}
envKeyMode = EnvironmentString{environmentBase: environmentBase{key: prefixKey + "KEYMODE", requirement: "must be set to a valid mode when using a key", desc: "How to retrieve the database store password."}, allowed: []string{commandKeyMode, plainKeyMode}, canDefault: true, defaultValue: commandKeyMode}
envKey = EnvironmentString{environmentBase: environmentBase{requirement: requiredKeyOrKeyFile, key: prefixKey + "KEY", desc: fmt.Sprintf("The database key ('%s' mode) or command to run ('%s' mode)\nto retrieve the database password.", plainKeyMode, commandKeyMode)}, allowed: []string{commandArgsExample, "password"}, canDefault: false}
- envConfigExpands = EnvironmentInt{environmentBase: environmentBase{key: EnvConfig.key + "_EXPANDS", desc: "The number of times to expand the input configuration to resolve variables."}, shortDesc: "hash length", allowZero: true, defaultValue: 3}
+ envConfigExpands = EnvironmentInt{environmentBase: environmentBase{key: EnvConfig.key + "_EXPANDS", desc: "The number of times to expand the input configuration to resolve variables.\nThis value can NOT be an expansion itself if set in the env config file."}, shortDesc: "hash length", allowZero: true, defaultValue: 3}
)
// GetReKey will get the rekey environment settings