Shows the segment name in the keyring API and command output.

This commit is contained in:
James Phillips 2017-09-07 12:17:39 -07:00
parent 34bae2487d
commit 02a3f3f27b
No known key found for this signature in database
GPG Key ID: 77183E682AC5FC11
6 changed files with 22 additions and 7 deletions

View File

@ -149,12 +149,12 @@ func (m *Internal) executeKeyringOp(
if wan { if wan {
mgr := m.srv.KeyManagerWAN() mgr := m.srv.KeyManagerWAN()
m.executeKeyringOpMgr(mgr, args, reply, wan) m.executeKeyringOpMgr(mgr, args, reply, wan, "")
} else { } else {
segments := m.srv.LANSegments() segments := m.srv.LANSegments()
for _, segment := range segments { for name, segment := range segments {
mgr := segment.KeyManager() mgr := segment.KeyManager()
m.executeKeyringOpMgr(mgr, args, reply, wan) m.executeKeyringOpMgr(mgr, args, reply, wan, name)
} }
} }
} }
@ -166,7 +166,7 @@ func (m *Internal) executeKeyringOpMgr(
mgr *serf.KeyManager, mgr *serf.KeyManager,
args *structs.KeyringRequest, args *structs.KeyringRequest,
reply *structs.KeyringResponses, reply *structs.KeyringResponses,
wan bool) { wan bool, segment string) {
var serfResp *serf.KeyResponse var serfResp *serf.KeyResponse
var err error var err error
@ -190,6 +190,7 @@ func (m *Internal) executeKeyringOpMgr(
reply.Responses = append(reply.Responses, &structs.KeyringResponse{ reply.Responses = append(reply.Responses, &structs.KeyringResponse{
WAN: wan, WAN: wan,
Datacenter: m.srv.config.Datacenter, Datacenter: m.srv.config.Datacenter,
Segment: segment,
Messages: serfResp.Messages, Messages: serfResp.Messages,
Keys: serfResp.Keys, Keys: serfResp.Keys,
NumNodes: serfResp.NumNodes, NumNodes: serfResp.NumNodes,

View File

@ -887,6 +887,7 @@ func (r *KeyringRequest) RequestDatacenter() string {
type KeyringResponse struct { type KeyringResponse struct {
WAN bool WAN bool
Datacenter string Datacenter string
Segment string
Messages map[string]string `json:",omitempty"` Messages map[string]string `json:",omitempty"`
Keys map[string]int Keys map[string]int
NumNodes int NumNodes int

View File

@ -13,6 +13,9 @@ type KeyringResponse struct {
// The datacenter name this request corresponds to // The datacenter name this request corresponds to
Datacenter string Datacenter string
// Segment has the network segment this request corresponds to.
Segment string
// A map of the encryption keys to the number of nodes they're installed on // A map of the encryption keys to the number of nodes they're installed on
Keys map[string]int Keys map[string]int

View File

@ -129,6 +129,9 @@ func (c *KeyringCommand) Run(args []string) int {
func (c *KeyringCommand) handleList(responses []*consulapi.KeyringResponse) { func (c *KeyringCommand) handleList(responses []*consulapi.KeyringResponse) {
for _, response := range responses { for _, response := range responses {
pool := response.Datacenter + " (LAN)" pool := response.Datacenter + " (LAN)"
if response.Segment != "" {
pool += fmt.Sprintf(" [%s]", response.Segment)
}
if response.WAN { if response.WAN {
pool = "WAN" pool = "WAN"
} }

View File

@ -55,6 +55,7 @@ $ curl \
{ {
"WAN": true, "WAN": true,
"Datacenter": "dc1", "Datacenter": "dc1",
"Segment": "",
"Keys": { "Keys": {
"0eK8RjnsGC/+I1fJErQsBA==": 1, "0eK8RjnsGC/+I1fJErQsBA==": 1,
"G/3/L4yOw3e5T7NTvuRi9g==": 1, "G/3/L4yOw3e5T7NTvuRi9g==": 1,
@ -65,6 +66,7 @@ $ curl \
{ {
"WAN": false, "WAN": false,
"Datacenter": "dc1", "Datacenter": "dc1",
"Segment": "",
"Keys": { "Keys": {
"0eK8RjnsGC/+I1fJErQsBA==": 1, "0eK8RjnsGC/+I1fJErQsBA==": 1,
"G/3/L4yOw3e5T7NTvuRi9g==": 1, "G/3/L4yOw3e5T7NTvuRi9g==": 1,
@ -80,6 +82,8 @@ $ curl \
- `Datacenter` is the datacenter the block refers to. - `Datacenter` is the datacenter the block refers to.
- `Segment` is the network segment the block refers to.
- `Keys` is a map of each gossip key to the number of nodes it's currently - `Keys` is a map of each gossip key to the number of nodes it's currently
installed on. installed on.

View File

@ -73,11 +73,14 @@ dc2 (LAN):
dc1 (LAN): dc1 (LAN):
a1i101sMY8rxB+0eAKD/gw== [2/2] a1i101sMY8rxB+0eAKD/gw== [2/2]
dc1 (LAN) [alpha]:
a1i101sMY8rxB+0eAKD/gw== [2/2]
``` ```
As you can see, the output above is divided first by gossip pool, and then by As you can see, the output above is divided first by gossip pool, including any network
encryption key. The indicator to the right of each key displays the number of segments, and then by encryption key. The indicator to the right of each key displays
nodes the key is installed on over the total number of nodes in the pool. the number of nodes the key is installed on over the total number of nodes in the pool.
## Errors ## Errors