lockbox

password manager
Log | Files | Refs | README | LICENSE

commit f13c3fbd8f508cab1db47f45bdbffdf74882dbc2
parent 44275e61d3532984ceead0ab22c305d25722eb87
Author: Sean Enck <sean@ttypty.com>
Date:   Sat,  1 Apr 2023 11:57:11 -0400

move some actions to core/query

Diffstat:
Minternal/backend/actions.go | 30------------------------------
Minternal/backend/core.go | 22++++++++++++++++++++++
Minternal/backend/query.go | 8++++++++
3 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/internal/backend/actions.go b/internal/backend/actions.go @@ -156,24 +156,6 @@ func findAndDo(isAdd bool, entityName string, offset []string, opEntity *gokeepa return g, e, done } -func splitComponents(path string) ([]string, string, error) { - if len(strings.Split(path, pathSep)) < 2 { - return nil, "", errPath - } - if strings.HasPrefix(path, pathSep) { - return nil, "", errors.New("path can NOT be rooted") - } - if strings.HasSuffix(path, pathSep) { - return nil, "", errors.New("path can NOT end with separator") - } - if strings.Contains(path, pathSep+pathSep) { - return nil, "", errors.New("unwilling to operate on path with empty segment") - } - title := base(path) - parts := strings.Split(directory(path), pathSep) - return parts, title, nil -} - // Move will move a src object to a dst location func (t *Transaction) Move(src QueryEntity, dst string) error { if strings.TrimSpace(src.Path) == "" { @@ -303,22 +285,10 @@ func (t *Transaction) RemoveAll(entities []QueryEntity) error { return nil } -func getValue(e gokeepasslib.Entry, key string) string { - v := e.Get(key) - if v == nil { - return "" - } - return v.Value.Content -} - func value(key string, value string) gokeepasslib.ValueData { return gokeepasslib.ValueData{Key: key, Value: gokeepasslib.V{Content: value}} } -func getPathName(entry gokeepasslib.Entry) string { - return entry.GetTitle() -} - func protectedValue(key string, value string) gokeepasslib.ValueData { return gokeepasslib.ValueData{ Key: key, diff --git a/internal/backend/core.go b/internal/backend/core.go @@ -41,6 +41,24 @@ func NewTransaction() (*Transaction, error) { return loadFile(os.Getenv(inputs.StoreEnv), false) } +func splitComponents(path string) ([]string, string, error) { + if len(strings.Split(path, pathSep)) < 2 { + return nil, "", errPath + } + if strings.HasPrefix(path, pathSep) { + return nil, "", errors.New("path can NOT be rooted") + } + if strings.HasSuffix(path, pathSep) { + return nil, "", errors.New("path can NOT end with separator") + } + if strings.Contains(path, pathSep+pathSep) { + return nil, "", errors.New("unwilling to operate on path with empty segment") + } + title := base(path) + parts := strings.Split(directory(path), pathSep) + return parts, title, nil +} + func getCredentials(key, keyFile string) (*gokeepasslib.DBCredentials, error) { if len(keyFile) > 0 { if !paths.Exist(keyFile) { @@ -86,3 +104,7 @@ func isTOTP(title string) (bool, error) { } return NewSuffix(title) == NewSuffix(t), nil } + +func getPathName(entry gokeepasslib.Entry) string { + return entry.GetTitle() +} diff --git a/internal/backend/query.go b/internal/backend/query.go @@ -187,3 +187,11 @@ func directory(s string) string { parts := strings.Split(s, pathSep) return NewPath(parts[0 : len(parts)-1]...) } + +func getValue(e gokeepasslib.Entry, key string) string { + v := e.Get(key) + if v == nil { + return "" + } + return v.Value.Content +}