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

User supplied http client in RPC provider: #355

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@
func (c *Client) registerRPCProvider() error {
driverRPC := rpc.New(c.providerConfig.rpc.ConsumerURL, c.Auth.Host, c.providerConfig.rpc.Opts.HMAC.Secrets)
c.providerConfig.rpc.Logger = c.Logger
httpClient := *c.httpClient
httpClient.Transport = c.httpClient.Transport.(*http.Transport).Clone()
c.providerConfig.rpc.HTTPClient = &httpClient

Check warning on line 142 in client.go

View check run for this annotation

Codecov / codecov/patch

client.go#L140-L142

Added lines #L140 - L142 were not covered by tests
if err := mergo.Merge(driverRPC, c.providerConfig.rpc, mergo.WithOverride, mergo.WithTransformers(&rpc.Provider{})); err != nil {
return fmt.Errorf("failed to merge user specified rpc config with the config defaults, rpc provider not available: %w", err)
}
Expand Down
9 changes: 5 additions & 4 deletions providers/rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"strings"
"time"

"github.com/bmc-toolbox/bmclib/v2/internal/httpclient"
"github.com/bmc-toolbox/bmclib/v2/providers"
"github.com/go-logr/logr"
"github.com/jacobweinstock/registrar"
Expand Down Expand Up @@ -64,8 +65,8 @@ type Provider struct {
ConsumerURL string
// Host is the BMC ip address or hostname or identifier.
Host string
// Client is the http client used for all HTTP calls.
Client *http.Client
// HTTPClient is the http client used for all HTTP calls.
HTTPClient *http.Client
// Logger is the logger to use for logging.
Logger logr.Logger
// LogNotificationsDisabled determines whether responses from rpc consumer/listeners will be logged or not.
Expand Down Expand Up @@ -136,7 +137,7 @@ func New(consumerURL string, host string, secrets Secrets) *Provider {
c := &Provider{
Host: host,
ConsumerURL: consumerURL,
Client: http.DefaultClient,
HTTPClient: httpclient.Build(),
Logger: logr.Discard(),
Opts: Opts{
Request: RequestOpts{
Expand Down Expand Up @@ -325,7 +326,7 @@ func (p *Provider) process(ctx context.Context, rp RequestPayload) (ResponsePayl
kvs = append(kvs, []interface{}{"params", rp.Params}...)
}

resp, err := p.Client.Do(req)
resp, err := p.HTTPClient.Do(req)
if err != nil {
p.Logger.Error(err, "failed to send rpc notification", kvs...)
return ResponsePayload{}, err
Expand Down