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
9c8ea2575a
commit
b50b31ff40
1 changed files with 18 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ package bmc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/OpenCHAMI/magellan/pkg/secrets"
|
"github.com/OpenCHAMI/magellan/pkg/secrets"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
|
@ -14,6 +15,23 @@ type BMCCredentials struct {
|
||||||
|
|
||||||
func GetBMCCredentials(store secrets.SecretStore, id string) (BMCCredentials, error) {
|
func GetBMCCredentials(store secrets.SecretStore, id string) (BMCCredentials, error) {
|
||||||
var creds BMCCredentials
|
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 {
|
if uriCreds, err := store.GetSecretByID(id); err != nil {
|
||||||
// Specific credentials for URI not found, fetch default.
|
// Specific credentials for URI not found, fetch default.
|
||||||
log.Warn().Str("id", id).Msg("specific credentials not found, falling back to 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