From 561ecb1809c77a637c5931e5aadf031f95e22a3e Mon Sep 17 00:00:00 2001 From: Matt Butcher Date: Tue, 6 Nov 2018 11:03:54 -0700 Subject: [PATCH] ref: use survey for password prompts (#373) This is a minor refactor to the password fetcher. It uses Survey instead of a home-grown password prompt. --- cmd/duffle/init.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cmd/duffle/init.go b/cmd/duffle/init.go index f7e50ae1..30a30215 100644 --- a/cmd/duffle/init.go +++ b/cmd/duffle/init.go @@ -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 ( @@ -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 }