Skip to content

Commit

Permalink
Update TLS config for elasticsearch client
Browse files Browse the repository at this point in the history
Follow up on elastic/beats#15516 to pass TLS
options to forward proxies.
  • Loading branch information
simitt committed Feb 4, 2020
1 parent e8b39bb commit 5649271
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions elasticsearch/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,12 @@ func (h Hosts) Validate() error {
}

func connectionConfig(config *Config) (*http.Transport, []string, error) {
var dial, tlsDial transport.Dialer
var addrs []string
proxy, err := httpProxyURL(config)
if err == nil {
addrs, err = addresses(config)
}
if err == nil {
dial, tlsDial, err = dialer(config)
}
transport := &http.Transport{
Proxy: proxy,
Dial: dial.Dial,
DialTLS: tlsDial.Dial,
addrs, err := addresses(config)
if err != nil {
return nil, nil, err
}
return transport, addrs, err
transp, err := httpTransport(config)
return transp, addrs, err
}

func httpProxyURL(cfg *Config) (func(*http.Request) (*url.URL, error), error) {
Expand Down Expand Up @@ -122,16 +113,27 @@ func addresses(cfg *Config) ([]string, error) {
return addresses, nil
}

func dialer(cfg *Config) (transport.Dialer, transport.Dialer, error) {
func httpTransport(cfg *Config) (*http.Transport, error) {
proxy, err := httpProxyURL(cfg)
if err != nil {
return nil, err
}

var tlsConfig *tlscommon.TLSConfig
var err error
if cfg.TLS.IsEnabled() {
if tlsConfig, err = tlscommon.LoadTLSConfig(cfg.TLS); err != nil {
return nil, nil, err
return nil, err
}
}

dialer := transport.NetDialer(cfg.Timeout)
tlsDialer, err := transport.TLSDialer(dialer, tlsConfig, cfg.Timeout)
return dialer, tlsDialer, err
if err != nil {
return nil, err
}
return &http.Transport{
Proxy: proxy,
Dial: dialer.Dial,
DialTLS: tlsDialer.Dial,
TLSClientConfig: tlsConfig.ToConfig(),
}, nil
}

0 comments on commit 5649271

Please sign in to comment.