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

Function loginWithStoredCredentials

cli/command/registry/login.go:189–227  ·  view source on GitHub ↗
(ctx context.Context, dockerCLI command.Cli, authConfig registrytypes.AuthConfig)

Source from the content-addressed store, hash-verified

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...")
191 if authConfig.Username != "" {
192 _, _ = fmt.Fprintf(dockerCLI.Err(), " [Username: %s]", authConfig.Username)
193 }
194 _, _ = fmt.Fprint(dockerCLI.Err(), "\n")
195
196 out := tui.NewOutput(dockerCLI.Err())
197 out.PrintNote("To login with a different account, run 'docker logout' followed by 'docker login'")
198
199 _, _ = fmt.Fprint(dockerCLI.Err(), "\n\n")
200
201 resp, err := dockerCLI.Client().RegistryLogin(ctx, client.RegistryLoginOptions{
202 Username: authConfig.Username,
203 Password: authConfig.Password,
204 ServerAddress: authConfig.ServerAddress,
205 IdentityToken: authConfig.IdentityToken,
206 RegistryToken: authConfig.RegistryToken,
207 })
208 if err != nil {
209 if errdefs.IsUnauthorized(err) {
210 _, _ = fmt.Fprintln(dockerCLI.Err(), "Stored credentials invalid or expired")
211 } else {
212 _, _ = fmt.Fprintln(dockerCLI.Err(), "Login did not succeed, error:", err)
213 }
214 // TODO(thaJeztah): should this return the error here, or is there a reason for continuing?
215 }
216
217 if resp.Auth.IdentityToken != "" {
218 authConfig.Password = ""
219 authConfig.IdentityToken = resp.Auth.IdentityToken
220 }
221
222 if err := storeCredentials(dockerCLI.ConfigFile(), authConfig); err != nil {
223 return "", err
224 }
225
226 return resp.Auth.Status, err
227}
228
229func loginUser(ctx context.Context, dockerCLI command.Cli, opts loginOptions, defaultUsername, serverAddress string) (msg string, _ error) {
230 // Some links documenting this:

Callers 2

runLoginFunction · 0.85

Calls 6

PrintNoteMethod · 0.95
storeCredentialsFunction · 0.85
RegistryLoginMethod · 0.80
ErrMethod · 0.65
ClientMethod · 0.65
ConfigFileMethod · 0.65

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…