Skip to content

Commit 3da5557

Browse files
committed
Load tls configs in healthcheck
1 parent 7a66e3e commit 3da5557

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pkg/plugin/datasource.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ func tlsSetup(config *models.PluginSettings) (*tls.Config, error) {
8282
certFile := config.ClientCertPath
8383
keyFile := config.ClientKeyPath
8484

85+
if caFile == "" || certFile == "" || keyFile == "" {
86+
return nil, errors.New("CA certificate, client certificate or client key file path is missing")
87+
}
88+
8589
// Loads CA certificate file
8690
caCert, err := os.ReadFile(caFile)
8791
if err != nil {
@@ -249,6 +253,20 @@ func (d *Datasource) CheckHealth(ctx context.Context, req *backend.CheckHealthRe
249253
}
250254

251255
opts := options.Client().ApplyURI(uri).SetTimeout(5 * time.Second)
256+
257+
if config.AuthMethod == "auth-tls-ssl" {
258+
// TLS setup
259+
tlsConfig, err := tlsSetup(config)
260+
if err != nil {
261+
backend.Logger.Error("Failed to setup TLS", "error", err)
262+
263+
res.Status = backend.HealthStatusError
264+
res.Message = err.Error()
265+
return res, nil
266+
}
267+
opts.SetTLSConfig(tlsConfig)
268+
}
269+
252270
client, err := mongo.Connect(ctx, opts)
253271
if err != nil {
254272
res.Status = backend.HealthStatusError

0 commit comments

Comments
 (0)