github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/command/operator_gossip_keyring_remove.go (about) 1 package command 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/mitchellh/cli" 8 "github.com/posener/complete" 9 ) 10 11 // OperatorGossipKeyringRemoveCommand is a Command implementation 12 // that handles removing a gossip encryption key from a keyring 13 type OperatorGossipKeyringRemoveCommand struct { 14 Meta 15 } 16 17 func (c *OperatorGossipKeyringRemoveCommand) Help() string { 18 helpText := ` 19 Usage: nomad operator gossip keyring remove [options] <key> 20 21 Remove the given key from the cluster. This operation may only be performed 22 on keys which are not currently the primary key. 23 24 This command can only be run against server nodes. It returns 0 if all nodes 25 reply and there are no errors. If any node fails to reply or reports failure, 26 the exit code will be 1. 27 28 If ACLs are enabled, this command requires a token with the 'agent:write' 29 capability. 30 31 General Options: 32 33 ` + generalOptionsUsage(usageOptsDefault|usageOptsNoNamespace) 34 35 return strings.TrimSpace(helpText) 36 } 37 38 func (c *OperatorGossipKeyringRemoveCommand) Synopsis() string { 39 return "Remove a gossip encryption key" 40 } 41 42 func (c *OperatorGossipKeyringRemoveCommand) AutocompleteFlags() complete.Flags { 43 return c.Meta.AutocompleteFlags(FlagSetClient) 44 } 45 46 func (c *OperatorGossipKeyringRemoveCommand) AutocompleteArgs() complete.Predictor { 47 return complete.PredictAnything 48 } 49 50 func (c *OperatorGossipKeyringRemoveCommand) Name() string { return "operator gossip keyring remove" } 51 52 func (c *OperatorGossipKeyringRemoveCommand) Run(args []string) int { 53 flags := c.Meta.FlagSet("operator-gossip-keyring-remove", FlagSetClient) 54 flags.Usage = func() { c.Ui.Output(c.Help()) } 55 if err := flags.Parse(args); err != nil { 56 return 1 57 } 58 59 c.Ui = &cli.PrefixedUi{ 60 OutputPrefix: "", 61 InfoPrefix: "==> ", 62 ErrorPrefix: "", 63 Ui: c.Ui, 64 } 65 66 args = flags.Args() 67 if len(args) != 1 { 68 c.Ui.Error("This command requires one argument: <key>") 69 c.Ui.Error(commandErrorText(c)) 70 return 1 71 } 72 removeKey := args[0] 73 74 client, err := c.Meta.Client() 75 if err != nil { 76 c.Ui.Error(fmt.Sprintf("Error creating nomad cli client: %s", err)) 77 return 1 78 } 79 80 c.Ui.Output("Removing gossip encryption key...") 81 _, err = client.Agent().RemoveKey(removeKey) 82 if err != nil { 83 c.Ui.Error(fmt.Sprintf("error: %s", err)) 84 return 1 85 } 86 return 0 87 }