mirror of https://github.com/status-im/consul.git
command/keyring: refactor, adjust tests
This commit is contained in:
parent
91ad3461f4
commit
6a3271980e
|
@ -11,7 +11,6 @@ import (
|
||||||
|
|
||||||
"github.com/hashicorp/consul/command/agent"
|
"github.com/hashicorp/consul/command/agent"
|
||||||
"github.com/mitchellh/cli"
|
"github.com/mitchellh/cli"
|
||||||
"github.com/ryanuber/columnize"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -97,7 +96,7 @@ func (c *KeyringCommand) Run(args []string) int {
|
||||||
defer client.Close()
|
defer client.Close()
|
||||||
|
|
||||||
if listKeys {
|
if listKeys {
|
||||||
c.Ui.Info("Asking all members for installed keys...")
|
c.Ui.Info("Gathering installed encryption keys...")
|
||||||
r, err := client.ListKeys()
|
r, err := client.ListKeys()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Ui.Error(fmt.Sprintf("error: %s", err))
|
c.Ui.Error(fmt.Sprintf("error: %s", err))
|
||||||
|
@ -161,17 +160,12 @@ func (c *KeyringCommand) handleResponse(
|
||||||
c.Ui.Error("")
|
c.Ui.Error("")
|
||||||
c.Ui.Error(fmt.Sprintf("%s error: %s", pool, i.Error))
|
c.Ui.Error(fmt.Sprintf("%s error: %s", pool, i.Error))
|
||||||
|
|
||||||
var errors []string
|
|
||||||
for _, msg := range messages {
|
for _, msg := range messages {
|
||||||
if msg.Datacenter != i.Datacenter || msg.Pool != i.Pool {
|
if msg.Datacenter != i.Datacenter || msg.Pool != i.Pool {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
errors = append(errors, fmt.Sprintf(
|
c.Ui.Error(fmt.Sprintf(" %s: %s", msg.Node, msg.Message))
|
||||||
"failed: %s | %s",
|
|
||||||
msg.Node,
|
|
||||||
msg.Message))
|
|
||||||
}
|
}
|
||||||
c.Ui.Error(columnize.SimpleFormat(errors))
|
|
||||||
rval = 1
|
rval = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -208,16 +202,13 @@ func (c *KeyringCommand) handleList(
|
||||||
installed[pool][key.Key] = []int{key.Count, nodes}
|
installed[pool][key.Key] = []int{key.Count, nodes}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for pool, keys := range installed {
|
for pool, keys := range installed {
|
||||||
c.Ui.Output("")
|
c.Ui.Output("")
|
||||||
c.Ui.Output(pool + ":")
|
c.Ui.Output(pool + ":")
|
||||||
var out []string
|
|
||||||
for key, num := range keys {
|
for key, num := range keys {
|
||||||
out = append(out, fmt.Sprintf(
|
c.Ui.Output(fmt.Sprintf(" %s [%d/%d]", key, num[0], num[1]))
|
||||||
"%s | [%d/%d]",
|
|
||||||
key, num[0], num[1]))
|
|
||||||
}
|
}
|
||||||
c.Ui.Output(columnize.SimpleFormat(out))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,10 +26,10 @@ func TestKeyringCommandRun(t *testing.T) {
|
||||||
|
|
||||||
// The LAN and WAN keyrings were initialized with key1
|
// The LAN and WAN keyrings were initialized with key1
|
||||||
out := listKeys(t, a1.addr)
|
out := listKeys(t, a1.addr)
|
||||||
if !strings.Contains(out, "dc1 (LAN):\n"+key1) {
|
if !strings.Contains(out, "dc1 (LAN):\n "+key1) {
|
||||||
t.Fatalf("bad: %#v", out)
|
t.Fatalf("bad: %#v", out)
|
||||||
}
|
}
|
||||||
if !strings.Contains(out, "WAN:\n"+key1) {
|
if !strings.Contains(out, "WAN:\n "+key1) {
|
||||||
t.Fatalf("bad: %#v", out)
|
t.Fatalf("bad: %#v", out)
|
||||||
}
|
}
|
||||||
if strings.Contains(out, key2) {
|
if strings.Contains(out, key2) {
|
||||||
|
@ -53,10 +53,10 @@ func TestKeyringCommandRun(t *testing.T) {
|
||||||
|
|
||||||
// Only key2 is present now
|
// Only key2 is present now
|
||||||
out = listKeys(t, a1.addr)
|
out = listKeys(t, a1.addr)
|
||||||
if !strings.Contains(out, "dc1 (LAN):\n"+key2) {
|
if !strings.Contains(out, "dc1 (LAN):\n "+key2) {
|
||||||
t.Fatalf("bad: %#v", out)
|
t.Fatalf("bad: %#v", out)
|
||||||
}
|
}
|
||||||
if !strings.Contains(out, "WAN:\n"+key2) {
|
if !strings.Contains(out, "WAN:\n "+key2) {
|
||||||
t.Fatalf("bad: %#v", out)
|
t.Fatalf("bad: %#v", out)
|
||||||
}
|
}
|
||||||
if strings.Contains(out, key1) {
|
if strings.Contains(out, key1) {
|
||||||
|
|
Loading…
Reference in New Issue