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

@ -69,7 +69,6 @@ func CollectInventory(assets *[]RemoteAsset, params *CollectParams, store secret
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,23 +118,9 @@ 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 (
fallbackStore = secrets.NewStaticStore(params.Username, params.Password)
systems []crawler.InventoryDetail systems []crawler.InventoryDetail
managers []crawler.Manager managers []crawler.Manager
config = crawler.CrawlerConfig{ config = crawler.CrawlerConfig{
@ -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 {