From 55a513da2e91234fba9b4e4235c9cc3213a6412d Mon Sep 17 00:00:00 2001 From: Frank Schroeder Date: Fri, 2 Jun 2017 11:35:59 +0200 Subject: [PATCH] agent: add GossipEncrypted function Remove dead code and expose a GossipEncrypted() method on the agent instead of accessing the internal delegate. --- command/agent/agent.go | 4 ++++ command/agent/command.go | 24 +----------------------- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/command/agent/agent.go b/command/agent/agent.go index 3f40aa4c45..406e9ed068 100644 --- a/command/agent/agent.go +++ b/command/agent/agent.go @@ -1817,6 +1817,10 @@ func (a *Agent) purgeCheckState(checkID types.CheckID) error { return err } +func (a *Agent) GossipEncrypted() bool { + return a.delegate.Encrypted() +} + // Stats is used to get various debugging state from the sub-systems func (a *Agent) Stats() map[string]map[string]string { toString := func(v uint64) string { diff --git a/command/agent/command.go b/command/agent/command.go index e89ce2b23b..67999a3d9e 100644 --- a/command/agent/command.go +++ b/command/agent/command.go @@ -17,7 +17,6 @@ import ( "github.com/armon/go-metrics/circonus" "github.com/armon/go-metrics/datadog" "github.com/hashicorp/consul/command/base" - "github.com/hashicorp/consul/consul" "github.com/hashicorp/consul/consul/structs" "github.com/hashicorp/consul/ipaddr" "github.com/hashicorp/consul/lib" @@ -596,24 +595,6 @@ func (cmd *Command) retryJoinWan(cfg *Config, errCh chan<- struct{}) { } } -// gossipEncrypted determines if the consul instance is using symmetric -// encryption keys to protect gossip protocol messages. -func (cmd *Command) gossipEncrypted() bool { - if cmd.agent.config.EncryptKey != "" { - return true - } - - server, ok := cmd.agent.delegate.(*consul.Server) - if ok { - return server.KeyManagerLAN() != nil || server.KeyManagerWAN() != nil - } - client, ok := cmd.agent.delegate.(*consul.Client) - if ok { - return client != nil && client.KeyManagerLAN() != nil - } - panic(fmt.Sprintf("delegate is neither server nor client: %T", cmd.agent.delegate)) -} - func (cmd *Command) Run(args []string) int { cmd.UI = &cli.PrefixedUi{ OutputPrefix: "==> ", @@ -817,9 +798,6 @@ func (cmd *Command) Run(args []string) int { }(wp) } - // Figure out if gossip is encrypted - gossipEncrypted := cmd.agent.delegate.Encrypted() - // Let the agent know we've finished registration cmd.agent.StartSync() @@ -834,7 +812,7 @@ func (cmd *Command) Run(args []string) int { cmd.UI.Info(fmt.Sprintf(" Cluster Addr: %v (LAN: %d, WAN: %d)", config.AdvertiseAddr, config.Ports.SerfLan, config.Ports.SerfWan)) cmd.UI.Info(fmt.Sprintf("Gossip encrypt: %v, RPC-TLS: %v, TLS-Incoming: %v", - gossipEncrypted, config.VerifyOutgoing, config.VerifyIncoming)) + cmd.agent.GossipEncrypted(), config.VerifyOutgoing, config.VerifyIncoming)) // Enable log streaming cmd.UI.Info("")