Skip to content

Commit

Permalink
Compute entire API key auth header value up front
Browse files Browse the repository at this point in the history
  • Loading branch information
ycombinator committed Jun 5, 2020
1 parent 2eb7a5f commit 9982b8d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions libbeat/esleg/eslegclient/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ type Connection struct {
Encoder BodyEncoder
HTTP esHTTPClient

encodedAPIKey string // Base64-encoded API key
version common.Version
log *logp.Logger
apiKeyAuthHeader string // Authorization HTTP request header with base64-encoded API key
version common.Version
log *logp.Logger
}

// ConnectionSettings are the settings needed for a Connection
Expand Down Expand Up @@ -167,7 +167,7 @@ func NewConnection(s ConnectionSettings) (*Connection, error) {
}

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

return &conn, nil
Expand Down Expand Up @@ -443,8 +443,8 @@ func (conn *Connection) execHTTPRequest(req *http.Request) (int, []byte, error)
req.SetBasicAuth(conn.Username, conn.Password)
}

if conn.encodedAPIKey != "" {
req.Header.Add("Authorization", "ApiKey "+conn.encodedAPIKey)
if conn.apiKeyAuthHeader != "" {
req.Header.Add("Authorization", conn.apiKeyAuthHeader)
}

for name, value := range conn.Headers {
Expand Down

0 comments on commit 9982b8d

Please sign in to comment.