(ctx context.Context, dockerCLI command.Cli, serverAddress string)
| 42 | } |
| 43 | |
| 44 | func runLogout(ctx context.Context, dockerCLI command.Cli, serverAddress string) error { |
| 45 | maybePrintEnvAuthWarning(dockerCLI) |
| 46 | |
| 47 | var isDefaultRegistry bool |
| 48 | |
| 49 | if serverAddress == "" { |
| 50 | serverAddress = registry.IndexServer |
| 51 | isDefaultRegistry = true |
| 52 | } |
| 53 | |
| 54 | var ( |
| 55 | regsToLogout = []string{serverAddress} |
| 56 | hostnameAddress = serverAddress |
| 57 | ) |
| 58 | if !isDefaultRegistry { |
| 59 | hostnameAddress = credentials.ConvertToHostname(serverAddress) |
| 60 | // the tries below are kept for backward compatibility where a user could have |
| 61 | // saved the registry in one of the following format. |
| 62 | regsToLogout = append(regsToLogout, hostnameAddress, "http://"+hostnameAddress, "https://"+hostnameAddress) |
| 63 | } |
| 64 | |
| 65 | if isDefaultRegistry { |
| 66 | store := dockerCLI.ConfigFile().GetCredentialsStore(registry.IndexServer) |
| 67 | if err := manager.NewManager(store).Logout(ctx); err != nil { |
| 68 | _, _ = fmt.Fprintln(dockerCLI.Err(), "WARNING:", err) |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | _, _ = fmt.Fprintln(dockerCLI.Out(), "Removing login credentials for", hostnameAddress) |
| 73 | errs := make(map[string]error) |
| 74 | for _, r := range regsToLogout { |
| 75 | if err := dockerCLI.ConfigFile().GetCredentialsStore(r).Erase(r); err != nil { |
| 76 | errs[r] = err |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | // if at least one removal succeeded, report success. Otherwise report errors |
| 81 | if len(errs) == len(regsToLogout) { |
| 82 | _, _ = fmt.Fprintln(dockerCLI.Err(), "WARNING: could not erase credentials:") |
| 83 | for k, v := range errs { |
| 84 | _, _ = fmt.Fprintf(dockerCLI.Err(), "%s: %s\n", k, v) |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | return nil |
| 89 | } |
no test coverage detected
searching dependent graphs…