Skip to content

Commit

Permalink
Fixed panic when setting --cacert from invalid client
Browse files Browse the repository at this point in the history
  • Loading branch information
davidallendj committed Aug 27, 2024
1 parent 057ff7b commit 3b29735
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"net/http"
"os"
"time"

"github.com/rs/zerolog/log"
)

type Option[T Client] func(client T)
Expand All @@ -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
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions pkg/client/smd.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ type SmdClient struct {
Xname string
}

func (c SmdClient) Init() {
c.Client = &http.Client{}
}

func (c SmdClient) Name() string {
return "smd"
}
Expand Down

0 comments on commit 3b29735

Please sign in to comment.