forked from aws/aws-sdk-go-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_client.go
42 lines (34 loc) · 867 Bytes
/
http_client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package external
import (
"crypto/tls"
"crypto/x509"
"net/http"
"github.com/aws/aws-sdk-go-v2/aws/awserr"
)
func addHTTPClientCABundle(client *http.Client, pemCerts []byte) error {
var t *http.Transport
switch v := client.Transport.(type) {
case *http.Transport:
t = v
default:
if client.Transport != nil {
return awserr.New("LoadCustomCABundleError",
"unable to set custom CA bundle trasnsport must be http.Transport type", nil)
}
}
if t == nil {
t = &http.Transport{}
}
if t.TLSClientConfig == nil {
t.TLSClientConfig = &tls.Config{}
}
if t.TLSClientConfig.RootCAs == nil {
t.TLSClientConfig.RootCAs = x509.NewCertPool()
}
if !t.TLSClientConfig.RootCAs.AppendCertsFromPEM(pemCerts) {
return awserr.New("LoadCustomCABundleError",
"failed to load custom CA bundle PEM file", nil)
}
client.Transport = t
return nil
}