MCPcopy Create free account
hub / github.com/docker/cli / runLogout

Function runLogout

cli/command/registry/logout.go:44–89  ·  view source on GitHub ↗
(ctx context.Context, dockerCLI command.Cli, serverAddress string)

Source from the content-addressed store, hash-verified

42}
43
44func 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}

Callers 1

newLogoutCommandFunction · 0.85

Calls 7

maybePrintEnvAuthWarningFunction · 0.85
GetCredentialsStoreMethod · 0.80
LogoutMethod · 0.80
ConfigFileMethod · 0.65
ErrMethod · 0.65
OutMethod · 0.65
EraseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…