prysm-pulse/beacon-chain/powchain/engine-api-client/v1/options.go
Raul Jordan f3a7f399c0
Engine API Client Authentication for the Merge via HTTP (#10236)
* round tripper with claims

* auth

* edit auth

* test out jwt

* passing

* jwt flag

* comment

* passing

* commentary

* fix up jwt parsing

* gaz

* update jwt libs

* tidy

* gaz

* lint

* tidy up

* comment too long

Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com>
2022-02-25 19:08:43 +00:00

40 lines
734 B
Go

package v1
import (
"net/http"
)
// Option for configuring the engine API client.
type Option func(c *Client) error
type config struct {
httpClient *http.Client
}
func defaultConfig() *config {
return &config{
httpClient: &http.Client{
Timeout: DefaultTimeout,
},
}
}
// WithJWTSecret allows setting a JWT secret for authenticating
// the client via HTTP connections.
func WithJWTSecret(secret []byte) Option {
return func(c *Client) error {
if len(secret) == 0 {
return nil
}
authTransport := &jwtTransport{
underlyingTransport: http.DefaultTransport,
jwtSecret: secret,
}
c.cfg.httpClient = &http.Client{
Timeout: DefaultTimeout,
Transport: authTransport,
}
return nil
}
}