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

Function runLogin

cli/command/registry/login.go:150–187  ·  view source on GitHub ↗
(ctx context.Context, dockerCLI command.Cli, opts loginOptions)

Source from the content-addressed store, hash-verified

148}
149
150func runLogin(ctx context.Context, dockerCLI command.Cli, opts loginOptions) error {
151 if err := verifyLoginOptions(dockerCLI, &opts); err != nil {
152 return err
153 }
154
155 maybePrintEnvAuthWarning(dockerCLI)
156
157 var (
158 serverAddress string
159 msg string
160 )
161 if opts.serverAddress != "" && opts.serverAddress != registry.DefaultNamespace {
162 serverAddress = opts.serverAddress
163 } else {
164 serverAddress = registry.IndexServer
165 }
166 isDefaultRegistry := serverAddress == registry.IndexServer
167
168 // attempt login with current (stored) credentials
169 authConfig, err := command.GetDefaultAuthConfig(dockerCLI.ConfigFile(), opts.user == "" && opts.password == "", serverAddress, isDefaultRegistry)
170 if err == nil && authConfig.Username != "" && authConfig.Password != "" {
171 msg, err = loginWithStoredCredentials(ctx, dockerCLI, authConfig)
172 }
173
174 // if we failed to authenticate with stored credentials (or didn't have stored credentials),
175 // prompt the user for new credentials
176 if err != nil || authConfig.Username == "" || authConfig.Password == "" {
177 msg, err = loginUser(ctx, dockerCLI, opts, authConfig.Username, authConfig.ServerAddress)
178 if err != nil {
179 return err
180 }
181 }
182
183 if msg != "" {
184 _, _ = fmt.Fprintln(dockerCLI.Out(), msg)
185 }
186 return nil
187}
188
189func loginWithStoredCredentials(ctx context.Context, dockerCLI command.Cli, authConfig registrytypes.AuthConfig) (msg string, _ error) {
190 _, _ = fmt.Fprintf(dockerCLI.Err(), "Authenticating with existing credentials...")

Callers 4

TestRunLoginFunction · 0.85
TestLoginNonInteractiveFunction · 0.85
TestLoginTerminationFunction · 0.85
newLoginCommandFunction · 0.85

Calls 6

verifyLoginOptionsFunction · 0.85
maybePrintEnvAuthWarningFunction · 0.85
loginUserFunction · 0.85
ConfigFileMethod · 0.65
OutMethod · 0.65

Tested by 3

TestRunLoginFunction · 0.68
TestLoginNonInteractiveFunction · 0.68
TestLoginTerminationFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…