mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
Add support for storage command and crawler output
Partially addresses issue #3 by adding a simple `magellan list devices` command to list storage devices. To close the issue, this PR still requires including storage device information in the `crawler`'s output. Reviewed-on: towk/magellan-ng#5
This commit is contained in:
parent
6deb292494
commit
12969adf25
20 changed files with 448 additions and 53 deletions
43
cmd/root.go
43
cmd/root.go
|
|
@ -21,6 +21,8 @@ import (
|
|||
|
||||
magellan "github.com/davidallendj/magellan/internal"
|
||||
"github.com/davidallendj/magellan/internal/util"
|
||||
"github.com/davidallendj/magellan/pkg/bmc"
|
||||
"github.com/davidallendj/magellan/pkg/secrets"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
|
@ -150,3 +152,44 @@ func SetDefaults() {
|
|||
viper.SetDefault("update.status", false)
|
||||
|
||||
}
|
||||
|
||||
func initSecretsStore(uri string) secrets.SecretStore {
|
||||
var (
|
||||
store secrets.SecretStore
|
||||
err error
|
||||
)
|
||||
if username != "" && password != "" {
|
||||
// First, try and load credentials from --username and --password if both are set.
|
||||
log.Debug().Str("id", uri).Msgf("--username and --password specified, using them for BMC credentials")
|
||||
store = secrets.NewStaticStore(username, password)
|
||||
} else {
|
||||
// Alternatively, locate specific credentials (falling back to default) and override those
|
||||
// with --username or --password if either are passed.
|
||||
log.Debug().Str("id", uri).Msgf("one or both of --username and --password NOT passed, attempting to obtain missing credentials from secret store at %s", secretsFile)
|
||||
if store, err = secrets.OpenStore(secretsFile); err != nil {
|
||||
log.Error().Str("id", uri).Err(err).Msg("failed to open local secrets store")
|
||||
}
|
||||
|
||||
// Either none of the flags were passed or only one of them were; get
|
||||
// credentials from secrets store to fill in the gaps.
|
||||
bmcCreds, _ := bmc.GetBMCCredentials(store, uri)
|
||||
nodeCreds := secrets.StaticStore{
|
||||
Username: bmcCreds.Username,
|
||||
Password: bmcCreds.Password,
|
||||
}
|
||||
|
||||
// If either of the flags were passed, override the fetched
|
||||
// credentials with them.
|
||||
if username != "" {
|
||||
log.Info().Str("id", uri).Msg("--username was set, overriding username for this BMC")
|
||||
nodeCreds.Username = username
|
||||
}
|
||||
if password != "" {
|
||||
log.Info().Str("id", uri).Msg("--password was set, overriding password for this BMC")
|
||||
nodeCreds.Password = password
|
||||
}
|
||||
|
||||
store = &nodeCreds
|
||||
}
|
||||
return store
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue