lockbox

password manager
Log | Files | Refs | README | LICENSE

commit 4bab0442b6cf611a0b1f11921604fc953a1baa47
parent 4c99af8deb603b9675ccd35d4ba9da1cbde05ba8
Author: Sean Enck <sean@ttypty.com>
Date:   Sat,  1 Oct 2022 12:36:31 -0400

move all field manipulations to backend

Diffstat:
Mcmd/vers.txt | 2+-
Minternal/backend/query.go | 17+++++++++++++++++
Minternal/subcommands/totp.go | 7+++----
3 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/cmd/vers.txt b/cmd/vers.txt @@ -1 +1 @@ -v22.10.01 +v22.10.02 diff --git a/internal/backend/query.go b/internal/backend/query.go @@ -5,6 +5,8 @@ import ( "crypto/sha512" "errors" "fmt" + "os" + "path/filepath" "sort" "strings" @@ -132,3 +134,18 @@ func (t *Transaction) QueryCallback(args QueryOptions) ([]QueryEntity, error) { } return results, nil } + +// NewSuffix creates a new user 'name' suffix +func NewSuffix(name string) string { + return fmt.Sprintf("%c%s", os.PathSeparator, name) +} + +// NewPath creates a new storage location path. +func NewPath(segments ...string) string { + return filepath.Join(segments...) +} + +// Directory gets the offset location of the entry without the 'name' +func (e QueryEntity) Directory() string { + return filepath.Dir(e.Path) +} diff --git a/internal/subcommands/totp.go b/internal/subcommands/totp.go @@ -6,7 +6,6 @@ import ( "fmt" "os" "os/exec" - "path/filepath" "strconv" "strings" "time" @@ -94,7 +93,7 @@ func display(token string, args cli.Arguments) error { if err != nil { return err } - entity, err := t.Get(filepath.Join(token, totpEnv()), backend.SecretValue) + entity, err := t.Get(backend.NewPath(token, totpEnv()), backend.SecretValue) if err != nil { return err } @@ -195,12 +194,12 @@ func TOTP(args []string) error { if err != nil { return err } - e, err := t.QueryCallback(backend.QueryOptions{Mode: backend.SuffixMode, Criteria: fmt.Sprintf("%c%s", os.PathSeparator, totpEnv())}) + e, err := t.QueryCallback(backend.QueryOptions{Mode: backend.SuffixMode, Criteria: backend.NewSuffix(totpEnv())}) if err != nil { return err } for _, entry := range e { - fmt.Println(filepath.Dir(entry.Path)) + fmt.Println(entry.Directory()) } return nil }