chore: refactor CreateTLSConfig

pull/5672/head
Pavel Zavora 2021-02-24 10:58:54 +01:00
parent 97089205a5
commit 7bc29c22e8
3 changed files with 6 additions and 5 deletions

View File

@ -488,7 +488,7 @@ func (s *Server) NewListener() (net.Listener, error) {
return listener, nil
}
tlsConfig, err := createTLSConfig(tlsOptions{
tlsConfig, err := CreateTLSConfig(tlsOptions{
Cert: string(s.Cert),
Key: string(s.Key),
Ciphers: strings.Split(s.TLSCiphers, ","),
@ -621,7 +621,7 @@ func (s *Server) Serve(ctx context.Context) {
} else {
var tlsConfig *tls.Config
if s.EtcdCert != "" {
tlsConfig, err = createTLSConfig(tlsOptions{
tlsConfig, err = CreateTLSConfig(tlsOptions{
Cert: string(s.EtcdCert),
Key: string(s.EtcdKey),
})

View File

@ -63,7 +63,8 @@ var versionsMap = map[string]uint16{
"1.3": tls.VersionTLS13,
}
func createTLSConfig(o tlsOptions) (out *tls.Config, err error) {
// CreateTLSConfig creates TLS configuration out of specific TLS
func CreateTLSConfig(o tlsOptions) (out *tls.Config, err error) {
// load key pair
if o.Cert == "" {
return nil, errors.New("no TLS certificate specified")

View File

@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require"
)
func Test_createTLSConfig(t *testing.T) {
func Test_CreateTLSConfig(t *testing.T) {
var tests = []struct {
name string
in tlsOptions
@ -143,7 +143,7 @@ func Test_createTLSConfig(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
config, err := createTLSConfig(test.in)
config, err := CreateTLSConfig(test.in)
if test.err == "" {
require.Nil(t, err)
require.NotNil(t, config.Certificates)