fix(bmc): check for default key

This commit is contained in:
Devon Bautista 2025-04-16 17:41:46 -06:00 committed by David Allen
parent 7bcd2f9462
commit e4a521971a
Signed by: towk
GPG key ID: 0430CDBE22619155

View file

@ -2,6 +2,7 @@ package bmc
import (
"encoding/json"
"fmt"
"github.com/OpenCHAMI/magellan/pkg/secrets"
"github.com/rs/zerolog/log"
@ -14,6 +15,23 @@ type BMCCredentials struct {
func GetBMCCredentials(store secrets.SecretStore, id string) (BMCCredentials, error) {
var creds BMCCredentials
if id == secrets.DEFAULT_KEY {
log.Info().Msg("fetching default credentials")
if uriCreds, err := store.GetSecretByID(id); err != nil {
log.Warn().Err(err).Msg("failed to get default credentials")
return creds, fmt.Errorf("get default credentials: %w", err)
} else {
if err := json.Unmarshal([]byte(uriCreds), &creds); err != nil {
log.Error().Err(err).Msg("failed to unmarshal default credentials")
return creds, fmt.Errorf("unmarshal default credentials: %w", err)
} else {
log.Info().Msg("default credentials found, using")
}
}
return creds, nil
}
if uriCreds, err := store.GetSecretByID(id); err != nil {
// Specific credentials for URI not found, fetch default.
log.Warn().Str("id", id).Msg("specific credentials not found, falling back to default")