mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-10 11:41:21 +00:00
f3a7f399c0
* 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>
40 lines
734 B
Go
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
|
|
}
|
|
}
|