lockbox

password manager
Log | Files | Refs | README | LICENSE

commit 5643c3f244726a6e7455d9b7b44084c5ca3079b1
parent dae897d94b988517da6194f6f418edef1212b35e
Author: Sean Enck <sean@ttypty.com>
Date:   Sat, 29 Jul 2023 10:08:39 -0400

change expands to be a maximum count cycle

Diffstat:
Minternal/config/core.go | 2+-
Minternal/config/core_test.go | 11+++++------
Minternal/config/vars.go | 2+-
3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/internal/config/core.go b/internal/config/core.go @@ -385,7 +385,7 @@ func ExpandParsed(inputs map[string]string) (map[string]string, error) { result = expanded cycles-- } - return result, nil + return nil, errors.New("reached maximum expand cycle count") } func expandParsed(inputs map[string]string) map[string]string { diff --git a/internal/config/core_test.go b/internal/config/core_test.go @@ -176,18 +176,18 @@ func TestExpandParsed(t *testing.T) { if err == nil || err.Error() != "strconv.Atoi: parsing \"a\": invalid syntax" { t.Errorf("invalid error: %v", err) } - ins["LOCKBOX_ENV_EXPANDS"] = "1" + ins["LOCKBOX_ENV_EXPANDS"] = "2" r, err = config.ExpandParsed(ins) 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") + os.Setenv("LOCKBOX_ENV_EXPANDS", "2") 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") + os.Setenv("LOCKBOX_ENV_EXPANDS", "2") r, err = config.ExpandParsed(ins) if err != nil || len(r) != 1 || r["TEST"] != "1" { t.Errorf("invalid expand: %v", r) @@ -196,9 +196,8 @@ func TestExpandParsed(t *testing.T) { os.Setenv("OTHER_TEST", "$ANOTHER_TEST") os.Setenv("ANOTHER_TEST", "2") os.Setenv("LOCKBOX_ENV_EXPANDS", "1") - r, err = config.ExpandParsed(ins) - if err != nil || len(r) != 1 || r["TEST"] != "$OTHER_TEST" { - t.Errorf("invalid expand: %v", r) + if _, err = config.ExpandParsed(ins); err == nil || err.Error() != "reached maximum expand cycle count" { + t.Errorf("invalid error: %v", err) } os.Setenv("LOCKBOX_ENV_EXPANDS", "2") ins["OTHER_FIRST"] = "2" 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.\nThis value can NOT be an expansion itself if set in the env config file."}, shortDesc: "hash length", allowZero: true, defaultValue: 3} + envConfigExpands = EnvironmentInt{environmentBase: environmentBase{key: EnvConfig.key + "_EXPANDS", desc: "The maximum number of times to expand the input env to resolve variables,\nset to 0 to disable expansion. This value can NOT be an expansion itself\nif set in the env config file."}, shortDesc: "max expands", allowZero: true, defaultValue: 20} ) // GetReKey will get the rekey environment settings