Skip to content

Add password prompt #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@
[[constraint]]
name = "github.com/urfave/cli"
version = "1.20.0"

[[constraint]]
name = "github.com/bgentry/speakeasy"
version = "0.1.0"
20 changes: 20 additions & 0 deletions shell/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/gruntwork-io/gruntwork-cli/errors"
"strings"
"github.com/fatih/color"
"github.com/bgentry/speakeasy"
)

var BRIGHT_GREEN = color.New(color.FgHiGreen, color.Bold)
Expand Down Expand Up @@ -45,3 +46,22 @@ func PromptUserForYesNo(prompt string, options *ShellOptions) (bool, error) {
}
}

// Prompt a user for a password or other sensitive info that should not be echoed back to stdout.
func PromptUserForPassword(prompt string, options *ShellOptions) (string, error) {
BRIGHT_GREEN.Print(prompt)

if options.NonInteractive {
return "", errors.WithStackTrace(NonInteractivePasswordPrompt)
}

password, err := speakeasy.Ask("")
if err != nil {
return "", errors.WithStackTrace(err)
}

return password, nil
}

// Custom error types

var NonInteractivePasswordPrompt = fmt.Errorf("The non-interactive flag is set, so unable to prompt user for a password.")