Skip to content

Commit 2d06cfc

Browse files
committed
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 <github@gone.nl>
1 parent 7d723e2 commit 2d06cfc

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

cli/command/cli.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,17 +260,15 @@ func NewAPIClientFromFlags(opts *cliflags.ClientOptions, configFile *configfile.
260260
}
261261

262262
func newAPIClientFromEndpoint(ep docker.Endpoint, configFile *configfile.ConfigFile) (client.APIClient, error) {
263-
clientOpts, err := ep.ClientOpts()
263+
opts, err := ep.ClientOpts()
264264
if err != nil {
265265
return nil, err
266266
}
267-
customHeaders := make(map[string]string, len(configFile.HTTPHeaders))
268-
for k, v := range configFile.HTTPHeaders {
269-
customHeaders[k] = v
267+
if len(configFile.HTTPHeaders) > 0 {
268+
opts = append(opts, client.WithHTTPHeaders(configFile.HTTPHeaders))
270269
}
271-
customHeaders["User-Agent"] = UserAgent()
272-
clientOpts = append(clientOpts, client.WithHTTPHeaders(customHeaders))
273-
return client.NewClientWithOpts(clientOpts...)
270+
opts = append(opts, client.WithUserAgent(UserAgent()))
271+
return client.NewClientWithOpts(opts...)
274272
}
275273

276274
func resolveDockerEndpoint(s store.Reader, contextName string) (docker.Endpoint, error) {

0 commit comments

Comments
 (0)