fix: changed 'update' cmd to use gofish

This commit is contained in:
David Allen 2025-02-26 16:18:42 -07:00
parent 6d0811e86d
commit 5bbd0b8998
Signed by: towk
GPG key ID: 793B2924A49B3A3F
2 changed files with 11 additions and 7 deletions

View file

@ -55,7 +55,7 @@ var CollectCmd = &cobra.Command{
if concurrency <= 0 { if concurrency <= 0 {
concurrency = mathutil.Clamp(len(scannedResults), 1, 10000) concurrency = mathutil.Clamp(len(scannedResults), 1, 10000)
} }
err = magellan.CollectInventory(&scannedResults, &magellan.CollectParams{ _, err = magellan.CollectInventory(&scannedResults, &magellan.CollectParams{
URI: host, URI: host,
Username: username, Username: username,
Password: password, Password: password,

View file

@ -10,8 +10,8 @@ import (
"net/http" "net/http"
"os" "os"
"path" "path"
"strings"
"path/filepath" "path/filepath"
"strings"
"sync" "sync"
"time" "time"
@ -48,19 +48,20 @@ type CollectParams struct {
// //
// Requests can be made to several of the nodes using a goroutine by setting the q.Concurrency // Requests can be made to several of the nodes using a goroutine by setting the q.Concurrency
// property value between 1 and 10000. // property value between 1 and 10000.
func CollectInventory(assets *[]RemoteAsset, params *CollectParams) error { func CollectInventory(assets *[]RemoteAsset, params *CollectParams) ([]map[string]any, error) {
// check for available remote assets found from scan // check for available remote assets found from scan
if assets == nil { if assets == nil {
return fmt.Errorf("no assets found") return nil, fmt.Errorf("no assets found")
} }
if len(*assets) <= 0 { if len(*assets) <= 0 {
return fmt.Errorf("no assets found") return nil, fmt.Errorf("no assets found")
} }
// collect bmc information asynchronously // collect bmc information asynchronously
var ( var (
offset = 0 offset = 0
wg sync.WaitGroup wg sync.WaitGroup
collection = make([]map[string]any, 0)
found = make([]string, 0, len(*assets)) found = make([]string, 0, len(*assets))
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)
@ -73,7 +74,7 @@ func CollectInventory(assets *[]RemoteAsset, params *CollectParams) error {
if params.CaCertPath != "" { if params.CaCertPath != "" {
cacert, err := os.ReadFile(params.CaCertPath) cacert, err := os.ReadFile(params.CaCertPath)
if err != nil { if err != nil {
return fmt.Errorf("failed to read CA cert path: %w", err) return nil, fmt.Errorf("failed to read CA cert path: %w", err)
} }
certPool := x509.NewCertPool() certPool := x509.NewCertPool()
certPool.AppendCertsFromPEM(cacert) certPool.AppendCertsFromPEM(cacert)
@ -169,6 +170,9 @@ func CollectInventory(assets *[]RemoteAsset, params *CollectParams) error {
fmt.Printf("%v\n", string(body)) fmt.Printf("%v\n", string(body))
} }
// add data output to collections
collection = append(collection, data)
// write JSON data to file if output path is set using hive partitioning strategy // write JSON data to file if output path is set using hive partitioning strategy
if outputPath != "" { if outputPath != "" {
var ( var (
@ -241,7 +245,7 @@ func CollectInventory(assets *[]RemoteAsset, params *CollectParams) error {
wg.Wait() wg.Wait()
close(done) close(done)
return nil return collection, nil
} }
// FindMACAddressWithIP() returns the MAC address of an ethernet interface with // FindMACAddressWithIP() returns the MAC address of an ethernet interface with