Skip to content

Commit d865626

Browse files
committed
Allow Cert and Key pair to be optional
I.e. if we just want to pass in the CA cert.
1 parent 0c228aa commit d865626

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

client/tls.go

+19-9
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,26 @@ func NewClientTLSConfig(caPem, certPem, keyPem []byte, insecureSkipVerify bool,
1313
panic("failed to add ca PEM")
1414
}
1515

16-
cert, err := tls.X509KeyPair(certPem, keyPem)
17-
if err != nil {
18-
panic(err)
19-
}
16+
var config *tls.Config
2017

21-
config := &tls.Config{
22-
Certificates: []tls.Certificate{cert},
23-
RootCAs: pool,
24-
InsecureSkipVerify: insecureSkipVerify,
25-
ServerName: serverName,
18+
if string(certPem) != "" && string(keyPem) != "" {
19+
cert, err := tls.X509KeyPair(certPem, keyPem)
20+
if err != nil {
21+
panic(err)
22+
}
23+
config = &tls.Config{
24+
RootCAs: pool,
25+
Certificates: []tls.Certificate{cert},
26+
InsecureSkipVerify: insecureSkipVerify,
27+
ServerName: serverName,
28+
}
29+
} else {
30+
config = &tls.Config{
31+
RootCAs: pool,
32+
InsecureSkipVerify: insecureSkipVerify,
33+
ServerName: serverName,
34+
}
2635
}
36+
2737
return config
2838
}

0 commit comments

Comments
 (0)