From 71fde20e17ebcc6180d04e6cd44dd333ca437eaf Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 13 Apr 2023 23:10:53 +0200 Subject: [PATCH] cli/command/system: prettyPrintServerInfo: simplify username Starting with b4ca1c7368daeead400fcc1b8f2d61951a0d9d1e, docker login no longer depends on info.IndexServerAddress to determine the default registry. The prettyPrintServerInfo() still depended on this information, which could potentially show the wrong information. This patch changes it to also depend on the same information as docker login now does. Signed-off-by: Sebastiaan van Stijn --- cli/command/system/info.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/cli/command/system/info.go b/cli/command/system/info.go index 1d675c75f0..a8b4b95a24 100644 --- a/cli/command/system/info.go +++ b/cli/command/system/info.go @@ -19,6 +19,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/versions" + "github.com/docker/docker/registry" "github.com/docker/go-units" "github.com/spf13/cobra" ) @@ -319,12 +320,8 @@ func prettyPrintServerInfo(dockerCli command.Cli, info types.Info) []error { fprintlnNonEmpty(dockerCli.Out(), " HTTPS Proxy:", info.HTTPSProxy) fprintlnNonEmpty(dockerCli.Out(), " No Proxy:", info.NoProxy) - if info.IndexServerAddress != "" { - u := dockerCli.ConfigFile().AuthConfigs[info.IndexServerAddress].Username - if len(u) > 0 { - fmt.Fprintln(dockerCli.Out(), " Username:", u) - } - } + u := dockerCli.ConfigFile().AuthConfigs[registry.IndexServer].Username + fprintlnNonEmpty(dockerCli.Out(), " Username:", u) if len(info.Labels) > 0 { fmt.Fprintln(dockerCli.Out(), " Labels:")