chore: added pre-condition guards for secrets

This commit is contained in:
David Allen 2025-03-17 10:14:36 -06:00 committed by David Allen
parent cdf380bd64
commit 9396de11c2
Signed by: towk
GPG key ID: 0430CDBE22619155
2 changed files with 8 additions and 1 deletions

View file

@ -148,7 +148,6 @@ func CrawlBMCForSystems(config CrawlerConfig) ([]InventoryDetail, error) {
return walkSystems(rf_systems, nil, config.URI) return walkSystems(rf_systems, nil, config.URI)
} }
// CrawlBMCForSystems pulls BMC manager information.
// CrawlBMCForManagers connects to a BMC (Baseboard Management Controller) using the provided configuration, // CrawlBMCForManagers connects to a BMC (Baseboard Management Controller) using the provided configuration,
// retrieves the ServiceRoot, and then fetches the list of managers from the ServiceRoot. // retrieves the ServiceRoot, and then fetches the list of managers from the ServiceRoot.
// //
@ -374,6 +373,10 @@ func walkManagers(rf_managers []*redfish.Manager, baseURI string) ([]Manager, er
} }
func loadBMCCreds(config CrawlerConfig) (BMCUsernamePassword, error) { func loadBMCCreds(config CrawlerConfig) (BMCUsernamePassword, error) {
// NOTE: it is possible for the SecretStore to be nil, so we need a check
if config.CredentialStore == nil {
return BMCUsernamePassword{}, fmt.Errorf("credential store is invalid")
}
creds, err := config.CredentialStore.GetSecretByID(config.URI) creds, err := config.CredentialStore.GetSecretByID(config.URI)
if err != nil { if err != nil {
event := log.Error() event := log.Error()

View file

@ -104,6 +104,10 @@ func (l *LocalSecretStore) ListSecrets() (map[string]string, error) {
// openStore tries to create or open the LocalSecretStore based on the environment // openStore tries to create or open the LocalSecretStore based on the environment
// variable MASTER_KEY. If not found, it prints an error. // variable MASTER_KEY. If not found, it prints an error.
func OpenStore(filename string) (SecretStore, error) { func OpenStore(filename string) (SecretStore, error) {
if filename == "" {
return nil, fmt.Errorf("no path to secret store provided")
}
masterKey := os.Getenv("MASTER_KEY") masterKey := os.Getenv("MASTER_KEY")
if masterKey == "" { if masterKey == "" {
return nil, fmt.Errorf("MASTER_KEY environment variable not set") return nil, fmt.Errorf("MASTER_KEY environment variable not set")