Skip to content

Commit

Permalink
Require option flag for continuous token updates
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kpitt committed Sep 30, 2022
1 parent 94b093b commit af266f6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/commands/otp.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
8 changes: 4 additions & 4 deletions internal/action/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
},
Expand Down
12 changes: 6 additions & 6 deletions internal/action/otp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit af266f6

Please sign in to comment.