(ctx context.Context, dockerCLI command.Cli, authConfig registrytypes.AuthConfig)
| 187 | } |
| 188 | |
| 189 | func 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 | |
| 229 | func loginUser(ctx context.Context, dockerCLI command.Cli, opts loginOptions, defaultUsername, serverAddress string) (msg string, _ error) { |
| 230 | // Some links documenting this: |
searching dependent graphs…