From 43237b10406cf1712a8699dedfcc5d4c4d7c0b79 Mon Sep 17 00:00:00 2001 From: "James W. Brinkerhoff" Date: Mon, 28 Oct 2024 14:55:25 -0400 Subject: [PATCH] providers/supermicro/supermicro.go: Initialize sum 'client' during serviceclient init --- providers/supermicro/supermicro.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/providers/supermicro/supermicro.go b/providers/supermicro/supermicro.go index e7d224f0..7d6b44df 100644 --- a/providers/supermicro/supermicro.go +++ b/providers/supermicro/supermicro.go @@ -136,7 +136,7 @@ func NewClient(host, user, pass string, log logr.Logger, opts ...Option) *Client opt(defaultConfig) } - serviceClient := newBmcServiceClient( + serviceClient, err := newBmcServiceClient( host, defaultConfig.Port, user, @@ -144,6 +144,10 @@ func NewClient(host, user, pass string, log logr.Logger, opts ...Option) *Client httpclient.Build(defaultConfig.httpClientSetupFuncs...), ) + if err != nil { + return nil + } + return &Client{ serviceClient: serviceClient, log: log, @@ -443,12 +447,20 @@ type serviceClient struct { sum *sum.Sum } -func newBmcServiceClient(host, port, user, pass string, client *http.Client) *serviceClient { +func newBmcServiceClient(host, port, user, pass string, client *http.Client) (*serviceClient, error) { + sc := &serviceClient{host: host, port: port, user: user, pass: pass, client: client} + if !strings.HasPrefix(host, "https://") && !strings.HasPrefix(host, "http://") { - host = "https://" + host + sc.host = "https://" + host + } + + s, err := sum.New(host, user, pass) + if err != nil { + return nil, err } + sc.sum = s - return &serviceClient{host: host, port: port, user: user, pass: pass, client: client} + return sc, nil } func (c *serviceClient) setCsrfToken(t string) {