Skip to content

Commit 04bf047

Browse files
authored
Merge pull request #4205 from thaJeztah/info_dont_depend_on_IndexServerAddress
cli/command/system: prettyPrintServerInfo: don't depend on IndexServerAddress and credential-store
2 parents 73e1298 + da3871f commit 04bf047

1 file changed

Lines changed: 12 additions & 15 deletions

File tree

cli/command/system/info.go

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/docker/docker/api/types"
2020
"github.com/docker/docker/api/types/swarm"
2121
"github.com/docker/docker/api/types/versions"
22+
"github.com/docker/docker/registry"
2223
"github.com/docker/go-units"
2324
"github.com/spf13/cobra"
2425
)
@@ -41,6 +42,7 @@ type info struct {
4142
// object.
4243
*types.Info `json:",omitempty"`
4344
ServerErrors []string `json:",omitempty"`
45+
UserName string `json:"-"`
4446

4547
ClientInfo *clientInfo `json:",omitempty"`
4648
ClientErrors []string `json:",omitempty"`
@@ -112,6 +114,8 @@ func runInfo(cmd *cobra.Command, dockerCli command.Cli, opts *infoOptions) error
112114
}
113115

114116
if opts.format == "" {
117+
info.UserName = dockerCli.ConfigFile().AuthConfigs[registry.IndexServer].Username
118+
info.ClientInfo.APIVersion = dockerCli.CurrentVersion()
115119
return prettyPrintInfo(dockerCli, info)
116120
}
117121
return formatInfo(dockerCli, info, opts.format)
@@ -173,7 +177,7 @@ func prettyPrintInfo(dockerCli command.Cli, info info) error {
173177
fmt.Fprintln(dockerCli.Out())
174178
fmt.Fprintln(dockerCli.Out(), "Server:")
175179
if info.Info != nil {
176-
for _, err := range prettyPrintServerInfo(dockerCli, *info.Info) {
180+
for _, err := range prettyPrintServerInfo(dockerCli, &info) {
177181
info.ServerErrors = append(info.ServerErrors, err.Error())
178182
}
179183
}
@@ -211,7 +215,7 @@ func prettyPrintClientInfo(dockerCli command.Cli, info clientInfo) {
211215
}
212216

213217
//nolint:gocyclo
214-
func prettyPrintServerInfo(dockerCli command.Cli, info types.Info) []error {
218+
func prettyPrintServerInfo(dockerCli command.Cli, info *info) []error {
215219
var errs []error
216220

217221
fmt.Fprintln(dockerCli.Out(), " Containers:", info.Containers)
@@ -246,7 +250,7 @@ func prettyPrintServerInfo(dockerCli command.Cli, info types.Info) []error {
246250
fmt.Fprintln(dockerCli.Out(), " Log:", strings.Join(info.Plugins.Log, " "))
247251

248252
fmt.Fprintln(dockerCli.Out(), " Swarm:", info.Swarm.LocalNodeState)
249-
printSwarmInfo(dockerCli, info)
253+
printSwarmInfo(dockerCli, *info.Info)
250254

251255
if len(info.Runtimes) > 0 {
252256
fmt.Fprint(dockerCli.Out(), " Runtimes:")
@@ -318,14 +322,7 @@ func prettyPrintServerInfo(dockerCli command.Cli, info types.Info) []error {
318322
fprintlnNonEmpty(dockerCli.Out(), " HTTP Proxy:", info.HTTPProxy)
319323
fprintlnNonEmpty(dockerCli.Out(), " HTTPS Proxy:", info.HTTPSProxy)
320324
fprintlnNonEmpty(dockerCli.Out(), " No Proxy:", info.NoProxy)
321-
322-
if info.IndexServerAddress != "" {
323-
u := dockerCli.ConfigFile().AuthConfigs[info.IndexServerAddress].Username
324-
if len(u) > 0 {
325-
fmt.Fprintln(dockerCli.Out(), " Username:", u)
326-
}
327-
}
328-
325+
fprintlnNonEmpty(dockerCli.Out(), " Username:", info.UserName)
329326
if len(info.Labels) > 0 {
330327
fmt.Fprintln(dockerCli.Out(), " Labels:")
331328
for _, lbl := range info.Labels {
@@ -444,16 +441,16 @@ func printSwarmInfo(dockerCli command.Cli, info types.Info) {
444441
}
445442
}
446443

447-
func printServerWarnings(dockerCli command.Cli, info types.Info) {
448-
if versions.LessThan(dockerCli.Client().ClientVersion(), "1.42") {
449-
printSecurityOptionsWarnings(dockerCli, info)
444+
func printServerWarnings(dockerCli command.Cli, info *info) {
445+
if versions.LessThan(info.ClientInfo.APIVersion, "1.42") {
446+
printSecurityOptionsWarnings(dockerCli, *info.Info)
450447
}
451448
if len(info.Warnings) > 0 {
452449
fmt.Fprintln(dockerCli.Err(), strings.Join(info.Warnings, "\n"))
453450
return
454451
}
455452
// daemon didn't return warnings. Fallback to old behavior
456-
printServerWarningsLegacy(dockerCli, info)
453+
printServerWarningsLegacy(dockerCli, *info.Info)
457454
}
458455

459456
// printSecurityOptionsWarnings prints warnings based on the security options

0 commit comments

Comments
 (0)