@@ -2,6 +2,7 @@ package atlas
2
2
3
3
import (
4
4
"bytes"
5
+ "crypto/tls"
5
6
"encoding/json"
6
7
"fmt"
7
8
"io"
@@ -14,6 +15,7 @@ import (
14
15
"strings"
15
16
16
17
"github.com/hashicorp/go-cleanhttp"
18
+ "github.com/hashicorp/go-rootcerts"
17
19
)
18
20
19
21
const (
@@ -24,6 +26,14 @@ const (
24
26
// default Atlas address.
25
27
atlasEndpointEnvVar = "ATLAS_ADDRESS"
26
28
29
+ // atlasCAFileEnvVar is the environment variable that causes the client to
30
+ // load trusted certs from a file
31
+ atlasCAFileEnvVar = "ATLAS_CAFILE"
32
+
33
+ // atlasCAPathEnvVar is the environment variable that causes the client to
34
+ // load trusted certs from a directory
35
+ atlasCAPathEnvVar = "ATLAS_CAPATH"
36
+
27
37
// atlasTokenHeader is the header key used for authenticating with Atlas
28
38
atlasTokenHeader = "X-Atlas-Token"
29
39
)
@@ -112,6 +122,17 @@ func NewClient(urlString string) (*Client, error) {
112
122
// init() sets defaults on the client.
113
123
func (c * Client ) init () error {
114
124
c .HTTPClient = cleanhttp .DefaultClient ()
125
+ tlsConfig := & tls.Config {}
126
+ err := rootcerts .ConfigureTLS (tlsConfig , & rootcerts.Config {
127
+ CAFile : os .Getenv (atlasCAFileEnvVar ),
128
+ CAPath : os .Getenv (atlasCAPathEnvVar ),
129
+ })
130
+ if err != nil {
131
+ return err
132
+ }
133
+ t := cleanhttp .DefaultTransport ()
134
+ t .TLSClientConfig = tlsConfig
135
+ c .HTTPClient .Transport = t
115
136
return nil
116
137
}
117
138
0 commit comments