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.
This commit is contained in:
Eric Lippmann 2022-05-13 16:32:51 +02:00
parent 399b6a3d32
commit 5e3a85976d
2 changed files with 4 additions and 9 deletions

View file

@ -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
}

View file

@ -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
}