From a25c8174780d06d8701916729a0c2b9af84bee7f Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Thu, 24 Jun 2021 14:38:29 -0400 Subject: [PATCH] tlsutil: remove indirection and duplication VerifyIncomingRPC and verifyIncomingRPC were duplicate functions, and once one is removed, Config.verifyIncomingRPC is only called in one place. Remove 2 of the 3 functions to make the behaviour easier to follow (less indirection). --- tlsutil/config.go | 18 ++++-------------- tlsutil/config_test.go | 2 +- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/tlsutil/config.go b/tlsutil/config.go index 7c661c9408..d933219a61 100644 --- a/tlsutil/config.go +++ b/tlsutil/config.go @@ -397,10 +397,6 @@ func (c Config) anyVerifyIncoming() bool { return c.VerifyIncoming || c.VerifyIncomingRPC || c.VerifyIncomingHTTPS } -func (c Config) verifyIncomingRPC() bool { - return c.VerifyIncoming || c.VerifyIncomingRPC -} - func loadKeyPair(certFile, keyFile string) (*tls.Certificate, error) { if certFile == "" || keyFile == "" { return nil, nil @@ -532,11 +528,12 @@ func (c *Configurator) Cert() *tls.Certificate { return cert } -// This function acquires a read lock because it reads from the config. +// VerifyIncomingRPC returns true if the configuration has enabled either +// VerifyIncoming, or VerifyIncomingRPC func (c *Configurator) VerifyIncomingRPC() bool { c.lock.RLock() defer c.lock.RUnlock() - return c.base.verifyIncomingRPC() + return c.base.VerifyIncoming || c.base.VerifyIncomingRPC } // This function acquires a read lock because it reads from the config. @@ -597,13 +594,6 @@ func (c *Configurator) domain() string { return c.base.Domain } -// This function acquires a read lock because it reads from the config. -func (c *Configurator) verifyIncomingRPC() bool { - c.lock.RLock() - defer c.lock.RUnlock() - return c.base.verifyIncomingRPC() -} - // This function acquires a read lock because it reads from the config. func (c *Configurator) verifyIncomingHTTPS() bool { c.lock.RLock() @@ -647,7 +637,7 @@ func (c *Configurator) IncomingGRPCConfig() *tls.Config { // IncomingRPCConfig generates a *tls.Config for incoming RPC connections. func (c *Configurator) IncomingRPCConfig() *tls.Config { c.log("IncomingRPCConfig") - config := c.commonTLSConfig(c.verifyIncomingRPC()) + config := c.commonTLSConfig(c.VerifyIncomingRPC()) config.GetConfigForClient = func(*tls.ClientHelloInfo) (*tls.Config, error) { return c.IncomingRPCConfig(), nil } diff --git a/tlsutil/config_test.go b/tlsutil/config_test.go index d55aed56c1..8ca985186c 100644 --- a/tlsutil/config_test.go +++ b/tlsutil/config_test.go @@ -846,7 +846,7 @@ func TestConfigurator_VerifyIncomingRPC(t *testing.T) { c := Configurator{base: &Config{ VerifyIncomingRPC: true, }} - verify := c.verifyIncomingRPC() + verify := c.VerifyIncomingRPC() require.Equal(t, c.base.VerifyIncomingRPC, verify) }