From 5e3a85976d4526e8f93ea1b44e60309da45f8b68 Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Fri, 13 May 2022 16:32:51 +0200 Subject: [PATCH] Expect serverName only in TLS.MakeConfig() With recent changes to Unix domain socket support, port and address handling in SQL and Redis configuration, the function can now be reduced to just expecting the server name. --- pkg/config/config.go | 11 +++-------- pkg/config/database.go | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 89e040b4..1388ba93 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -8,7 +8,6 @@ import ( "github.com/jessevdk/go-flags" "github.com/pkg/errors" "io/ioutil" - "net" "os" ) @@ -94,8 +93,8 @@ type TLS struct { Insecure bool `yaml:"insecure"` } -// MakeConfig assembles a tls.Config from t and address. -func (t *TLS) MakeConfig(address string) (*tls.Config, error) { +// MakeConfig assembles a tls.Config from t and serverName. +func (t *TLS) MakeConfig(serverName string) (*tls.Config, error) { if !t.Enable { return nil, nil } @@ -130,11 +129,7 @@ func (t *TLS) MakeConfig(address string) (*tls.Config, error) { } } - if host, _, err := net.SplitHostPort(address); err == nil { - tlsConfig.ServerName = host - } else { - tlsConfig.ServerName = address - } + tlsConfig.ServerName = serverName return tlsConfig, nil } diff --git a/pkg/config/database.go b/pkg/config/database.go index 9766af5b..b42ff8e1 100644 --- a/pkg/config/database.go +++ b/pkg/config/database.go @@ -63,7 +63,7 @@ func (d *Database) Open(logger *logging.Logger) (*icingadb.DB, error) { config.Timeout = time.Minute config.Params = map[string]string{"sql_mode": "ANSI_QUOTES"} - tlsConfig, err := d.TlsOptions.MakeConfig(config.Addr) + tlsConfig, err := d.TlsOptions.MakeConfig(d.Host) if err != nil { return nil, err }