From 9c932c6837292002c1d77ec7b7fc25050f1ff5c1 Mon Sep 17 00:00:00 2001 From: "BARRY Thierno Ibrahima (Canal Plus Prestataire)" Date: Mon, 5 Oct 2020 18:46:34 +0200 Subject: [PATCH] use system CA or ca_certificate, but not both --- internal/provider/data_source.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/provider/data_source.go b/internal/provider/data_source.go index 0249b74a..a7b5f5ee 100644 --- a/internal/provider/data_source.go +++ b/internal/provider/data_source.go @@ -71,15 +71,16 @@ func dataSourceRead(ctx context.Context, d *schema.ResourceData, meta interface{ caCert := d.Get("ca_certificate").(string) // Get the System Cert Pool - caCertPool, _ := x509.SystemCertPool() - if caCertPool == nil { - caCertPool = x509.NewCertPool() + caCertPool, err := x509.SystemCertPool() + if err != nil { + return fmt.Errorf("Error tls: %s", err) } - // Append `ca_certificate` to the system CA cert pool + // Use `ca_certificate` cert pool if caCert != "" { + caCertPool = x509.NewCertPool() if ok := caCertPool.AppendCertsFromPEM([]byte(caCert)); !ok { - return fmt.Errorf("Error when adding CA certificate to certificate pool") + return fmt.Errorf("Error tls: Can't add the CA certificate to certificate pool") } }