mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix TLS from environment variables in client
A recent change accidently caused any TLS configuration in FromEnv to be ignored. This change alters WithHost to create a new http client only if one doesn't already exist, and otherwise applies the logic to the transport on the existing client. This preserves the TLS configuration that might already be on the client. Signed-off-by: Drew Erny <drew.erny@docker.com>
This commit is contained in:
parent
2d97f5e780
commit
80904e9571
1 changed files with 14 additions and 15 deletions
|
@ -133,23 +133,15 @@ func FromEnv(c *Client) error {
|
|||
},
|
||||
CheckRedirect: CheckRedirect,
|
||||
}
|
||||
WithHTTPClient(httpClient)(c)
|
||||
}
|
||||
|
||||
host := os.Getenv("DOCKER_HOST")
|
||||
if host != "" {
|
||||
var err error
|
||||
// WithHost will create an API client if it doesn't exist
|
||||
if err := WithHost(host)(c); err != nil {
|
||||
return err
|
||||
}
|
||||
httpClient, err = defaultHTTPClient(host)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if httpClient != nil {
|
||||
if err := WithHTTPClient(httpClient)(c); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
version := os.Getenv("DOCKER_API_VERSION")
|
||||
if version != "" {
|
||||
|
@ -167,7 +159,8 @@ func WithVersion(version string) func(*Client) error {
|
|||
}
|
||||
}
|
||||
|
||||
// WithHost overrides the client host with the specified one
|
||||
// WithHost overrides the client host with the specified one, creating a new
|
||||
// http client if one doesn't exist
|
||||
func WithHost(host string) func(*Client) error {
|
||||
return func(c *Client) error {
|
||||
hostURL, err := ParseHostURL(host)
|
||||
|
@ -178,11 +171,17 @@ func WithHost(host string) func(*Client) error {
|
|||
c.proto = hostURL.Scheme
|
||||
c.addr = hostURL.Host
|
||||
c.basePath = hostURL.Path
|
||||
client, err := defaultHTTPClient(host)
|
||||
if err != nil {
|
||||
return err
|
||||
if c.client == nil {
|
||||
client, err := defaultHTTPClient(host)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return WithHTTPClient(client)(c)
|
||||
}
|
||||
return WithHTTPClient(client)(c)
|
||||
if transport, ok := c.client.Transport.(*http.Transport); ok {
|
||||
return sockets.ConfigureTransport(transport, c.proto, c.addr)
|
||||
}
|
||||
return fmt.Errorf("cannot apply host to http transport")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue