Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
ref: use survey for password prompts (#373)
Browse files Browse the repository at this point in the history
This is a minor refactor to the password fetcher. It uses Survey instead of a home-grown password prompt.
  • Loading branch information
technosophos authored Nov 6, 2018
1 parent fea4886 commit 561ecb1
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions cmd/duffle/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"io"
"os"
"strings"
"syscall"

"gopkg.in/AlecAivazis/survey.v1"

"github.com/deis/duffle/pkg/duffle/home"
"github.com/deis/duffle/pkg/ohai"
"github.com/deis/duffle/pkg/signature"

"github.com/spf13/cobra"
"golang.org/x/crypto/ssh/terminal"
)

const (
Expand Down Expand Up @@ -242,8 +242,10 @@ func (i *initCmd) printUserID(k *signature.Key) {

// passwordFetcher is a simple prompt-based no-echo password input.
func passwordFetcher(prompt string) ([]byte, error) {
fmt.Printf("Passphrase for key %q > ", prompt)
pp, err := terminal.ReadPassword(int(syscall.Stdin))
fmt.Println()
return pp, err
var pw string
err := survey.AskOne(&survey.Password{
Message: fmt.Sprintf("Passphrase for key %q > ", prompt),
Help: "Unlock a passphrase-protected key",
}, &pw, nil)
return []byte(pw), err
}

0 comments on commit 561ecb1

Please sign in to comment.