1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #22956 from Microsoft/jjh/nonttylogin

Fix bad error doing docker login in from non TTY
This commit is contained in:
Brian Goff 2016-05-25 16:45:48 -04:00
commit ff3dc48966

View file

@ -41,7 +41,6 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
}
ctx := context.Background()
var serverAddress string
var isDefaultRegistry bool
if len(cmd.Args()) > 0 {
@ -50,17 +49,14 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
serverAddress = cli.electAuthServer(ctx)
isDefaultRegistry = true
}
authConfig, err := cli.configureAuth(*flUser, *flPassword, serverAddress, isDefaultRegistry)
if err != nil {
return err
}
response, err := cli.client.RegistryLogin(ctx, authConfig)
if err != nil {
return err
}
if response.IdentityToken != "" {
authConfig.Password = ""
authConfig.IdentityToken = response.IdentityToken
@ -89,6 +85,17 @@ func (cli *DockerCli) configureAuth(flUser, flPassword, serverAddress string, is
return authconfig, err
}
// Some links documenting this:
// - https://code.google.com/archive/p/mintty/issues/56
// - https://github.com/docker/docker/issues/15272
// - https://mintty.github.io/ (compatibility)
// Linux will hit this if you attempt `cat | docker login`, and Windows
// will hit this if you attempt docker login from mintty where stdin
// is a pipe, not a character based console.
if flPassword == "" && !cli.isTerminalIn {
return authconfig, fmt.Errorf("Error: Cannot perform an interactive logon from a non TTY device")
}
authconfig.Username = strings.TrimSpace(authconfig.Username)
if flUser = strings.TrimSpace(flUser); flUser == "" {
@ -103,11 +110,9 @@ func (cli *DockerCli) configureAuth(flUser, flPassword, serverAddress string, is
flUser = authconfig.Username
}
}
if flUser == "" {
return authconfig, fmt.Errorf("Error: Non-null Username Required")
}
if flPassword == "" {
oldState, err := term.SaveState(cli.inFd)
if err != nil {