Skip to content

Commit be307c5

Browse files
committed
cli/command/system: prettyPrintServerInfo: move out collecting username
Make this function only _print_ the info we have, and not read the username from the credential-store. This patch adds a Username field to the (local) `info` type, and sets it when needed, so that prettyPrintServerInfo only has to format and print the information, instead of calling out to the credential-store. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 71fde20 commit be307c5

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

cli/command/system/info.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type info struct {
4242
// object.
4343
*types.Info `json:",omitempty"`
4444
ServerErrors []string `json:",omitempty"`
45+
UserName string `json:"-"`
4546

4647
ClientInfo *clientInfo `json:",omitempty"`
4748
ClientErrors []string `json:",omitempty"`
@@ -113,6 +114,7 @@ func runInfo(cmd *cobra.Command, dockerCli command.Cli, opts *infoOptions) error
113114
}
114115

115116
if opts.format == "" {
117+
info.UserName = dockerCli.ConfigFile().AuthConfigs[registry.IndexServer].Username
116118
return prettyPrintInfo(dockerCli, info)
117119
}
118120
return formatInfo(dockerCli, info, opts.format)
@@ -174,7 +176,7 @@ func prettyPrintInfo(dockerCli command.Cli, info info) error {
174176
fmt.Fprintln(dockerCli.Out())
175177
fmt.Fprintln(dockerCli.Out(), "Server:")
176178
if info.Info != nil {
177-
for _, err := range prettyPrintServerInfo(dockerCli, *info.Info) {
179+
for _, err := range prettyPrintServerInfo(dockerCli, &info) {
178180
info.ServerErrors = append(info.ServerErrors, err.Error())
179181
}
180182
}
@@ -212,7 +214,7 @@ func prettyPrintClientInfo(dockerCli command.Cli, info clientInfo) {
212214
}
213215

214216
//nolint:gocyclo
215-
func prettyPrintServerInfo(dockerCli command.Cli, info types.Info) []error {
217+
func prettyPrintServerInfo(dockerCli command.Cli, info *info) []error {
216218
var errs []error
217219

218220
fmt.Fprintln(dockerCli.Out(), " Containers:", info.Containers)
@@ -247,7 +249,7 @@ func prettyPrintServerInfo(dockerCli command.Cli, info types.Info) []error {
247249
fmt.Fprintln(dockerCli.Out(), " Log:", strings.Join(info.Plugins.Log, " "))
248250

249251
fmt.Fprintln(dockerCli.Out(), " Swarm:", info.Swarm.LocalNodeState)
250-
printSwarmInfo(dockerCli, info)
252+
printSwarmInfo(dockerCli, *info.Info)
251253

252254
if len(info.Runtimes) > 0 {
253255
fmt.Fprint(dockerCli.Out(), " Runtimes:")
@@ -319,10 +321,7 @@ func prettyPrintServerInfo(dockerCli command.Cli, info types.Info) []error {
319321
fprintlnNonEmpty(dockerCli.Out(), " HTTP Proxy:", info.HTTPProxy)
320322
fprintlnNonEmpty(dockerCli.Out(), " HTTPS Proxy:", info.HTTPSProxy)
321323
fprintlnNonEmpty(dockerCli.Out(), " No Proxy:", info.NoProxy)
322-
323-
u := dockerCli.ConfigFile().AuthConfigs[registry.IndexServer].Username
324-
fprintlnNonEmpty(dockerCli.Out(), " Username:", u)
325-
324+
fprintlnNonEmpty(dockerCli.Out(), " Username:", info.UserName)
326325
if len(info.Labels) > 0 {
327326
fmt.Fprintln(dockerCli.Out(), " Labels:")
328327
for _, lbl := range info.Labels {
@@ -367,7 +366,7 @@ func prettyPrintServerInfo(dockerCli command.Cli, info types.Info) []error {
367366

368367
fmt.Fprint(dockerCli.Out(), "\n")
369368

370-
printServerWarnings(dockerCli, info)
369+
printServerWarnings(dockerCli, *info.Info)
371370
return errs
372371
}
373372

0 commit comments

Comments
 (0)