From 541fba13fcbef5e082e3ce08a14901edce4697b6 Mon Sep 17 00:00:00 2001 From: John Howard Date: Tue, 24 May 2016 16:38:54 -0700 Subject: [PATCH] Error login from non TTY Signed-off-by: John Howard --- api/client/login.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/api/client/login.go b/api/client/login.go index df963db530..265466d300 100644 --- a/api/client/login.go +++ b/api/client/login.go @@ -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 {