@@ -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