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