feat: added sessions cmd

This commit is contained in:
David Allen 2025-05-26 22:46:14 -06:00
parent a6c445b86f
commit fdf715c6b3
Signed by: towk
GPG key ID: 0430CDBE22619155
2 changed files with 357 additions and 20 deletions

View file

@ -25,7 +25,7 @@ var secretsCmd = &cobra.Command{
// generate new key and set environment variable
export MASTER_KEY=$(magellan secrets generatekey)
// store specific BMC node creds for collect and crawl in default secrets store (--file/-f flag not set)
// store specific BMC node creds for collect and crawl in default secrets store (--secrets-file/-f flag not set)
magellan secrets store $bmc_host $bmc_creds
// retrieve creds from secrets store
@ -117,8 +117,8 @@ var secretsStoreCmd = &cobra.Command{
}
// check the decoded string if it's a valid JSON and has creds
if !isValidCredsJSON(string(decoded)) {
log.Error().Err(err).Msg("value is not a valid JSON or is missing credentials")
if !json.Valid(decoded) {
log.Error().Err(err).Msg("decoded secret value is not a valid JSON")
os.Exit(1)
}
@ -144,8 +144,9 @@ var secretsStoreCmd = &cobra.Command{
}
// make sure we have valid JSON with "username" and "password" properties
if !isValidCredsJSON(string(secretValue)) {
log.Error().Err(err).Msg("not a valid JSON or creds")
if !json.Valid([]byte(secretValue)) {
log.Error().Err(err).Msg("secret value is not a valid JSON")
os.Exit(1)
}
store, err = secrets.OpenStore(secretsFile)
@ -165,21 +166,6 @@ var secretsStoreCmd = &cobra.Command{
},
}
func isValidCredsJSON(val string) bool {
var (
valid = !json.Valid([]byte(val))
creds map[string]string
err error
)
err = json.Unmarshal([]byte(val), &creds)
if err != nil {
return false
}
_, valid = creds["username"]
_, valid = creds["password"]
return valid
}
var secretsRetrieveCmd = &cobra.Command{
Use: "retrieve secretID",
Args: cobra.MinimumNArgs(1),