From 2d06cfcde645d52f6e1acdabe56046b5b4f31fac Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 12 Jun 2023 12:39:05 +0200 Subject: [PATCH] cli/command: newAPIClientFromEndpoint: use WithUserAgent More things to be done after this, to allow passing a custom user-agent, but let's start with just using this utility. Signed-off-by: Sebastiaan van Stijn --- cli/command/cli.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/cli/command/cli.go b/cli/command/cli.go index 29a109af9e..a000bcc246 100644 --- a/cli/command/cli.go +++ b/cli/command/cli.go @@ -260,17 +260,15 @@ func NewAPIClientFromFlags(opts *cliflags.ClientOptions, configFile *configfile. } func newAPIClientFromEndpoint(ep docker.Endpoint, configFile *configfile.ConfigFile) (client.APIClient, error) { - clientOpts, err := ep.ClientOpts() + opts, err := ep.ClientOpts() if err != nil { return nil, err } - customHeaders := make(map[string]string, len(configFile.HTTPHeaders)) - for k, v := range configFile.HTTPHeaders { - customHeaders[k] = v + if len(configFile.HTTPHeaders) > 0 { + opts = append(opts, client.WithHTTPHeaders(configFile.HTTPHeaders)) } - customHeaders["User-Agent"] = UserAgent() - clientOpts = append(clientOpts, client.WithHTTPHeaders(customHeaders)) - return client.NewClientWithOpts(clientOpts...) + opts = append(opts, client.WithUserAgent(UserAgent())) + return client.NewClientWithOpts(opts...) } func resolveDockerEndpoint(s store.Reader, contextName string) (docker.Endpoint, error) {