github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/command/operator_root_keyring_list.go (about) 1 package command 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/posener/complete" 8 ) 9 10 // OperatorRootKeyringListCommand is a Command 11 // implementation that lists the variables encryption keys. 12 type OperatorRootKeyringListCommand struct { 13 Meta 14 } 15 16 func (c *OperatorRootKeyringListCommand) Help() string { 17 helpText := ` 18 Usage: nomad operator root keyring list [options] 19 20 List the currently installed keys. This list returns key metadata and not 21 sensitive key material. 22 23 If ACLs are enabled, this command requires a management token. 24 25 General Options: 26 27 ` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) + ` 28 29 Keyring Options: 30 31 -verbose 32 Show full information. 33 ` 34 35 return strings.TrimSpace(helpText) 36 } 37 38 func (c *OperatorRootKeyringListCommand) Synopsis() string { 39 return "Lists the root encryption keys" 40 } 41 42 func (c *OperatorRootKeyringListCommand) AutocompleteFlags() complete.Flags { 43 return mergeAutocompleteFlags(c.Meta.AutocompleteFlags(FlagSetClient), 44 complete.Flags{ 45 "-verbose": complete.PredictNothing, 46 }) 47 } 48 49 func (c *OperatorRootKeyringListCommand) AutocompleteArgs() complete.Predictor { 50 return complete.PredictNothing 51 } 52 53 func (c *OperatorRootKeyringListCommand) Name() string { 54 return "root keyring list" 55 } 56 57 func (c *OperatorRootKeyringListCommand) Run(args []string) int { 58 var verbose bool 59 60 flags := c.Meta.FlagSet("root keyring list", FlagSetClient) 61 flags.Usage = func() { c.Ui.Output(c.Help()) } 62 flags.BoolVar(&verbose, "verbose", false, "") 63 64 if err := flags.Parse(args); err != nil { 65 return 1 66 } 67 68 args = flags.Args() 69 if len(args) != 0 { 70 c.Ui.Error("This command requires no arguments.") 71 c.Ui.Error(commandErrorText(c)) 72 return 1 73 } 74 75 client, err := c.Meta.Client() 76 if err != nil { 77 c.Ui.Error(fmt.Sprintf("Error creating nomad cli client: %s", err)) 78 return 1 79 } 80 81 resp, _, err := client.Keyring().List(nil) 82 if err != nil { 83 c.Ui.Error(fmt.Sprintf("error: %s", err)) 84 return 1 85 } 86 c.Ui.Output(renderVariablesKeysResponse(resp, verbose)) 87 return 0 88 }