Browse Source

command: basic rpc works for keys command

pull/336/head
Ryan Uber 10 years ago
parent
commit
67b179ccc9
  1. 15
      command/agent/agent.go
  2. 13
      command/agent/rpc.go
  3. 22
      command/agent/rpc_client.go
  4. 8
      command/keys.go
  5. 4
      consul/client.go

15
command/agent/agent.go

@ -741,17 +741,20 @@ func loadKeyringFile(keyringFile string) *memberlist.Keyring {
}
// ListKeysLAN returns the keys installed on the LAN gossip pool
func (a *Agent) ListKeysLAN() map[string]int {
func (a *Agent) ListKeysLAN() (*serf.KeyResponse, error) {
if a.server != nil {
return a.server.ListKeysLAN()
km := a.server.KeyManagerLAN()
return km.ListKeys()
}
return a.client.ListKeysLAN()
km := a.client.KeyManagerLAN()
return km.ListKeys()
}
// ListKeysWAN returns the keys installed on the WAN gossip pool
func (a *Agent) ListKeysWAN() map[string]int {
func (a *Agent) ListKeysWAN() (*serf.KeyResponse, error) {
if a.server != nil {
return a.server.ListKeysWAN()
km := a.server.KeyManagerWAN()
return km.ListKeys()
}
return nil
return nil, nil
}

13
command/agent/rpc.go

@ -629,7 +629,11 @@ func (i *AgentRPC) handleListKeysLAN(client *rpcClient, seq uint64) error {
Seq: seq,
Error: "",
}
resp := i.agent.ListKeysLAN()
resp, err := i.agent.ListKeysLAN()
if err != nil {
return err
}
return client.Send(&header, resp)
}
@ -638,7 +642,12 @@ func (i *AgentRPC) handleListKeysWAN(client *rpcClient, seq uint64) error {
Seq: seq,
Error: "",
}
resp := i.agent.ListKeysWAN()
resp, err := i.agent.ListKeysWAN()
if err != nil {
return err
}
return client.Send(&header, resp)
}

22
command/agent/rpc_client.go

@ -176,6 +176,28 @@ func (c *RPCClient) WANMembers() ([]Member, error) {
return resp.Members, err
}
func (c *RPCClient) ListKeysLAN() (map[string]int, error) {
header := requestHeader{
Command: listKeysLANCommand,
Seq: c.getSeq(),
}
resp := make(map[string]int)
err := c.genericRPC(&header, nil, &resp)
return resp, err
}
func (c *RPCClient) ListKeysWAN() (map[string]int, error) {
header := requestHeader{
Command: listKeysWANCommand,
Seq: c.getSeq(),
}
resp := make(map[string]int)
err := c.genericRPC(&header, nil, &resp)
return resp, err
}
// Leave is used to trigger a graceful leave and shutdown
func (c *RPCClient) Leave() error {
header := requestHeader{

8
command/keys.go

@ -49,8 +49,12 @@ func (c *KeysCommand) Run(args []string) int {
}
if listKeys {
km := client.KeyManager()
fmt.Println(km.ListKeys())
keys, err := client.ListKeysLAN()
if err != nil {
c.Ui.Error(fmt.Sprintf("Error: %s", err))
return 1
}
fmt.Println(keys)
return 0
}

4
consul/client.go

@ -206,8 +206,8 @@ func (c *Client) UserEvent(name string, payload []byte) error {
return c.serf.UserEvent(userEventName(name), payload, false)
}
// KeyManager returns the Serf keyring manager
func (c *Client) KeyManager() *serf.KeyManager {
// KeyManager returns the LAN Serf keyring manager
func (c *Client) KeyManagerLAN() *serf.KeyManager {
return c.serf.KeyManager()
}

Loading…
Cancel
Save