mirror of https://github.com/docker/cli.git
Merge pull request #2583 from simonferquel/logout-config-out-of-sync2
Don't filter out registries to logout from with config file contents
This commit is contained in:
commit
ba2a712ff0
|
@ -39,36 +39,29 @@ func runLogout(dockerCli command.Cli, serverAddress string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
loggedIn bool
|
regsToLogout = []string{serverAddress}
|
||||||
regsToLogout []string
|
|
||||||
hostnameAddress = serverAddress
|
hostnameAddress = serverAddress
|
||||||
regsToTry = []string{serverAddress}
|
|
||||||
)
|
)
|
||||||
if !isDefaultRegistry {
|
if !isDefaultRegistry {
|
||||||
hostnameAddress = registry.ConvertToHostname(serverAddress)
|
hostnameAddress = registry.ConvertToHostname(serverAddress)
|
||||||
// the tries below are kept for backward compatibility where a user could have
|
// the tries below are kept for backward compatibility where a user could have
|
||||||
// saved the registry in one of the following format.
|
// saved the registry in one of the following format.
|
||||||
regsToTry = append(regsToTry, hostnameAddress, "http://"+hostnameAddress, "https://"+hostnameAddress)
|
regsToLogout = append(regsToLogout, hostnameAddress, "http://"+hostnameAddress, "https://"+hostnameAddress)
|
||||||
}
|
|
||||||
|
|
||||||
// check if we're logged in based on the records in the config file
|
|
||||||
// which means it couldn't have user/pass cause they may be in the creds store
|
|
||||||
for _, s := range regsToTry {
|
|
||||||
if _, ok := dockerCli.ConfigFile().AuthConfigs[s]; ok {
|
|
||||||
loggedIn = true
|
|
||||||
regsToLogout = append(regsToLogout, s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !loggedIn {
|
|
||||||
fmt.Fprintf(dockerCli.Out(), "Not logged in to %s\n", hostnameAddress)
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(dockerCli.Out(), "Removing login credentials for %s\n", hostnameAddress)
|
fmt.Fprintf(dockerCli.Out(), "Removing login credentials for %s\n", hostnameAddress)
|
||||||
|
errs := make(map[string]error)
|
||||||
for _, r := range regsToLogout {
|
for _, r := range regsToLogout {
|
||||||
if err := dockerCli.ConfigFile().GetCredentialsStore(r).Erase(r); err != nil {
|
if err := dockerCli.ConfigFile().GetCredentialsStore(r).Erase(r); err != nil {
|
||||||
fmt.Fprintf(dockerCli.Err(), "WARNING: could not erase credentials: %v\n", err)
|
errs[r] = err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if at least one removal succeeded, report success. Otherwise report errors
|
||||||
|
if len(errs) == len(regsToLogout) {
|
||||||
|
fmt.Fprintln(dockerCli.Err(), "WARNING: could not erase credentials:")
|
||||||
|
for k, v := range errs {
|
||||||
|
fmt.Fprintf(dockerCli.Err(), "%s: %s\n", k, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue