Skip to content

Commit

Permalink
use system CA or ca_certificate, but not both
Browse files Browse the repository at this point in the history
  • Loading branch information
BARRY Thierno Ibrahima (Canal Plus Prestataire) committed May 4, 2021
1 parent 3754f48 commit 0a84c06
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions internal/provider/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down

0 comments on commit 0a84c06

Please sign in to comment.