mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
fix(bmc): check for default key
This commit is contained in:
parent
7bcd2f9462
commit
e4a521971a
1 changed files with 18 additions and 0 deletions
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue