From 8e59885f556800f335bdea54d95674c44a3b54ed Mon Sep 17 00:00:00 2001 From: David Allen Date: Fri, 9 Aug 2024 07:58:42 -0600 Subject: [PATCH] Minor changes and improvements --- internal/cache/sqlite/sqlite.go | 10 ++++++++++ internal/collect.go | 9 +++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/internal/cache/sqlite/sqlite.go b/internal/cache/sqlite/sqlite.go index 7f0bbf5..74abe88 100644 --- a/internal/cache/sqlite/sqlite.go +++ b/internal/cache/sqlite/sqlite.go @@ -4,6 +4,7 @@ import ( "fmt" magellan "github.com/OpenCHAMI/magellan/internal" + "github.com/OpenCHAMI/magellan/internal/util" "github.com/jmoiron/sqlx" ) @@ -83,6 +84,15 @@ func DeleteScannedAssets(path string, results ...magellan.ScannedAsset) error { } func GetScannedAssets(path string) ([]magellan.ScannedAsset, error) { + // check if path exists first to prevent creating the database + exists, err := util.PathExists(path) + if !exists { + return nil, fmt.Errorf("no file found") + } else if err != nil { + return nil, err + } + + // now check if the file is the SQLite database db, err := sqlx.Open("sqlite3", path) if err != nil { return nil, fmt.Errorf("failed to open database: %v", err) diff --git a/internal/collect.go b/internal/collect.go index 88cde9c..8809591 100644 --- a/internal/collect.go +++ b/internal/collect.go @@ -65,8 +65,8 @@ func CollectInventory(scannedResults *[]ScannedAsset, params *CollectParams) err done = make(chan struct{}, params.Concurrency+1) chanScannedResult = make(chan ScannedAsset, params.Concurrency+1) outputPath = path.Clean(params.OutputPath) - smdClient = client.NewClient( - client.WithSecureTLS(params.CaCertPath), + smdClient = client.NewClient[client.SmdClient]( + client.WithSecureTLS[client.SmdClient](params.CaCertPath), ) ) wg.Add(params.Concurrency) @@ -152,13 +152,14 @@ func CollectInventory(scannedResults *[]ScannedAsset, params *CollectParams) err } // add all endpoints to smd - err = smdClient.AddRedfishEndpoint(data, headers) + err = smdClient.Add(body, headers) if err != nil { log.Error().Err(err).Msgf("failed to add Redfish endpoint") // try updating instead if params.ForceUpdate { - err = smdClient.UpdateRedfishEndpoint(data["ID"].(string), body, headers) + smdClient.Xname = data["ID"].(string) + err = smdClient.Update(body, headers) if err != nil { log.Error().Err(err).Msgf("failed to update Redfish endpoint") }