Added temporary solution for creating new clients

This commit is contained in:
David Allen 2024-08-27 17:17:19 -06:00
parent 9991f02631
commit 874d750dde
No known key found for this signature in database
GPG key ID: 717C593FF60A2ACC

View file

@ -2,8 +2,12 @@
package magellan package magellan
import ( import (
"crypto/tls"
"crypto/x509"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net"
"net/http"
"os" "os"
"path" "path"
"sync" "sync"
@ -58,12 +62,32 @@ func CollectInventory(assets *[]RemoteAsset, params *CollectParams) error {
done = make(chan struct{}, params.Concurrency+1) done = make(chan struct{}, params.Concurrency+1)
chanAssets = make(chan RemoteAsset, params.Concurrency+1) chanAssets = make(chan RemoteAsset, params.Concurrency+1)
outputPath = path.Clean(params.OutputPath) outputPath = path.Clean(params.OutputPath)
smdClient = client.NewClient( smdClient = &client.SmdClient{Client: &http.Client{}}
client.WithSecureTLS[*client.SmdClient](params.CaCertPath),
)
) )
// 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 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) wg.Add(params.Concurrency)
for i := 0; i < params.Concurrency; i++ { for i := 0; i < params.Concurrency; i++ {
go func() { go func() {