lockbox

password manager
Log | Files | Refs | README | LICENSE

commit dd8125cdf0da2cee8e043346eb82846a24b57a06
parent 1929337856271d47c50bc926c12c9ff0c38ed81d
Author: Sean Enck <sean@ttypty.com>
Date:   Fri,  3 Mar 2023 19:22:57 -0500

this helper is not overly useful

Diffstat:
Mcmd/main.go | 2--
Minternal/app/core.go | 9+++------
Minternal/app/insert.go | 19+------------------
Minternal/cli/completions.bash | 4++--
Minternal/cli/core.go | 5-----
Minternal/cli/core_test.go | 4++--
Mscripts/testing/check.go | 4----
Mscripts/testing/expected.log | 1-
8 files changed, 8 insertions(+), 40 deletions(-)

diff --git a/cmd/main.go b/cmd/main.go @@ -81,8 +81,6 @@ func run() error { insert := app.InsertOptions{} insert.Confirm = confirm insert.IsPipe = inputs.IsInputFromPipe - insert.IsNoTOTP = inputs.IsNoTOTP - insert.TOTPToken = inputs.TOTPToken insert.Input = inputs.GetUserInputPassword insertArgs, err := app.ParseInsertArgs(insert, sub) if err != nil { diff --git a/internal/app/core.go b/internal/app/core.go @@ -6,17 +6,14 @@ type ( Confirm func(string) bool // InsertOptions are functions required for insert InsertOptions struct { - IsNoTOTP func() (bool, error) - IsPipe func() bool - TOTPToken func() string - Input func(bool, bool) ([]byte, error) - Confirm Confirm + IsPipe func() bool + Input func(bool, bool) ([]byte, error) + Confirm Confirm } // InsertArgs are parsed insert settings for insert commands InsertArgs struct { Entry string Multi bool - TOTP bool Opts InsertOptions } ) diff --git a/internal/app/insert.go b/internal/app/insert.go @@ -9,7 +9,6 @@ import ( "github.com/enckse/lockbox/internal/backend" "github.com/enckse/lockbox/internal/cli" - "github.com/enckse/lockbox/internal/totp" ) func insertError(message string, err error) error { @@ -19,7 +18,6 @@ func insertError(message string, err error) error { // ParseInsertArgs will parse the input args for insert commands func ParseInsertArgs(cmd InsertOptions, args []string) (InsertArgs, error) { multi := false - isTOTP := false idx := 0 switch len(args) { case 0: @@ -30,15 +28,6 @@ func ParseInsertArgs(cmd InsertOptions, args []string) (InsertArgs, error) { switch opt { case cli.InsertMultiCommand: multi = true - case cli.InsertTOTPCommand: - off, err := cmd.IsNoTOTP() - if err != nil { - return InsertArgs{}, err - } - if off { - return InsertArgs{}, totp.ErrNoTOTP - } - isTOTP = true default: return InsertArgs{}, errors.New("unknown argument") } @@ -47,17 +36,11 @@ func ParseInsertArgs(cmd InsertOptions, args []string) (InsertArgs, error) { default: return InsertArgs{}, errors.New("too many arguments") } - return InsertArgs{Opts: cmd, Multi: multi, TOTP: isTOTP, Entry: args[idx]}, nil + return InsertArgs{Opts: cmd, Multi: multi, Entry: args[idx]}, nil } // Do will execute an insert func (args InsertArgs) Do(w io.Writer, t *backend.Transaction) error { - if args.TOTP { - totpToken := args.Opts.TOTPToken() - if !strings.HasSuffix(args.Entry, backend.NewSuffix(totpToken)) { - args.Entry = backend.NewPath(args.Entry, totpToken) - } - } existing, err := t.Get(args.Entry, backend.BlankValue) if err != nil { return insertError("unable to check for existing entry", err) diff --git a/internal/cli/completions.bash b/internal/cli/completions.bash @@ -13,7 +13,7 @@ _{{ $.Executable }}() { case ${COMP_WORDS[1]} in {{ if not $.ReadOnly }} "{{ $.InsertCommand }}") - opts="{{ $.InsertMultiCommand }}{{ if $.CanTOTP }} {{ $.InsertTOTPCommand }}{{end}} $({{ $.DoList }})" + opts="{{ $.InsertMultiCommand }} $({{ $.DoList }})" ;; "{{ $.HelpCommand }}") opts="{{ $.HelpAdvancedCommand }}" @@ -39,7 +39,7 @@ _{{ $.Executable }}() { case "${COMP_WORDS[1]}" in {{ if not $.ReadOnly }} "{{ $.InsertCommand }}") - if [ "${COMP_WORDS[2]}" == "{{ $.InsertMultiCommand }}" ] {{ if $.CanTOTP }}|| [ "${COMP_WORDS[2]}" == "{{ $.InsertTOTPCommand }}" ] {{end}}; then + if [ "${COMP_WORDS[2]}" == "{{ $.InsertMultiCommand }}" ]; then opts=$({{ $.DoList }}) fi ;; diff --git a/internal/cli/core.go b/internal/cli/core.go @@ -47,8 +47,6 @@ const ( EnvCommand = "env" // InsertMultiCommand handles multi-line inserts InsertMultiCommand = "-multi" - // InsertTOTPCommand is a helper for totp inserts - InsertTOTPCommand = "-totp" // TOTPClipCommand is the argument for copying totp codes to clipboard TOTPClipCommand = "-clip" // TOTPShortCommand is the argument for getting the short version of a code @@ -87,7 +85,6 @@ type ( TOTPOnceCommand string TOTPClipCommand string InsertMultiCommand string - InsertTOTPCommand string RemoveCommand string ClipCommand string ShowCommand string @@ -145,7 +142,6 @@ func BashCompletions(defaults bool) ([]string, error) { InsertMultiCommand: InsertMultiCommand, HelpCommand: HelpCommand, HelpAdvancedCommand: HelpAdvancedCommand, - InsertTOTPCommand: InsertTOTPCommand, TOTPCommand: TOTPCommand, MoveCommand: MoveCommand, DoList: fmt.Sprintf("%s %s", name, ListCommand), @@ -216,7 +212,6 @@ func Usage(verbose bool) ([]string, error) { results = append(results, subCommand(HelpCommand, HelpAdvancedCommand, "", "display verbose help information")) results = append(results, command(InsertCommand, "entry", "insert a new entry into the store")) results = append(results, subCommand(InsertCommand, InsertMultiCommand, "entry", "insert a multi-line entry")) - results = append(results, subCommand(InsertCommand, InsertTOTPCommand, "entry", "insert a new totp entry")) results = append(results, command(ListCommand, "", "list entries")) results = append(results, command(MoveCommand, "src dst", "move an entry from source to destination")) results = append(results, command(RemoveCommand, "entry", "remove an entry from the store")) diff --git a/internal/cli/core_test.go b/internal/cli/core_test.go @@ -10,11 +10,11 @@ import ( func TestUsage(t *testing.T) { u, _ := cli.Usage(false) - if len(u) != 22 { + if len(u) != 21 { t.Errorf("invalid usage, out of date? %d", len(u)) } u, _ = cli.Usage(true) - if len(u) != 81 { + if len(u) != 80 { t.Errorf("invalid verbose usage, out of date? %d", len(u)) } for _, usage := range u { diff --git a/scripts/testing/check.go b/scripts/testing/check.go @@ -145,10 +145,6 @@ func execute() error { show("keys/k/one2") show("keys2/k/three") runCommand([]string{"stats", "keys2/k/three"}, nil) - for _, k := range []string{"test/k", "test/k/totp"} { - runCommand([]string{"insert", "-totp", k}, []string{"5ae472abqdekjqykoyxk7hvc2leklq5n"}) - } - totpList() insert("test/k/totp", []string{"5ae472abqdekjqykoyxk7hvc2leklq5n"}) totpList() runCommand([]string{"totp", "test/k"}, nil) diff --git a/scripts/testing/expected.log b/scripts/testing/expected.log @@ -20,7 +20,6 @@ test3 test4 modtime: XXXX-XX-XX test/k -test/k XXXXXX key/a/one: modtime: XXXX-XX-XX