2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2022-06-14 15:22:42 +00:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/posener/complete"
|
|
|
|
)
|
|
|
|
|
2022-08-26 18:03:56 +00:00
|
|
|
// OperatorRootKeyringListCommand is a Command
|
|
|
|
// implementation that lists the variables encryption keys.
|
|
|
|
type OperatorRootKeyringListCommand struct {
|
2022-06-14 15:22:42 +00:00
|
|
|
Meta
|
|
|
|
}
|
|
|
|
|
2022-08-26 18:03:56 +00:00
|
|
|
func (c *OperatorRootKeyringListCommand) Help() string {
|
2022-06-14 15:22:42 +00:00
|
|
|
helpText := `
|
2022-08-26 18:03:56 +00:00
|
|
|
Usage: nomad operator root keyring list [options]
|
2022-06-14 15:22:42 +00:00
|
|
|
|
|
|
|
List the currently installed keys. This list returns key metadata and not
|
|
|
|
sensitive key material.
|
|
|
|
|
|
|
|
If ACLs are enabled, this command requires a management token.
|
|
|
|
|
|
|
|
General Options:
|
|
|
|
|
|
|
|
` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + `
|
|
|
|
|
|
|
|
Keyring Options:
|
|
|
|
|
|
|
|
-verbose
|
|
|
|
Show full information.
|
|
|
|
`
|
|
|
|
|
|
|
|
return strings.TrimSpace(helpText)
|
|
|
|
}
|
|
|
|
|
2022-08-26 18:03:56 +00:00
|
|
|
func (c *OperatorRootKeyringListCommand) Synopsis() string {
|
|
|
|
return "Lists the root encryption keys"
|
2022-06-14 15:22:42 +00:00
|
|
|
}
|
|
|
|
|
2022-08-26 18:03:56 +00:00
|
|
|
func (c *OperatorRootKeyringListCommand) AutocompleteFlags() complete.Flags {
|
2022-06-14 15:22:42 +00:00
|
|
|
return mergeAutocompleteFlags(c.Meta.AutocompleteFlags(FlagSetClient),
|
|
|
|
complete.Flags{
|
|
|
|
"-verbose": complete.PredictNothing,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-08-26 18:03:56 +00:00
|
|
|
func (c *OperatorRootKeyringListCommand) AutocompleteArgs() complete.Predictor {
|
2022-06-14 15:22:42 +00:00
|
|
|
return complete.PredictNothing
|
|
|
|
}
|
|
|
|
|
2022-08-26 18:03:56 +00:00
|
|
|
func (c *OperatorRootKeyringListCommand) Name() string {
|
|
|
|
return "root keyring list"
|
2022-06-14 15:22:42 +00:00
|
|
|
}
|
|
|
|
|
2022-08-26 18:03:56 +00:00
|
|
|
func (c *OperatorRootKeyringListCommand) Run(args []string) int {
|
2022-06-14 15:22:42 +00:00
|
|
|
var verbose bool
|
|
|
|
|
2022-08-26 18:03:56 +00:00
|
|
|
flags := c.Meta.FlagSet("root keyring list", FlagSetClient)
|
2022-06-14 15:22:42 +00:00
|
|
|
flags.Usage = func() { c.Ui.Output(c.Help()) }
|
|
|
|
flags.BoolVar(&verbose, "verbose", false, "")
|
|
|
|
|
|
|
|
if err := flags.Parse(args); err != nil {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
args = flags.Args()
|
|
|
|
if len(args) != 0 {
|
|
|
|
c.Ui.Error("This command requires no arguments.")
|
|
|
|
c.Ui.Error(commandErrorText(c))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
client, err := c.Meta.Client()
|
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("Error creating nomad cli client: %s", err))
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, _, err := client.Keyring().List(nil)
|
|
|
|
if err != nil {
|
|
|
|
c.Ui.Error(fmt.Sprintf("error: %s", err))
|
|
|
|
return 1
|
|
|
|
}
|
2022-08-26 18:03:56 +00:00
|
|
|
c.Ui.Output(renderVariablesKeysResponse(resp, verbose))
|
2022-06-14 15:22:42 +00:00
|
|
|
return 0
|
|
|
|
}
|