From 1f9d13dc73e16331264326f92b97f177713afaff Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Thu, 2 Oct 2014 18:12:01 -0700 Subject: [PATCH] agent: squash some more common keyring semantics --- command/agent/keyring.go | 20 ++++++++------------ consul/internal_endpoint.go | 9 --------- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/command/agent/keyring.go b/command/agent/keyring.go index 6df94d3c9b..2f1835d634 100644 --- a/command/agent/keyring.go +++ b/command/agent/keyring.go @@ -73,6 +73,10 @@ func (a *Agent) keyringProcess( method string, args *structs.KeyringRequest) (*structs.KeyringResponses, error) { + // Allow any server to handle the request, since this is + // done over the gossip protocol. + args.AllowStale = true + var reply structs.KeyringResponses if a.server == nil { return nil, fmt.Errorf("keyring operations must run against a server node") @@ -87,32 +91,24 @@ func (a *Agent) keyringProcess( // ListKeys lists out all keys installed on the collective Consul cluster. This // includes both servers and clients in all DC's. func (a *Agent) ListKeys() (*structs.KeyringResponses, error) { - args := structs.KeyringRequest{} - args.AllowStale = true - args.Operation = structs.KeyringList + args := structs.KeyringRequest{Operation: structs.KeyringList} return a.keyringProcess("Internal.KeyringOperation", &args) } // InstallKey installs a new gossip encryption key func (a *Agent) InstallKey(key string) (*structs.KeyringResponses, error) { - args := structs.KeyringRequest{Key: key} - args.AllowStale = true - args.Operation = structs.KeyringInstall + args := structs.KeyringRequest{Key: key, Operation: structs.KeyringInstall} return a.keyringProcess("Internal.KeyringOperation", &args) } // UseKey changes the primary encryption key used to encrypt messages func (a *Agent) UseKey(key string) (*structs.KeyringResponses, error) { - args := structs.KeyringRequest{Key: key} - args.AllowStale = true - args.Operation = structs.KeyringUse + args := structs.KeyringRequest{Key: key, Operation: structs.KeyringUse} return a.keyringProcess("Internal.KeyringOperation", &args) } // RemoveKey will remove a gossip encryption key from the keyring func (a *Agent) RemoveKey(key string) (*structs.KeyringResponses, error) { - args := structs.KeyringRequest{Key: key} - args.AllowStale = true - args.Operation = structs.KeyringRemove + args := structs.KeyringRequest{Key: key, Operation: structs.KeyringRemove} return a.keyringProcess("Internal.KeyringOperation", &args) } diff --git a/consul/internal_endpoint.go b/consul/internal_endpoint.go index 50109f88d3..055e450c71 100644 --- a/consul/internal_endpoint.go +++ b/consul/internal_endpoint.go @@ -12,15 +12,6 @@ type Internal struct { srv *Server } -type KeyringOperation uint8 - -const ( - listKeysOperation KeyringOperation = iota - installKeyOperation - useKeyOperation - removeKeyOperation -) - // ChecksInState is used to get all the checks in a given state func (m *Internal) NodeInfo(args *structs.NodeSpecificRequest, reply *structs.IndexedNodeDump) error {