Fixed panic when setting --cacert from invalid client

This commit is contained in:
David Allen 2024-08-27 14:30:03 -06:00
parent 057ff7bdef
commit 3b297351ec
No known key found for this signature in database
GPG key ID: 717C593FF60A2ACC
2 changed files with 14 additions and 2 deletions

View file

@ -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,

View file

@ -16,6 +16,10 @@ type SmdClient struct {
Xname string
}
func (c SmdClient) Init() {
c.Client = &http.Client{}
}
func (c SmdClient) Name() string {
return "smd"
}