Skip to content

Commit 1b684b5

Browse files
authored
fix: allow specify root ca without client/key (#41)
Signed-off-by: Raffael Sahli <[email protected]> Signed-off-by: Raffael Sahli <[email protected]>
1 parent a3dc868 commit 1b684b5

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

pkg/sinks/sink.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,22 @@ type TLS struct {
3535
}
3636

3737
func setupTLS(cfg *TLS) (*tls.Config, error) {
38-
var caCert []byte
38+
tlsClientConfig := &tls.Config{
39+
InsecureSkipVerify: cfg.InsecureSkipVerify,
40+
ServerName: cfg.ServerName,
41+
}
3942

4043
if len(cfg.CaFile) > 0 {
4144
readFile, err := ioutil.ReadFile(cfg.CaFile)
4245
if err != nil {
4346
return nil, err
4447
}
45-
caCert = readFile
46-
}
4748

48-
tlsClientConfig := &tls.Config{
49-
InsecureSkipVerify: cfg.InsecureSkipVerify,
50-
ServerName: cfg.ServerName,
51-
}
52-
if len(cfg.KeyFile) > 0 && len(cfg.CertFile) > 0 {
5349
tlsClientConfig.RootCAs = x509.NewCertPool()
54-
tlsClientConfig.RootCAs.AppendCertsFromPEM(caCert)
50+
tlsClientConfig.RootCAs.AppendCertsFromPEM(readFile)
51+
}
5552

53+
if len(cfg.KeyFile) > 0 && len(cfg.CertFile) > 0 {
5654
cert, err := tls.LoadX509KeyPair(cfg.CertFile, cfg.KeyFile)
5755
if err != nil {
5856
return nil, fmt.Errorf("could not read client certificate or key: %w", err)

0 commit comments

Comments
 (0)