github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/command/operator_gossip_keyring_install.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 // OperatorGossipKeyringInstallCommand is a Command implementation 12 // that handles installing a gossip encryption key from a keyring 13 type OperatorGossipKeyringInstallCommand struct { 14 Meta 15 } 16 17 func (c *OperatorGossipKeyringInstallCommand) Help() string { 18 helpText := ` 19 Usage: nomad operator gossip keyring install [options] <key> 20 21 Install a new encryption key used for gossip. This will broadcast the new key 22 to all members in the cluster. 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 *OperatorGossipKeyringInstallCommand) Synopsis() string { 39 return "Install a gossip encryption key" 40 } 41 42 func (c *OperatorGossipKeyringInstallCommand) AutocompleteFlags() complete.Flags { 43 return c.Meta.AutocompleteFlags(FlagSetClient) 44 } 45 46 func (c *OperatorGossipKeyringInstallCommand) AutocompleteArgs() complete.Predictor { 47 return complete.PredictAnything 48 } 49 50 func (c *OperatorGossipKeyringInstallCommand) Name() string { return "operator gossip keyring install" } 51 52 func (c *OperatorGossipKeyringInstallCommand) Run(args []string) int { 53 flags := c.Meta.FlagSet("operator-gossip-keyring-install", 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 installKey := 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("Installing new gossip encryption key...") 81 _, err = client.Agent().InstallKey(installKey) 82 if err != nil { 83 c.Ui.Error(fmt.Sprintf("error: %s", err)) 84 return 1 85 } 86 return 0 87 }