mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 11:37:01 -07:00
chore: more miscellaneous updates
This commit is contained in:
parent
7ffb080c7e
commit
094fb0df3b
6 changed files with 56 additions and 31 deletions
|
|
@ -10,6 +10,13 @@ import (
|
||||||
type BMCCredentials struct {
|
type BMCCredentials struct {
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
|
SessionTokens map[string]string `json:"session-tokens"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c BMCCredentials) IsEmpty() bool {
|
||||||
|
return c.Username == "" &&
|
||||||
|
c.Password == "" &&
|
||||||
|
len(c.SessionTokens) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBMCCredentialsDefault(store secrets.SecretStore) (BMCCredentials, error) {
|
func GetBMCCredentialsDefault(store secrets.SecretStore) (BMCCredentials, error) {
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ type CollectParams struct {
|
||||||
Format string // set the output format
|
Format string // set the output format
|
||||||
ForceUpdate bool // set whether to force updating SMD with 'force-update' flag
|
ForceUpdate bool // set whether to force updating SMD with 'force-update' flag
|
||||||
AccessToken string // set the access token to include in request with 'access-token' flag
|
AccessToken string // set the access token to include in request with 'access-token' flag
|
||||||
|
SessionToken string // set the session token to use for auth
|
||||||
SecretStore secrets.SecretStore // set BMC credentials
|
SecretStore secrets.SecretStore // set BMC credentials
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,7 +72,7 @@ func CollectInventory(assets *[]RemoteAsset, params *CollectParams, store secret
|
||||||
|
|
||||||
// set the client's params from CLI
|
// set the client's params from CLI
|
||||||
wg.Add(params.Concurrency)
|
wg.Add(params.Concurrency)
|
||||||
for i := 0; i < params.Concurrency; i++ {
|
for _ = range params.Concurrency {
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
sr, ok := <-chanAssets
|
sr, ok := <-chanAssets
|
||||||
|
|
@ -129,7 +130,7 @@ func CollectInventory(assets *[]RemoteAsset, params *CollectParams, store secret
|
||||||
|
|
||||||
// get BMC username to send
|
// get BMC username to send
|
||||||
bmcCreds := bmc.GetBMCCredentialsOrDefault(params.SecretStore, config.URI)
|
bmcCreds := bmc.GetBMCCredentialsOrDefault(params.SecretStore, config.URI)
|
||||||
if bmcCreds == (bmc.BMCCredentials{}) {
|
if bmcCreds.IsEmpty() {
|
||||||
log.Warn().Str("id", config.URI).Msg("username will be blank")
|
log.Warn().Str("id", config.URI).Msg("username will be blank")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,13 @@ type CrawlerConfig struct {
|
||||||
URI string // URI of the BMC
|
URI string // URI of the BMC
|
||||||
Insecure bool // Whether to ignore SSL errors
|
Insecure bool // Whether to ignore SSL errors
|
||||||
CredentialStore secrets.SecretStore
|
CredentialStore secrets.SecretStore
|
||||||
|
SessionID string
|
||||||
|
SessionToken string
|
||||||
UseDefault bool
|
UseDefault bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cc *CrawlerConfig) GetUserPass() (bmc.BMCCredentials, error) {
|
func (cc *CrawlerConfig) GetUserPass() (bmc.BMCCredentials, error) {
|
||||||
return loadBMCCreds(*cc)
|
return LoadBMCCreds(*cc)
|
||||||
}
|
}
|
||||||
|
|
||||||
type EthernetInterface struct {
|
type EthernetInterface struct {
|
||||||
|
|
@ -110,7 +112,7 @@ func CrawlBMCForSystems(config CrawlerConfig) ([]InventoryDetail, error) {
|
||||||
rf_systems []*redfish.ComputerSystem
|
rf_systems []*redfish.ComputerSystem
|
||||||
)
|
)
|
||||||
// get username and password from secret store
|
// get username and password from secret store
|
||||||
bmc_creds, err := loadBMCCreds(config)
|
bmc_creds, err := LoadBMCCreds(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
event := log.Error()
|
event := log.Error()
|
||||||
event.Err(err)
|
event.Err(err)
|
||||||
|
|
@ -124,8 +126,13 @@ func CrawlBMCForSystems(config CrawlerConfig) ([]InventoryDetail, error) {
|
||||||
Username: bmc_creds.Username,
|
Username: bmc_creds.Username,
|
||||||
Password: bmc_creds.Password,
|
Password: bmc_creds.Password,
|
||||||
Insecure: config.Insecure,
|
Insecure: config.Insecure,
|
||||||
|
Session: &gofish.Session{
|
||||||
|
ID: config.SessionID,
|
||||||
|
Token: bmc_creds.SessionTokens[config.SessionID],
|
||||||
|
},
|
||||||
BasicAuth: true,
|
BasicAuth: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.HasPrefix(err.Error(), "404:") {
|
if strings.HasPrefix(err.Error(), "404:") {
|
||||||
err = fmt.Errorf("no ServiceRoot found. This is probably not a BMC: %s", config.URI)
|
err = fmt.Errorf("no ServiceRoot found. This is probably not a BMC: %s", config.URI)
|
||||||
|
|
@ -186,7 +193,7 @@ func CrawlBMCForSystems(config CrawlerConfig) ([]InventoryDetail, error) {
|
||||||
func CrawlBMCForManagers(config CrawlerConfig) ([]Manager, error) {
|
func CrawlBMCForManagers(config CrawlerConfig) ([]Manager, error) {
|
||||||
|
|
||||||
// get username and password from secret store
|
// get username and password from secret store
|
||||||
bmc_creds, err := loadBMCCreds(config)
|
bmc_creds, err := LoadBMCCreds(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
event := log.Error()
|
event := log.Error()
|
||||||
event.Err(err)
|
event.Err(err)
|
||||||
|
|
@ -229,7 +236,7 @@ func CrawlBMCForManagers(config CrawlerConfig) ([]Manager, error) {
|
||||||
|
|
||||||
func CrawlBMCForStorage(config CrawlerConfig) ([]Storage, error) {
|
func CrawlBMCForStorage(config CrawlerConfig) ([]Storage, error) {
|
||||||
// get username and password from secret store
|
// get username and password from secret store
|
||||||
bmc_creds, err := loadBMCCreds(config)
|
bmc_creds, err := LoadBMCCreds(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
event := log.Error()
|
event := log.Error()
|
||||||
event.Err(err)
|
event.Err(err)
|
||||||
|
|
@ -466,12 +473,12 @@ func walkStorage(rf_storage []*redfish.Storage, baseURI string) ([]Storage, erro
|
||||||
return storage, nil
|
return storage, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadBMCCreds(config CrawlerConfig) (bmc.BMCCredentials, error) {
|
func LoadBMCCreds(config CrawlerConfig) (bmc.BMCCredentials, error) {
|
||||||
// NOTE: it is possible for the SecretStore to be nil, so we need a check
|
// NOTE: it is possible for the SecretStore to be nil, so we need a check
|
||||||
if config.CredentialStore == nil {
|
if config.CredentialStore == nil {
|
||||||
return bmc.BMCCredentials{}, fmt.Errorf("credential store is invalid")
|
return bmc.BMCCredentials{}, fmt.Errorf("credential store is invalid")
|
||||||
}
|
}
|
||||||
if creds := util.GetBMCCredentials(config.CredentialStore, config.URI); creds == (bmc.BMCCredentials{}) {
|
if creds := util.GetBMCCredentials(config.CredentialStore, config.URI); creds.IsEmpty() {
|
||||||
return creds, fmt.Errorf("%s: credentials blank for BMC", config.URI)
|
return creds, fmt.Errorf("%s: credentials blank for BMC", config.URI)
|
||||||
} else {
|
} else {
|
||||||
return creds, nil
|
return creds, nil
|
||||||
|
|
|
||||||
10
pkg/list.go
10
pkg/list.go
|
|
@ -18,27 +18,27 @@ func PrintRemoteAssets(data []RemoteAsset, format string) {
|
||||||
util.PrintJSON(data)
|
util.PrintJSON(data)
|
||||||
case "yaml":
|
case "yaml":
|
||||||
util.PrintYAML(data)
|
util.PrintYAML(data)
|
||||||
case "none":
|
case "list":
|
||||||
for _, r := range data {
|
for _, r := range data {
|
||||||
fmt.Printf("%s:%d (%s) @%s\n", r.Host, r.Port, r.Protocol, r.Timestamp.Format(time.UnixDate))
|
fmt.Printf("%s:%d (%s) @%s\n", r.Host, r.Port, r.Protocol, r.Timestamp.Format(time.UnixDate))
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
log.Error().Msg("unrecognized format")
|
log.Error().Msg("PrintRemoteAssets: unrecognized format")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrintMapFormat(data map[string]any, format string) {
|
func PrintMapWithFormat(data map[string]any, format string) {
|
||||||
switch strings.ToLower(format) {
|
switch strings.ToLower(format) {
|
||||||
case "json":
|
case "json":
|
||||||
util.PrintJSON(data)
|
util.PrintJSON(data)
|
||||||
case "yaml":
|
case "yaml":
|
||||||
util.PrintYAML(data)
|
util.PrintYAML(data)
|
||||||
case "none":
|
case "list":
|
||||||
for k, v := range data {
|
for k, v := range data {
|
||||||
fmt.Printf("%s: %v\n", k, v)
|
fmt.Printf("%s: %v\n", k, v)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
log.Error().Msg("unrecognized format")
|
log.Error().Msg("PrintMapWithFormat: unrecognized format")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,11 @@ func (l *LocalSecretStore) ListSecrets() (map[string]string, error) {
|
||||||
defer l.mu.RUnlock()
|
defer l.mu.RUnlock()
|
||||||
|
|
||||||
secretsCopy := make(map[string]string)
|
secretsCopy := make(map[string]string)
|
||||||
for key, value := range l.Secrets {
|
for key, _ := range l.Secrets {
|
||||||
|
value, err := l.GetSecretByID(key)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
secretsCopy[key] = value
|
secretsCopy[key] = value
|
||||||
}
|
}
|
||||||
return secretsCopy, nil
|
return secretsCopy, nil
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,13 @@
|
||||||
package secrets
|
package secrets
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
const DEFAULT_KEY = "default"
|
const DEFAULT_KEY = "default"
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrLoadFailedCreds = errors.New("failed to load BMC credentials")
|
||||||
|
)
|
||||||
|
|
||||||
type SecretStore interface {
|
type SecretStore interface {
|
||||||
GetSecretByID(secretID string) (string, error)
|
GetSecretByID(secretID string) (string, error)
|
||||||
StoreSecretByID(secretID, secret string) error
|
StoreSecretByID(secretID, secret string) error
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue