mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
Fixed panic when setting --cacert from invalid client
This commit is contained in:
parent
057ff7bdef
commit
3b297351ec
2 changed files with 14 additions and 2 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -16,6 +16,10 @@ type SmdClient struct {
|
|||
Xname string
|
||||
}
|
||||
|
||||
func (c SmdClient) Init() {
|
||||
c.Client = &http.Client{}
|
||||
}
|
||||
|
||||
func (c SmdClient) Name() string {
|
||||
return "smd"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue