2022-02-03 03:46:27 +00:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-25 19:08:43 +00:00
|
|
|
// WithJWTSecret allows setting a JWT secret for authenticating
|
|
|
|
// the client via HTTP connections.
|
|
|
|
func WithJWTSecret(secret []byte) Option {
|
2022-02-03 03:46:27 +00:00
|
|
|
return func(c *Client) error {
|
2022-02-25 19:08:43 +00:00
|
|
|
if len(secret) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
authTransport := &jwtTransport{
|
|
|
|
underlyingTransport: http.DefaultTransport,
|
|
|
|
jwtSecret: secret,
|
|
|
|
}
|
|
|
|
c.cfg.httpClient = &http.Client{
|
|
|
|
Timeout: DefaultTimeout,
|
|
|
|
Transport: authTransport,
|
|
|
|
}
|
2022-02-03 03:46:27 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|