mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
chore: made changes to build and fix issues
This commit is contained in:
parent
62a7c436a3
commit
5386ba3397
3 changed files with 52 additions and 11 deletions
|
|
@ -139,7 +139,7 @@ var sessionLoginCmd = &cobra.Command{
|
|||
case "yaml":
|
||||
util.PrintYAML(newSessions)
|
||||
default:
|
||||
log.Error().Msg("unrecognized output format")
|
||||
log.Error().Msg("unrecognized output sessionOutputFormat")
|
||||
os.Exit(1)
|
||||
}
|
||||
},
|
||||
|
|
@ -226,7 +226,7 @@ var sessionLogoutCmd = &cobra.Command{
|
|||
|
||||
var sessionStatusCmd = &cobra.Command{
|
||||
Use: "status",
|
||||
Example: ` // show the host's session service status in YAML format
|
||||
Example: ` // show the host's session service status in YAML sessionOutputFormat
|
||||
magellan sessions status https://172.21.0.2:5000 -u $bmc_username -p $bmc_password -i -F yaml`,
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
Short: "Show the status of the session service",
|
||||
|
|
@ -283,7 +283,7 @@ var sessionListCmd = &cobra.Command{
|
|||
case FORMAT_YAML:
|
||||
util.PrintYAML(session)
|
||||
default:
|
||||
log.Error().Msg("unrecognized output format")
|
||||
log.Error().Msg("unrecognized output sessionOutputFormat")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
|
@ -311,7 +311,7 @@ var sessionListCmd = &cobra.Command{
|
|||
case FORMAT_YAML:
|
||||
util.PrintYAML(sessionIDs)
|
||||
default:
|
||||
log.Error().Msg("unrecognized output format")
|
||||
log.Error().Msg("unrecognized output sessionOutputFormat")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
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
|
||||
}
|
||||
|
|
@ -51,7 +51,7 @@ type CollectParams struct {
|
|||
//
|
||||
// Requests can be made to several of the nodes using a goroutine by setting the q.Concurrency
|
||||
// property value between 1 and 10000.
|
||||
func CollectInventory(assets *[]RemoteAsset, params *CollectParams, store secrets.SecretStore) ([]map[string]any, error) {
|
||||
func CollectInventory(assets *[]RemoteAsset, params *CollectParams) ([]map[string]any, error) {
|
||||
// check for available remote assets found from scan
|
||||
if assets == nil {
|
||||
return nil, fmt.Errorf("no assets found")
|
||||
|
|
@ -134,12 +134,6 @@ func CollectInventory(assets *[]RemoteAsset, params *CollectParams, store secret
|
|||
log.Warn().Str("id", config.URI).Msg("username will be blank")
|
||||
}
|
||||
|
||||
// get BMC username to send
|
||||
bmcCreds, err := bmc.GetBMCCredentials(params.SecretStore, config.URI)
|
||||
if err != nil {
|
||||
log.Error().Str("id", config.URI).Msg("username will be blank")
|
||||
}
|
||||
|
||||
// data to be sent to smd
|
||||
data := map[string]any{
|
||||
"ID": fmt.Sprintf("%v", node.String()[:len(node.String())-2]),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue