mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 11:37:01 -07:00
chore: made changes to build and fix issues
This commit is contained in:
parent
9f80d746c7
commit
1410e53849
6 changed files with 91 additions and 44 deletions
47
internal/util/bmc.go
Normal file
47
internal/util/bmc.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"github.com/davidallendj/magellan/pkg/bmc"
|
||||
"github.com/davidallendj/magellan/pkg/secrets"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func GetBMCCredentials(store secrets.SecretStore, id string) bmc.BMCCredentials {
|
||||
var (
|
||||
creds bmc.BMCCredentials
|
||||
err error
|
||||
)
|
||||
|
||||
if id == "" {
|
||||
log.Error().Msg("failed to get BMC credentials: id was empty")
|
||||
return creds
|
||||
}
|
||||
|
||||
if id == secrets.DEFAULT_KEY {
|
||||
log.Info().Msg("fetching default credentials")
|
||||
if creds, err = bmc.GetBMCCredentialsDefault(store); err != nil {
|
||||
log.Warn().Err(err).Msg("failed to get default credentials")
|
||||
} else {
|
||||
log.Info().Msg("default credentials found, using")
|
||||
}
|
||||
return creds
|
||||
}
|
||||
|
||||
if creds, err = bmc.GetBMCCredentials(store, 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")
|
||||
if defaultSecret, err := bmc.GetBMCCredentialsDefault(store); err != nil {
|
||||
// We've exhausted all options, the credentials will be blank unless
|
||||
// overridden by a CLI flag.
|
||||
log.Warn().Str("id", id).Err(err).Msg("no default credentials were set, they will be blank unless overridden by CLI flags")
|
||||
} else {
|
||||
// Default credentials found, use them.
|
||||
log.Info().Str("id", id).Msg("default credentials found, using")
|
||||
creds = defaultSecret
|
||||
}
|
||||
} else {
|
||||
log.Info().Str("id", id).Msg("specific credentials found, using")
|
||||
}
|
||||
|
||||
return creds
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue