(ctx context.Context, dockerCLI command.Cli, opts loginOptions, defaultUsername, serverAddress string)
| 227 | } |
| 228 | |
| 229 | func loginUser(ctx context.Context, dockerCLI command.Cli, opts loginOptions, defaultUsername, serverAddress string) (msg string, _ error) { |
| 230 | // Some links documenting this: |
| 231 | // - https://code.google.com/archive/p/mintty/issues/56 |
| 232 | // - https://github.com/docker/docker/issues/15272 |
| 233 | // - https://mintty.github.io/ (compatibility) |
| 234 | // Linux will hit this if you attempt `cat | docker login`, and Windows |
| 235 | // will hit this if you attempt docker login from mintty where stdin |
| 236 | // is a pipe, not a character based console. |
| 237 | if (opts.user == "" || opts.password == "") && !dockerCLI.In().IsTerminal() { |
| 238 | return "", errors.New("error: cannot perform an interactive login from a non-TTY device") |
| 239 | } |
| 240 | |
| 241 | // If we're logging into the index server and the user didn't provide a username or password, use the device flow |
| 242 | if serverAddress == registry.IndexServer && opts.user == "" && opts.password == "" { |
| 243 | var err error |
| 244 | msg, err = loginWithDeviceCodeFlow(ctx, dockerCLI) |
| 245 | // if the error represents a failure to initiate the device-code flow, |
| 246 | // then we fallback to regular cli credentials login |
| 247 | if !errors.Is(err, manager.ErrDeviceLoginStartFail) { |
| 248 | return msg, err |
| 249 | } |
| 250 | _, _ = fmt.Fprint(dockerCLI.Err(), "Failed to start web-based login - falling back to command line login...\n\n") |
| 251 | } |
| 252 | |
| 253 | return loginWithUsernameAndPassword(ctx, dockerCLI, opts, defaultUsername, serverAddress) |
| 254 | } |
| 255 | |
| 256 | func loginWithUsernameAndPassword(ctx context.Context, dockerCLI command.Cli, opts loginOptions, defaultUsername, serverAddress string) (msg string, _ error) { |
| 257 | // Prompt user for credentials |
no test coverage detected
searching dependent graphs…