Skip to content

Commit d9c95c9

Browse files
committed
cli/context/docker: Endpoint.ClientOpts: inline withHTTPClient
Inline the wrapper "option", as the signature for ClientOpts may not be implementable in future (possibly we need to change this); docker#18 16.94 # github.com/docker/cli/cli/context/docker docker#18 16.94 cli/context/docker/load.go:105:29: cannot use withHTTPClient(tlsConfig) (value of type func(*client.Client) error) as client.Opt value in argument to append docker#18 16.94 cli/context/docker/load.go:152:6: cannot use c (variable of type *client.Client) as *client.clientConfig value in argument to client.WithHTTPClient(&http.Client{…}) Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 27b316f commit d9c95c9

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

cli/context/docker/load.go

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,22 @@ func (ep *Endpoint) ClientOpts() ([]client.Opt, error) {
102102
if err != nil {
103103
return nil, err
104104
}
105-
result = append(result, withHTTPClient(tlsConfig))
105+
106+
// If there's no tlsConfig available, we use the default HTTPClient.
107+
if tlsConfig != nil {
108+
result = append(result,
109+
client.WithHTTPClient(&http.Client{
110+
Transport: &http.Transport{
111+
TLSClientConfig: tlsConfig,
112+
DialContext: (&net.Dialer{
113+
KeepAlive: 30 * time.Second,
114+
Timeout: 30 * time.Second,
115+
}).DialContext,
116+
},
117+
CheckRedirect: client.CheckRedirect,
118+
}),
119+
)
120+
}
106121
}
107122
result = append(result, client.WithHost(ep.Host))
108123
} else {
@@ -134,25 +149,6 @@ func isSocket(addr string) bool {
134149
}
135150
}
136151

137-
func withHTTPClient(tlsConfig *tls.Config) func(*client.Client) error {
138-
return func(c *client.Client) error {
139-
if tlsConfig == nil {
140-
// Use the default HTTPClient
141-
return nil
142-
}
143-
return client.WithHTTPClient(&http.Client{
144-
Transport: &http.Transport{
145-
TLSClientConfig: tlsConfig,
146-
DialContext: (&net.Dialer{
147-
KeepAlive: 30 * time.Second,
148-
Timeout: 30 * time.Second,
149-
}).DialContext,
150-
},
151-
CheckRedirect: client.CheckRedirect,
152-
})(c)
153-
}
154-
}
155-
156152
// EndpointFromContext parses a context docker endpoint metadata into a typed EndpointMeta structure
157153
func EndpointFromContext(metadata store.Metadata) (EndpointMeta, error) {
158154
ep, ok := metadata.Endpoints[DockerEndpoint]

0 commit comments

Comments
 (0)