MCPcopy Index your code
hub / github.com/docker/cli / loginUser

Function loginUser

cli/command/registry/login.go:229–254  ·  view source on GitHub ↗
(ctx context.Context, dockerCLI command.Cli, opts loginOptions, defaultUsername, serverAddress string)

Source from the content-addressed store, hash-verified

227}
228
229func 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
256func loginWithUsernameAndPassword(ctx context.Context, dockerCLI command.Cli, opts loginOptions, defaultUsername, serverAddress string) (msg string, _ error) {
257 // Prompt user for credentials

Callers 1

runLoginFunction · 0.85

Calls 5

loginWithDeviceCodeFlowFunction · 0.85
InMethod · 0.65
ErrMethod · 0.65
IsTerminalMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…