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

add timeout on docker username #1200

Merged
merged 1 commit into from
Aug 1, 2017
Merged
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
27 changes: 21 additions & 6 deletions cmd/notary/tuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -851,23 +851,38 @@ type passwordStore struct {
anonymous bool
}

func getUsername(input chan string) {
in := bufio.NewReader(os.Stdin)
result, err := in.ReadString('\n')
if err != nil {
logrus.Errorf("error processing username input: %s", err)
input <- ""
}
input <- result
}

func (ps passwordStore) Basic(u *url.URL) (string, string) {
// if it's not a terminal, don't wait on input
if ps.anonymous {
return "", ""
}

stdin := bufio.NewReader(os.Stdin)
input := make(chan string, 1)
fmt.Fprintf(os.Stdout, "Enter username: ")

userIn, err := stdin.ReadBytes('\n')
if err != nil {
logrus.Errorf("error processing username input: %s", err)
go getUsername(input)
var username string
select {
case i := <-input:
username = strings.TrimSpace(i)
if username == "" {
return "", ""
}
case <-time.After(30 * time.Second):
logrus.Error("timeout when retrieving username input")
return "", ""
}

username := strings.TrimSpace(string(userIn))

fmt.Fprintf(os.Stdout, "Enter password: ")
passphrase, err := passphrase.GetPassphrase(stdin)
fmt.Fprintln(os.Stdout)
Expand Down