Skip to content

Commit

Permalink
Parse elasticsearch URL before logging it (#3075)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewkroh authored and tsg committed Nov 30, 2016
1 parent c963ba0 commit 7d3adfe
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions libbeat/outputs/elasticsearch/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,23 @@ func NewClient(
pipeline = nil
}

u, err := url.Parse(s.URL)
if err != nil {
return nil, fmt.Errorf("failed to parse elasticsearch URL: %v", err)
}
if u.User != nil {
s.Username = u.User.Username()
s.Password, _ = u.User.Password()
u.User = nil

// Re-write URL without credentials.
s.URL = u.String()
}

logp.Info("Elasticsearch url: %s", s.URL)

// TODO: add socks5 proxy support
var dialer, tlsDialer transport.Dialer
var err error

dialer = transport.NetDialer(s.Timeout)
tlsDialer, err = transport.TLSDialer(dialer, s.TLS, s.Timeout)
Expand Down Expand Up @@ -142,19 +154,6 @@ func NewClient(
}
}

u, err := url.Parse(s.URL)
if err != nil {
return nil, fmt.Errorf("failed to parse elasticsearch URL: %v", err)
}
if u.User != nil {
s.Username = u.User.Username()
s.Password, _ = u.User.Password()
u.User = nil

// Re-write URL without credentials.
s.URL = u.String()
}

client := &Client{
Connection: Connection{
URL: s.URL,
Expand Down

0 comments on commit 7d3adfe

Please sign in to comment.