fix: collect not falling back to CLI args correctly

This commit is contained in:
David Allen 2025-03-25 09:53:58 -06:00
parent c88a29be00
commit d4d0bc8a2c
Signed by: towk
GPG key ID: 0430CDBE22619155

View file

@ -61,15 +61,14 @@ func CollectInventory(assets *[]RemoteAsset, params *CollectParams, store secret
// 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) 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)
outputPath = path.Clean(params.OutputPath) outputPath = path.Clean(params.OutputPath)
smdClient = &client.SmdClient{Client: &http.Client{}} smdClient = &client.SmdClient{Client: &http.Client{}}
initialStore secrets.SecretStore = store
) )
// set the client's params from CLI // set the client's params from CLI
@ -106,9 +105,6 @@ func CollectInventory(assets *[]RemoteAsset, params *CollectParams, store secret
return return
} }
// use initial store to check for creds for specific node
store = initialStore
// generate custom xnames for bmcs // generate custom xnames for bmcs
// TODO: add xname customization via CLI // TODO: add xname customization via CLI
var ( var (
@ -122,26 +118,12 @@ func CollectInventory(assets *[]RemoteAsset, params *CollectParams, store secret
) )
offset += 1 offset += 1
// determine if local store exists and has credentials for
// the provided secretID...
// if it does not, create a static store and use the username
// and password provided instead
if store != nil {
_, err := store.GetSecretByID(uri)
if err != nil {
log.Warn().Err(err).Msgf("could not retrieve secrets for %s...falling back to default provided credentials", uri)
store = secrets.NewStaticStore(params.Username, params.Password)
}
} else {
log.Warn().Msgf("invalid store...falling back to default provided credentials for %s", uri)
store = secrets.NewStaticStore(params.Username, params.Password)
}
// crawl BMC node to fetch inventory data via Redfish // crawl BMC node to fetch inventory data via Redfish
var ( var (
systems []crawler.InventoryDetail fallbackStore = secrets.NewStaticStore(params.Username, params.Password)
managers []crawler.Manager systems []crawler.InventoryDetail
config = crawler.CrawlerConfig{ managers []crawler.Manager
config = crawler.CrawlerConfig{
URI: uri, URI: uri,
CredentialStore: store, CredentialStore: store,
Insecure: true, Insecure: true,
@ -149,6 +131,21 @@ func CollectInventory(assets *[]RemoteAsset, params *CollectParams, store secret
err error err error
) )
// determine if local store exists and has credentials for
// the provided secretID...
// if it does not, use the fallback static store instead with
// the username and password provided as arguments
if store != nil {
_, err := store.GetSecretByID(uri)
if err != nil {
log.Warn().Err(err).Msgf("could not retrieve secrets for %s...falling back to default provided credentials", uri)
config.CredentialStore = fallbackStore
}
} else {
log.Warn().Msgf("invalid store...falling back to default provided credentials for %s", uri)
config.CredentialStore = fallbackStore
}
// crawl for node and BMC information // crawl for node and BMC information
systems, err = crawler.CrawlBMCForSystems(config) systems, err = crawler.CrawlBMCForSystems(config)
if err != nil { if err != nil {