diff --git a/pkg/client/client.go b/pkg/client/client.go index 0005254..06a2632 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -9,6 +9,8 @@ import ( "net/http" "os" "time" + + "github.com/rs/zerolog/log" ) type Option[T Client] func(client T) @@ -18,7 +20,7 @@ type Option[T Client] func(client T) // It also provides functions that work with `collect` data. type Client interface { Name() string - GetClient() *http.Client + GetInternalClient() *http.Client RootEndpoint(endpoint string) string // functions needed to make request @@ -36,11 +38,17 @@ func NewClient[T Client](opts ...func(T)) T { } func WithCertPool[T Client](certPool *x509.CertPool) func(T) { + // make sure we have a valid cert pool if certPool == nil { return func(client T) {} } return func(client T) { - client.GetClient().Transport = &http.Transport{ + // make sure that we can access the internal client + if client.GetInternalClient() == nil { + log.Warn().Msg("internal client is invalid") + return + } + client.GetInternalClient().Transport = &http.Transport{ TLSClientConfig: &tls.Config{ RootCAs: certPool, InsecureSkipVerify: true, diff --git a/pkg/client/smd.go b/pkg/client/smd.go index a118460..443d445 100644 --- a/pkg/client/smd.go +++ b/pkg/client/smd.go @@ -16,6 +16,10 @@ type SmdClient struct { Xname string } +func (c SmdClient) Init() { + c.Client = &http.Client{} +} + func (c SmdClient) Name() string { return "smd" }