Skip to content

Commit

Permalink
Merge pull request #1200 from eiais/login_timeout
Browse files Browse the repository at this point in the history
add timeout on docker username
  • Loading branch information
riyazdf committed Aug 1, 2017
2 parents 9d9ac96 + 403b9cc commit c63c37c
Showing 1 changed file with 21 additions and 6 deletions.
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

0 comments on commit c63c37c

Please sign in to comment.