lockbox

password manager
Log | Files | Refs | README | LICENSE

commit 26c5690dc5db31e5727b27bc9eacdbc43c454aad
parent a056729ea4e1120aad9af942fd5c5747f52e3e4a
Author: Sean Enck <sean@ttypty.com>
Date:   Wed, 26 Jul 2023 21:01:43 -0400

convert mod time

Diffstat:
Minternal/app/rekey.go | 2+-
Minternal/backend/actions.go | 2+-
Minternal/inputs/env.go | 4++++
Minternal/inputs/vars.go | 6+++---
4 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/internal/app/rekey.go b/internal/app/rekey.go @@ -96,7 +96,7 @@ func ReKey(cmd CommandOptions, r Keyer) error { } var insertEnv []string insertEnv = append(insertEnv, vars...) - insertEnv = append(insertEnv, fmt.Sprintf("%s=%s", inputs.ModTimeEnv, modTime)) + insertEnv = append(insertEnv, inputs.EnvModTime.Set(modTime)) if err := r.Insert(ReKeyEntry{Path: path, Env: insertEnv, Data: []byte(entry.Data)}); err != nil { return err } diff --git a/internal/backend/actions.go b/internal/backend/actions.go @@ -163,7 +163,7 @@ func (t *Transaction) Move(src QueryEntity, dst string) error { if strings.TrimSpace(src.Value) == "" { return errors.New("empty secret not allowed") } - mod := inputs.EnvironOrDefault(inputs.ModTimeEnv, "") + mod := inputs.EnvModTime.Get() modTime := time.Now() if mod != "" { p, err := time.Parse(inputs.ModTimeFormat, mod) diff --git a/internal/inputs/env.go b/internal/inputs/env.go @@ -140,3 +140,7 @@ func (e EnvironmentCommand) Get() ([]string, error) { } return shlex(value) } + +func (e environmentBase) Set(value string) string { + return fmt.Sprintf("%s=%s", e.key, value) +} diff --git a/internal/inputs/vars.go b/internal/inputs/vars.go @@ -23,8 +23,6 @@ const ( defaultTOTPField = "totp" commandArgsExample = "[cmd args...]" detectedValue = "(detected)" - // ModTimeEnv is modtime override ability for entries - ModTimeEnv = prefixKey + "SET_MODTIME" // ModTimeFormat is the expected modtime format ModTimeFormat = time.RFC3339 // JSONDataOutputEnv controls how JSON is output @@ -74,6 +72,8 @@ var ( EnvKeyFile = EnvironmentString{environmentBase: environmentBase{key: prefixKey + "KEYFILE"}, canDefault: true, defaultValue: ""} envKeyMode = EnvironmentString{environmentBase: environmentBase{key: prefixKey + "KEYMODE"}, canDefault: true, defaultValue: commandKeyMode} envKey = EnvironmentString{environmentBase: environmentBase{key: prefixKey + "KEY"}, canDefault: false} + // EnvModTime is modtime override ability for entries + EnvModTime = EnvironmentString{environmentBase: environmentBase{key: prefixKey + "SET_MODTIME"}, canDefault: true, defaultValue: ""} ) type ( @@ -191,7 +191,7 @@ func ListEnvironmentVariables(showValues bool) []string { results = append(results, e.formatEnvironmentVariable(false, EnvHookDir.key, "", "the path to hooks to execute on actions against the database", []string{"directory"})) results = append(results, e.formatEnvironmentVariable(false, EnvClipOSC52.key, no, "enable OSC52 clipboard mode", isYesNoArgs)) results = append(results, e.formatEnvironmentVariable(false, EnvKeyFile.key, "", "additional keyfile to access/protect the database", []string{"keyfile"})) - results = append(results, e.formatEnvironmentVariable(false, ModTimeEnv, ModTimeFormat, fmt.Sprintf("input modification time to set for the entry\n(expected format: %s)", ModTimeFormat), []string{"modtime"})) + results = append(results, e.formatEnvironmentVariable(false, EnvModTime.key, ModTimeFormat, fmt.Sprintf("input modification time to set for the entry\n(expected format: %s)", ModTimeFormat), []string{"modtime"})) results = append(results, e.formatEnvironmentVariable(false, JSONDataOutputEnv, string(JSONDataOutputHash), fmt.Sprintf("changes what the data field in JSON outputs will contain\nuse '%s' with CAUTION", JSONDataOutputRaw), []string{string(JSONDataOutputRaw), string(JSONDataOutputHash), string(JSONDataOutputBlank)})) results = append(results, e.formatEnvironmentVariable(false, EnvHashLength.key, fmt.Sprintf("%d", EnvHashLength.defaultValue), fmt.Sprintf("maximum hash length the JSON output should contain\nwhen '%s' mode is set for JSON output", JSONDataOutputHash), intArgs)) return results