From a75530e96bf0bdcf72bad3019e5c72d48fced9bc Mon Sep 17 00:00:00 2001 From: "David J. Allen" Date: Wed, 8 May 2024 14:46:29 -0600 Subject: [PATCH] Fixed TLS errors in collect --- internal/collect.go | 2 +- internal/util/util.go | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/internal/collect.go b/internal/collect.go index 41f3cdc..d97b6e6 100644 --- a/internal/collect.go +++ b/internal/collect.go @@ -529,7 +529,7 @@ func makeGofishConfig(q *QueryParams) (gofish.ClientConfig, error) { Endpoint: url, Username: q.User, Password: q.Pass, - Insecure: q.CaCertPath == "", + Insecure: true, TLSHandshakeTimeout: q.Timeout, HTTPClient: client, // MaxConcurrentRequests: int64(q.Threads), // NOTE: this was added in latest version of gofish diff --git a/internal/util/util.go b/internal/util/util.go index 4aebca2..f385746 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -45,11 +45,13 @@ func MakeRequest(client *http.Client, url string, httpMethod string, body []byte // use defaults if no client provided if client == nil { client = http.DefaultClient - http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} + client.Transport = &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + } } req, err := http.NewRequest(httpMethod, url, bytes.NewBuffer(body)) if err != nil { - return nil, nil, fmt.Errorf("failed tocreate new HTTP request: %v", err) + return nil, nil, fmt.Errorf("failed to create new HTTP request: %v", err) } req.Header.Add("User-Agent", "magellan") for k, v := range headers { @@ -57,12 +59,12 @@ func MakeRequest(client *http.Client, url string, httpMethod string, body []byte } res, err := client.Do(req) if err != nil { - return nil, nil, fmt.Errorf("failed tomake request: %v", err) + return nil, nil, fmt.Errorf("failed to make request: %v", err) } b, err := io.ReadAll(res.Body) res.Body.Close() if err != nil { - return nil, nil, fmt.Errorf("failed toread response body: %v", err) + return nil, nil, fmt.Errorf("failed to read response body: %v", err) } return res, b, err } @@ -76,7 +78,7 @@ func MakeOutputDirectory(path string) (string, error) { // check if path is valid and directory pathExists, err := PathExists(final) if err != nil { - return final, fmt.Errorf("failed tocheck for existing path: %v", err) + return final, fmt.Errorf("failed to check for existing path: %v", err) } if pathExists { // make sure it is directory with 0o644 permissions @@ -86,7 +88,7 @@ func MakeOutputDirectory(path string) (string, error) { // create directory with data + time err = os.MkdirAll(final, 0766) if err != nil { - return final, fmt.Errorf("failed tomake directory: %v", err) + return final, fmt.Errorf("failed to make directory: %v", err) } return final, nil }