ClientOpts returns a slice of Client options to configure an API client with this endpoint
()
| 85 | |
| 86 | // ClientOpts returns a slice of Client options to configure an API client with this endpoint |
| 87 | func (ep *Endpoint) ClientOpts() ([]client.Opt, error) { |
| 88 | var result []client.Opt |
| 89 | if ep.Host != "" { |
| 90 | helper, err := connhelper.GetConnectionHelper(ep.Host) |
| 91 | if err != nil { |
| 92 | return nil, err |
| 93 | } |
| 94 | if helper == nil { |
| 95 | // Check if we're connecting over a socket, because there's no |
| 96 | // need to configure TLS for a socket connection. |
| 97 | // |
| 98 | // TODO(thaJeztah); make resolveDockerEndpoint and resolveDefaultDockerEndpoint not load TLS data, |
| 99 | // and load TLS files lazily; see https://github.com/docker/cli/pull/1581 |
| 100 | if !isSocket(ep.Host) { |
| 101 | tlsConfig, err := ep.tlsConfig() |
| 102 | if err != nil { |
| 103 | return nil, err |
| 104 | } |
| 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 | } |
| 121 | } |
| 122 | result = append(result, client.WithHost(ep.Host)) |
| 123 | } else { |
| 124 | result = append(result, |
| 125 | client.WithHTTPClient(&http.Client{ |
| 126 | // No TLS, and no proxy. |
| 127 | Transport: &http.Transport{ |
| 128 | DialContext: helper.Dialer, |
| 129 | }, |
| 130 | }), |
| 131 | client.WithHost(helper.Host), |
| 132 | client.WithDialContext(helper.Dialer), |
| 133 | ) |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | result = append(result, client.WithAPIVersionFromEnv()) |
| 138 | return result, nil |
| 139 | } |
| 140 | |
| 141 | // isSocket checks if the given address is a Unix-socket (linux), |
| 142 | // named pipe (Windows), or file-descriptor. |
no test coverage detected