Skip to content

Commit

Permalink
cli/command: newAPIClientFromEndpoint: use WithUserAgent
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
thaJeztah committed Jun 20, 2023
1 parent 7d723e2 commit 2d06cfc
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions cli/command/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2d06cfc

Please sign in to comment.