lockbox

password manager
Log | Files | Refs | README | LICENSE

commit 85d2d8ee9f09c7805dc1858385480f41ab6e48cb
parent b66bc5efb787dba690ee9cd2073dd0a4e70f9584
Author: Sean Enck <sean@ttypty.com>
Date:   Fri, 28 Jul 2023 21:08:32 -0400

'none' should disable the env config file

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

diff --git a/internal/config/core.go b/internal/config/core.go @@ -19,6 +19,7 @@ const ( yes = "yes" no = "no" detectEnvironment = "detect" + noEnvironment = "none" envFile = "lockbox.env" // MacOSPlatform is the macos indicator for platform MacOSPlatform = "macos" @@ -283,7 +284,7 @@ func ParseColorWindow(windowString string) ([]ColorWindow, error) { // it will also set the environment to empty for the caller func NewEnvFiles() ([]string, error) { v := EnvConfig.Get() - if v == "" { + if v == "" || v == noEnvironment { return []string{}, nil } EnvConfig.Set("") diff --git a/internal/config/core_test.go b/internal/config/core_test.go @@ -84,8 +84,7 @@ func TestParseWindows(t *testing.T) { } func TestNewEnvFiles(t *testing.T) { - os.Setenv("LOCKBOX_ENV", "") - os.Setenv("HOME", "test") + os.Setenv("LOCKBOX_ENV", "none") f, err := config.NewEnvFiles() if len(f) != 0 || err != nil { t.Errorf("invalid files: %v %v", f, err) @@ -95,6 +94,7 @@ func TestNewEnvFiles(t *testing.T) { if len(f) != 1 || f[0] != "test" || err != nil { t.Errorf("invalid files: %v %v", f, err) } + os.Setenv("HOME", "test") os.Setenv("LOCKBOX_ENV", "detect") f, err = config.NewEnvFiles() if len(f) != 2 || err != nil { diff --git a/internal/config/vars.go b/internal/config/vars.go @@ -19,7 +19,7 @@ const ( plainKeyMode = "plaintext" commandKeyMode = "command" commandArgsExample = "[cmd args...]" - fileExample = "file" + fileExample = "<file>" detectedValue = "(detected)" requiredKeyOrKeyFile = "a key, a key file, or both must be set" // ModTimeFormat is the expected modtime format @@ -64,7 +64,7 @@ var ( // EnvStore is the location of the keepass file/store EnvStore = EnvironmentString{environmentBase: environmentBase{key: prefixKey + "STORE", desc: "directory to the database file", requirement: "must be set"}, canDefault: false, allowed: []string{fileExample}} // EnvHookDir is the directory of hooks to execute - EnvHookDir = EnvironmentString{environmentBase: environmentBase{key: prefixKey + "HOOKDIR", desc: "the path to hooks to execute on actions against the database"}, allowed: []string{"directory"}, canDefault: true, defaultValue: ""} + EnvHookDir = EnvironmentString{environmentBase: environmentBase{key: prefixKey + "HOOKDIR", desc: "the path to hooks to execute on actions against the database"}, allowed: []string{"<directory>"}, canDefault: true, defaultValue: ""} // EnvClipCopy allows overriding the clipboard copy command EnvClipCopy = EnvironmentCommand{environmentBase: environmentBase{key: clipBaseEnv + "COPY", desc: "override the detected platform copy command"}} // EnvClipPaste allows overriding the clipboard paste command @@ -82,7 +82,7 @@ var ( 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} // EnvConfig is the location of the config file to read environment variables from - EnvConfig = EnvironmentString{environmentBase: environmentBase{key: prefixKey + "ENV", desc: fmt.Sprintf("allows setting a specific file of environment variables\nfor lockbox to read and use as configuration values (an '.env' file)\nthe keyword '%s' will search for a file in the following paths,\nmatching the first:\n%v", detectEnvironment, detectEnvironmentPaths)}, canDefault: false, allowed: []string{detectEnvironment, fileExample}} + EnvConfig = EnvironmentString{environmentBase: environmentBase{key: prefixKey + "ENV", desc: fmt.Sprintf("allows setting a specific file of environment variables\nfor lockbox to read and use as configuration values (an '.env' file).\nthe keyword '%s' will disable this functionality\nthe keyword '%s' will search for a file in the following paths\nin user's home directory\nmatching the first:\n%v", noEnvironment, detectEnvironment, detectEnvironmentPaths)}, canDefault: true, defaultValue: detectEnvironment, allowed: []string{detectEnvironment, fileExample, noEnvironment}} ) // GetReKey will get the rekey environment settings diff --git a/tests/run.sh b/tests/run.sh @@ -192,7 +192,7 @@ if [ -z "$1" ]; then fi _unset -unset LOCKBOX_ENV +export LOCKBOX_ENV="none" mkdir -p "$DATA" find "$DATA" -type f -delete