Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encode API key as base64 in common code #18945

Merged
merged 9 commits into from
Jun 9, 2020
Prev Previous commit
Next Next commit
Move encodedAPIKey field to Connection
  • Loading branch information
ycombinator committed Jun 5, 2020
commit 97806e077a0965bd6f65e328c21c60118166262a
21 changes: 11 additions & 10 deletions libbeat/esleg/eslegclient/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ type Connection struct {
Encoder BodyEncoder
HTTP esHTTPClient

version common.Version
log *logp.Logger
encodedAPIKey string // Base64-encoded API key
version common.Version
log *logp.Logger
}

// ConnectionSettings are the settings needed for a Connection
Expand All @@ -76,8 +77,6 @@ type ConnectionSettings struct {

Timeout time.Duration
IdleConnTimeout time.Duration

encodedAPIKey string // Base64-encoded API key
}

// NewConnection returns a new Elasticsearch client
Expand Down Expand Up @@ -160,16 +159,18 @@ func NewConnection(s ConnectionSettings) (*Connection, error) {
logp.Info("kerberos client created")
}

if s.APIKey != "" {
s.encodedAPIKey = base64.StdEncoding.EncodeToString([]byte(s.APIKey))
}

return &Connection{
conn := Connection{
ConnectionSettings: s,
HTTP: httpClient,
Encoder: encoder,
log: logp.NewLogger("esclientleg"),
}, nil
}

if s.APIKey != "" {
conn.encodedAPIKey = base64.StdEncoding.EncodeToString([]byte(s.APIKey))
}

return &conn, nil
}

func settingsWithDefaults(s ConnectionSettings) ConnectionSettings {
Expand Down