Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit d301d82

Browse files
authored
Merge pull request #2592 from thaJeztah/19.03_backport_logout_config_out_of_sync2
[19.03 backport] Don't filter out registries to logout from with config file contents Upstream-commit: 0ed913b885c8919944a2e4c8d0b80a318a8dd48b Component: cli
2 parents 051459c + 936779c commit d301d82

1 file changed

Lines changed: 12 additions & 19 deletions

File tree

components/cli/cli/command/registry/logout.go

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,36 +39,29 @@ func runLogout(dockerCli command.Cli, serverAddress string) error {
3939
}
4040

4141
var (
42-
loggedIn bool
43-
regsToLogout []string
42+
regsToLogout = []string{serverAddress}
4443
hostnameAddress = serverAddress
45-
regsToTry = []string{serverAddress}
4644
)
4745
if !isDefaultRegistry {
4846
hostnameAddress = registry.ConvertToHostname(serverAddress)
4947
// the tries below are kept for backward compatibility where a user could have
5048
// saved the registry in one of the following format.
51-
regsToTry = append(regsToTry, hostnameAddress, "http://"+hostnameAddress, "https://"+hostnameAddress)
52-
}
53-
54-
// check if we're logged in based on the records in the config file
55-
// which means it couldn't have user/pass cause they may be in the creds store
56-
for _, s := range regsToTry {
57-
if _, ok := dockerCli.ConfigFile().AuthConfigs[s]; ok {
58-
loggedIn = true
59-
regsToLogout = append(regsToLogout, s)
60-
}
61-
}
62-
63-
if !loggedIn {
64-
fmt.Fprintf(dockerCli.Out(), "Not logged in to %s\n", hostnameAddress)
65-
return nil
49+
regsToLogout = append(regsToLogout, hostnameAddress, "http://"+hostnameAddress, "https://"+hostnameAddress)
6650
}
6751

6852
fmt.Fprintf(dockerCli.Out(), "Removing login credentials for %s\n", hostnameAddress)
53+
errs := make(map[string]error)
6954
for _, r := range regsToLogout {
7055
if err := dockerCli.ConfigFile().GetCredentialsStore(r).Erase(r); err != nil {
71-
fmt.Fprintf(dockerCli.Err(), "WARNING: could not erase credentials: %v\n", err)
56+
errs[r] = err
57+
}
58+
}
59+
60+
// if at least one removal succeeded, report success. Otherwise report errors
61+
if len(errs) == len(regsToLogout) {
62+
fmt.Fprintln(dockerCli.Err(), "WARNING: could not erase credentials:")
63+
for k, v := range errs {
64+
fmt.Fprintf(dockerCli.Err(), "%s: %s\n", k, v)
7265
}
7366
}
7467

0 commit comments

Comments
 (0)