Skip to content
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

Read Secret Access Key with terminal.ReadPassword() #625

Merged
merged 1 commit into from
Aug 17, 2020
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
2 changes: 1 addition & 1 deletion cli/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func AddCommand(input AddCommandInput, keyring keyring.Keyring, awsConfigFile *v
if accessKeyId, err = prompt.TerminalPrompt("Enter Access Key ID: "); err != nil {
return fmt.Errorf(err.Error())
}
if secretKey, err = prompt.TerminalPrompt("Enter Secret Access Key: "); err != nil {
if secretKey, err = prompt.TerminalSecretPrompt("Enter Secret Access Key: "); err != nil {
return fmt.Errorf(err.Error())
}
}
Expand Down
15 changes: 15 additions & 0 deletions prompt/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"os"
"strings"

"golang.org/x/crypto/ssh/terminal"
)

func TerminalPrompt(message string) (string, error) {
Expand All @@ -19,6 +21,19 @@ func TerminalPrompt(message string) (string, error) {
return strings.TrimSpace(text), nil
}

func TerminalSecretPrompt(message string) (string, error) {
fmt.Fprint(os.Stderr, message)

text, err := terminal.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
return "", err
}

fmt.Println()

return strings.TrimSpace(string(text)), nil
}

func TerminalMfaPrompt(mfaSerial string) (string, error) {
return TerminalPrompt(mfaPromptMessage(mfaSerial))
}
Expand Down