From 874d750ddef233367203381ee5359c5e786c0cd2 Mon Sep 17 00:00:00 2001 From: David Allen Date: Tue, 27 Aug 2024 17:17:19 -0600 Subject: [PATCH] Added temporary solution for creating new clients --- internal/collect.go | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/internal/collect.go b/internal/collect.go index 49cb449..8c03050 100644 --- a/internal/collect.go +++ b/internal/collect.go @@ -2,8 +2,12 @@ package magellan import ( + "crypto/tls" + "crypto/x509" "encoding/json" "fmt" + "net" + "net/http" "os" "path" "sync" @@ -58,12 +62,32 @@ func CollectInventory(assets *[]RemoteAsset, params *CollectParams) error { done = make(chan struct{}, params.Concurrency+1) chanAssets = make(chan RemoteAsset, params.Concurrency+1) outputPath = path.Clean(params.OutputPath) - smdClient = client.NewClient( - client.WithSecureTLS[*client.SmdClient](params.CaCertPath), - ) + smdClient = &client.SmdClient{Client: &http.Client{}} ) - // set the client's host from the CLI param + // set the client's params from CLI + // NOTE: temporary solution until client.NewClient() is fixed smdClient.URI = params.URI + if params.CaCertPath != "" { + cacert, err := os.ReadFile(params.CaCertPath) + if err != nil { + return fmt.Errorf("failed to read CA cert path: %w", err) + } + certPool := x509.NewCertPool() + certPool.AppendCertsFromPEM(cacert) + smdClient.Client.Transport = &http.Transport{ + TLSClientConfig: &tls.Config{ + RootCAs: certPool, + InsecureSkipVerify: true, + }, + DisableKeepAlives: true, + Dial: (&net.Dialer{ + Timeout: 120 * time.Second, + KeepAlive: 120 * time.Second, + }).Dial, + TLSHandshakeTimeout: 120 * time.Second, + ResponseHeaderTimeout: 120 * time.Second, + } + } wg.Add(params.Concurrency) for i := 0; i < params.Concurrency; i++ { go func() {