From 9396de11c25ac2fc765f862de12ecc4219ca93ae Mon Sep 17 00:00:00 2001 From: "David J. Allen" Date: Mon, 17 Mar 2025 10:14:36 -0600 Subject: [PATCH] chore: added pre-condition guards for secrets --- pkg/crawler/main.go | 5 ++++- pkg/secrets/localstore.go | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/crawler/main.go b/pkg/crawler/main.go index ddf6357..bd29fcb 100644 --- a/pkg/crawler/main.go +++ b/pkg/crawler/main.go @@ -148,7 +148,6 @@ func CrawlBMCForSystems(config CrawlerConfig) ([]InventoryDetail, error) { return walkSystems(rf_systems, nil, config.URI) } -// CrawlBMCForSystems pulls BMC manager information. // 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. // @@ -374,6 +373,10 @@ func walkManagers(rf_managers []*redfish.Manager, baseURI string) ([]Manager, er } 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) if err != nil { event := log.Error() diff --git a/pkg/secrets/localstore.go b/pkg/secrets/localstore.go index 553a63a..1cf862a 100644 --- a/pkg/secrets/localstore.go +++ b/pkg/secrets/localstore.go @@ -104,6 +104,10 @@ func (l *LocalSecretStore) ListSecrets() (map[string]string, error) { // openStore tries to create or open the LocalSecretStore based on the environment // variable MASTER_KEY. If not found, it prints an error. func OpenStore(filename string) (SecretStore, error) { + if filename == "" { + return nil, fmt.Errorf("no path to secret store provided") + } + masterKey := os.Getenv("MASTER_KEY") if masterKey == "" { return nil, fmt.Errorf("MASTER_KEY environment variable not set")