Merge pull request #4363 from thaJeztah/cleanup_useragent

cli/command: newAPIClientFromEndpoint: use WithUserAgent
This commit is contained in:
Sebastiaan van Stijn 2023-06-21 11:38:55 +02:00 committed by GitHub
commit 3c99d229d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 7 deletions

View File

@ -260,17 +260,15 @@ func NewAPIClientFromFlags(opts *cliflags.ClientOptions, configFile *configfile.
} }
func newAPIClientFromEndpoint(ep docker.Endpoint, configFile *configfile.ConfigFile) (client.APIClient, error) { func newAPIClientFromEndpoint(ep docker.Endpoint, configFile *configfile.ConfigFile) (client.APIClient, error) {
clientOpts, err := ep.ClientOpts() opts, err := ep.ClientOpts()
if err != nil { if err != nil {
return nil, err return nil, err
} }
customHeaders := make(map[string]string, len(configFile.HTTPHeaders)) if len(configFile.HTTPHeaders) > 0 {
for k, v := range configFile.HTTPHeaders { opts = append(opts, client.WithHTTPHeaders(configFile.HTTPHeaders))
customHeaders[k] = v
} }
customHeaders["User-Agent"] = UserAgent() opts = append(opts, client.WithUserAgent(UserAgent()))
clientOpts = append(clientOpts, client.WithHTTPHeaders(customHeaders)) return client.NewClientWithOpts(opts...)
return client.NewClientWithOpts(clientOpts...)
} }
func resolveDockerEndpoint(s store.Reader, contextName string) (docker.Endpoint, error) { func resolveDockerEndpoint(s store.Reader, contextName string) (docker.Endpoint, error) {