mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 11:37:01 -07:00
refactor: split BMC data structures into pkg/bmc package
This commit is contained in:
parent
e62a38183f
commit
93010587c6
4 changed files with 78 additions and 51 deletions
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
|
||||
"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,10 +369,10 @@ 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 {
|
||||
|
|
@ -391,19 +387,19 @@ func loadBMCCreds(config CrawlerConfig) (BMCUsernamePassword, error) {
|
|||
event := log.Error()
|
||||
event.Err(err)
|
||||
event.Msg("failed to get default credentials from secret store")
|
||||
return BMCUsernamePassword{}, err
|
||||
return bmc.BMCCredentials{}, err
|
||||
}
|
||||
} else {
|
||||
return BMCUsernamePassword{}, err
|
||||
return bmc.BMCCredentials{}, err
|
||||
}
|
||||
}
|
||||
var bmc_creds BMCUsernamePassword
|
||||
var bmc_creds bmc.BMCCredentials
|
||||
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.BMCCredentials{}, err
|
||||
}
|
||||
return bmc_creds, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue