Skip to content

Commit

Permalink
[7.15](backport #28277) Explicitly pass http config to doppler consum…
Browse files Browse the repository at this point in the history
…er (#28302)

Explicitly pass the TLS and proxy settings to doppler consumer, don't
rely on the type of the underlying transport.
Fixes issue initializing the client.

(cherry picked from commit 6a841cf)

Co-authored-by: Jaime Soriano Pastor <jaime.soriano@elastic.co>
  • Loading branch information
mergify[bot] and jsoriano authored Oct 8, 2021
1 parent fa436c8 commit fddc57f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Disable the option of running --machine-learning on its own. {pull}20241[20241]
- Fix PANW field spelling "veredict" to "verdict" on event.action {pull}18808[18808]
- Add support for GMT timezone offsets in `decode_cef`. {pull}20993[20993]
- Fix initialization of http client in Cloudfoundry input. {issue}28271[28271] {pull}28277[28277]

*Heartbeat*

Expand Down
12 changes: 4 additions & 8 deletions x-pack/libbeat/common/cloudfoundry/dopplerconsumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
package cloudfoundry

import (
"fmt"
"crypto/tls"
"net/http"
"net/url"
"regexp"
"sync"

Expand Down Expand Up @@ -37,13 +38,8 @@ type DopplerConsumer struct {
started bool
}

func newDopplerConsumer(address string, id string, log *logp.Logger, client *http.Client, tr *TokenRefresher, callbacks DopplerCallbacks) (*DopplerConsumer, error) {
transport, ok := client.Transport.(*http.Transport)
if !ok {
return nil, fmt.Errorf("expected http transport on client")
}

c := consumer.New(address, transport.TLSClientConfig, transport.Proxy)
func newDopplerConsumer(address string, id string, log *logp.Logger, tlsConfig *tls.Config, proxy func(*http.Request) (*url.URL, error), tr *TokenRefresher, callbacks DopplerCallbacks) (*DopplerConsumer, error) {
c := consumer.New(address, tlsConfig, proxy)
c.RefreshTokenFrom(tr)
c.SetDebugPrinter(newLogpDebugPrinter(log))

Expand Down
7 changes: 4 additions & 3 deletions x-pack/libbeat/common/cloudfoundry/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,14 @@ func (h *Hub) DopplerConsumerFromClient(client *cfclient.Client, callbacks Doppl
if dopplerAddress == "" {
dopplerAddress = client.Endpoint.DopplerEndpoint
}
httpClient, _, err := h.httpClient()
tlsConfig, err := tlscommon.LoadTLSConfig(h.cfg.Transport.TLS)
if err != nil {
return nil, errors.Wrap(err, "getting http client")
return nil, errors.Wrap(err, "loading tls config")
}
proxy := h.cfg.Transport.Proxy.ProxyFunc()

tr := TokenRefresherFromCfClient(client)
return newDopplerConsumer(dopplerAddress, h.cfg.ShardID, h.log, httpClient, tr, callbacks)
return newDopplerConsumer(dopplerAddress, h.cfg.ShardID, h.log, tlsConfig.ToConfig(), proxy, tr, callbacks)
}

// doerFromClient returns an auth token doer using uaa.
Expand Down

0 comments on commit fddc57f

Please sign in to comment.