From af266f6a63d1fe5f171951d5610a80fa54c07cb1 Mon Sep 17 00:00:00 2001 From: Kenny Pitt Date: Fri, 30 Sep 2022 14:04:43 -0400 Subject: [PATCH] Require option flag for continuous token updates The `otp` extension command for `pass` always prints a single token. To improve drop-in compatibility, this is now the default behavior for `gopass otp`, and an option is required to enable continuous updates. --- docs/commands/otp.md | 2 +- internal/action/commands.go | 8 ++++---- internal/action/otp.go | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/commands/otp.md b/docs/commands/otp.md index 609b770c36..3395d929d7 100644 --- a/docs/commands/otp.md +++ b/docs/commands/otp.md @@ -15,4 +15,4 @@ Flag | Aliases | Description ---- | ------- | ----------- `--clip` | `-c` | Copy the time-based token into the clipboard. `--qr` | `-q` | Write QR code to file. -`--password` | `-o` | Only display the token. For use in scripts. +`--continuous` | `-C` | Display tokens continuously until interrupted. diff --git a/internal/action/commands.go b/internal/action/commands.go index 2d18aac232..34af8486cc 100644 --- a/internal/action/commands.go +++ b/internal/action/commands.go @@ -637,12 +637,12 @@ Use the "git init" command if the store does not yet have a git repository.`, &cli.StringFlag{ Name: "qr", Aliases: []string{"q"}, - Usage: "Write QR code to FILE", + Usage: "Write QR code to `FILE`", }, &cli.BoolFlag{ - Name: "password", - Aliases: []string{"o"}, - Usage: "Only display the token", + Name: "continuous", + Aliases: []string{"C"}, + Usage: "Display tokens continuously until interrupted", }, }, }, diff --git a/internal/action/otp.go b/internal/action/otp.go index 82a0e1775a..96633d054e 100644 --- a/internal/action/otp.go +++ b/internal/action/otp.go @@ -34,9 +34,9 @@ func (s *Action) OTP(c *cli.Context) error { qrf := c.String("qr") clip := c.Bool("clip") - pw := c.Bool("password") + continuous := c.Bool("continuous") - return s.otp(ctx, name, qrf, clip, pw, true) + return s.otp(ctx, name, qrf, clip, continuous, true) } func tickingBar(ctx context.Context, expiresAt time.Time, bar *termio.ProgressBar) { @@ -88,16 +88,16 @@ func waitForKeyPress(ctx context.Context, cancel context.CancelFunc) { } //nolint:cyclop -func (s *Action) otp(ctx context.Context, name, qrf string, clip, pw, recurse bool) error { +func (s *Action) otp(ctx context.Context, name, qrf string, clip, continuous, recurse bool) error { sec, err := s.Store.Get(ctx, name) if err != nil { - return s.otpHandleError(ctx, name, qrf, clip, pw, recurse, err) + return s.otpHandleError(ctx, name, qrf, clip, continuous, recurse, err) } ctx, cancel := context.WithCancel(ctx) defer cancel() - skip := ctxutil.IsHidden(ctx) || pw || qrf != "" || !ctxutil.IsTerminal(ctx) || !ctxutil.IsInteractive(ctx) || clip + skip := ctxutil.IsHidden(ctx) || !continuous || qrf != "" || !ctxutil.IsTerminal(ctx) || !ctxutil.IsInteractive(ctx) || clip if !skip { // let us monitor key presses for cancellation:. out.Warningf(ctx, "%s", "[q] to stop. -o flag to avoid.") @@ -168,7 +168,7 @@ func (s *Action) otp(ctx context.Context, name, qrf string, clip, pw, recurse bo } // check if we are in "password only" or in "qr code" mode or being redirected to a pipe. - if pw || qrf != "" || !ctxutil.IsTerminal(ctx) { + if !continuous || qrf != "" || !ctxutil.IsTerminal(ctx) { out.Printf(ctx, "%s", token) cancel() } else { // if not then we want to print a progress bar with the expiry time.