From 9991f02631a493ae91f153c5ee1bdd0100cfe904 Mon Sep 17 00:00:00 2001 From: David Allen Date: Tue, 27 Aug 2024 15:55:16 -0600 Subject: [PATCH] Updated warning message and changed SMD client to use pointer receivers --- internal/collect.go | 2 +- pkg/client/client.go | 6 +++--- pkg/client/smd.go | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/collect.go b/internal/collect.go index ea7ca69..49cb449 100644 --- a/internal/collect.go +++ b/internal/collect.go @@ -59,7 +59,7 @@ func CollectInventory(assets *[]RemoteAsset, params *CollectParams) error { chanAssets = make(chan RemoteAsset, params.Concurrency+1) outputPath = path.Clean(params.OutputPath) smdClient = client.NewClient( - client.WithSecureTLS[client.SmdClient](params.CaCertPath), + client.WithSecureTLS[*client.SmdClient](params.CaCertPath), ) ) // set the client's host from the CLI param diff --git a/pkg/client/client.go b/pkg/client/client.go index 5952523..eda049b 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -13,7 +13,7 @@ import ( "github.com/rs/zerolog/log" ) -type Option[T Client] func(client T) +type Option[T Client] func(client *T) // The 'Client' struct is a wrapper around the default http.Client // that provides an extended API to work with functional options. @@ -21,8 +21,8 @@ type Option[T Client] func(client T) type Client interface { Init() Name() string - GetInternalClient() *http.Client RootEndpoint(endpoint string) string + GetInternalClient() *http.Client // functions needed to make request Add(data HTTPBody, headers HTTPHeader) error @@ -46,7 +46,7 @@ func WithCertPool[T Client](certPool *x509.CertPool) func(T) { return func(client T) { // make sure that we can access the internal client if client.GetInternalClient() == nil { - log.Warn().Msg("internal client is invalid") + log.Warn().Any("client", client.GetInternalClient()).Msg("invalid internal HTTP client ()") return } client.GetInternalClient().Transport = &http.Transport{ diff --git a/pkg/client/smd.go b/pkg/client/smd.go index 520520f..499a72c 100644 --- a/pkg/client/smd.go +++ b/pkg/client/smd.go @@ -16,26 +16,26 @@ type SmdClient struct { Xname string } -func (c SmdClient) Init() { +func (c *SmdClient) Init() { c.Client = &http.Client{} } -func (c SmdClient) Name() string { +func (c *SmdClient) Name() string { return "smd" } -func (c SmdClient) RootEndpoint(endpoint string) string { +func (c *SmdClient) RootEndpoint(endpoint string) string { return fmt.Sprintf("%s/hsm/v2%s", c.URI, endpoint) } -func (c SmdClient) GetInternalClient() *http.Client { +func (c *SmdClient) GetInternalClient() *http.Client { return c.Client } // Add() has a similar function definition to that of the default implementation, // but also allows further customization and data/header manipulation that would // be specific and/or unique to SMD's API. -func (c SmdClient) Add(data HTTPBody, headers HTTPHeader) error { +func (c *SmdClient) Add(data HTTPBody, headers HTTPHeader) error { if data == nil { return fmt.Errorf("failed to add redfish endpoint: no data found") } @@ -57,7 +57,7 @@ func (c SmdClient) Add(data HTTPBody, headers HTTPHeader) error { return err } -func (c SmdClient) Update(data HTTPBody, headers HTTPHeader) error { +func (c *SmdClient) Update(data HTTPBody, headers HTTPHeader) error { if data == nil { return fmt.Errorf("failed to add redfish endpoint: no data found") }