mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 11:37:01 -07:00
merge: updates from default secret store (PR #87/90)
This commit is contained in:
commit
6bcfea2803
10 changed files with 308 additions and 161 deletions
|
|
@ -1,10 +1,11 @@
|
|||
package crawler
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/OpenCHAMI/magellan/internal/util"
|
||||
"github.com/OpenCHAMI/magellan/pkg/bmc"
|
||||
"github.com/OpenCHAMI/magellan/pkg/secrets"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/stmcginnis/gofish"
|
||||
|
|
@ -18,15 +19,10 @@ type CrawlerConfig struct {
|
|||
UseDefault bool
|
||||
}
|
||||
|
||||
func (cc *CrawlerConfig) GetUserPass() (BMCUsernamePassword, error) {
|
||||
func (cc *CrawlerConfig) GetUserPass() (bmc.BMCCredentials, error) {
|
||||
return loadBMCCreds(*cc)
|
||||
}
|
||||
|
||||
type BMCUsernamePassword struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type EthernetInterface struct {
|
||||
URI string `json:"uri,omitempty"` // URI of the interface
|
||||
MAC string `json:"mac,omitempty"` // MAC address of the interface
|
||||
|
|
@ -373,37 +369,14 @@ func walkManagers(rf_managers []*redfish.Manager, baseURI string) ([]Manager, er
|
|||
return managers, nil
|
||||
}
|
||||
|
||||
func loadBMCCreds(config CrawlerConfig) (BMCUsernamePassword, error) {
|
||||
func loadBMCCreds(config CrawlerConfig) (bmc.BMCCredentials, 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")
|
||||
return bmc.BMCCredentials{}, fmt.Errorf("credential store is invalid")
|
||||
}
|
||||
creds, err := config.CredentialStore.GetSecretByID(config.URI)
|
||||
if err != nil {
|
||||
event := log.Error()
|
||||
event.Err(err)
|
||||
event.Msg("failed to get credentials from secret store")
|
||||
// try to get default if parameter is set
|
||||
if config.UseDefault {
|
||||
creds, err = config.CredentialStore.GetSecretByID(secrets.DEFAULT_KEY)
|
||||
// no default credentials
|
||||
if err != nil {
|
||||
event := log.Error()
|
||||
event.Err(err)
|
||||
event.Msg("failed to get default credentials from secret store")
|
||||
return BMCUsernamePassword{}, err
|
||||
}
|
||||
} else {
|
||||
return BMCUsernamePassword{}, err
|
||||
}
|
||||
if creds := util.GetBMCCredentials(config.CredentialStore, config.URI); creds == (bmc.BMCCredentials{}) {
|
||||
return creds, fmt.Errorf("%s: credentials blank for BNC", config.URI)
|
||||
} else {
|
||||
return creds, nil
|
||||
}
|
||||
var bmc_creds BMCUsernamePassword
|
||||
err = json.Unmarshal([]byte(creds), &bmc_creds)
|
||||
if err != nil {
|
||||
event := log.Error()
|
||||
event.Err(err)
|
||||
event.Msg("failed to unmarshal credentials")
|
||||
return BMCUsernamePassword{}, err
|
||||
}
|
||||
return bmc_creds, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue