Skip to content

Commit b2f8540

Browse files
committed
Use go-rootcerts to configure TLS
Allows configuration of the CA certs for the Atlas connection via environment variables `ATLAS_CAFILE` or `ATLAS_CAPATH`. Also catches the workaround for golang/go#14514 in go-rootcerts so that OS X clients behave properly.
1 parent 0008886 commit b2f8540

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

v1/client.go

+18
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"strings"
1515

1616
"github.com/hashicorp/go-cleanhttp"
17+
"github.com/hashicorp/go-rootcerts"
1718
)
1819

1920
const (
@@ -24,6 +25,14 @@ const (
2425
// default Atlas address.
2526
atlasEndpointEnvVar = "ATLAS_ADDRESS"
2627

28+
// atlasCAFileEnvVar is the environment variable that causes the client to
29+
// load trusted certs from a file
30+
atlasCAFileEnvVar = "ATLAS_CAFILE"
31+
32+
// atlasCAPathEnvVar is the environment variable that causes the client to
33+
// load trusted certs from a directory
34+
atlasCAPathEnvVar = "ATLAS_CAPATH"
35+
2736
// atlasTokenHeader is the header key used for authenticating with Atlas
2837
atlasTokenHeader = "X-Atlas-Token"
2938
)
@@ -112,6 +121,15 @@ func NewClient(urlString string) (*Client, error) {
112121
// init() sets defaults on the client.
113122
func (c *Client) init() error {
114123
c.HTTPClient = cleanhttp.DefaultClient()
124+
t := cleanhttp.DefaultTransport()
125+
err := rootcerts.ConfigureTLS(t.TLSClientConfig, &rootcerts.Config{
126+
CAFile: os.Getenv(atlasCAFileEnvVar),
127+
CAPath: os.Getenv(atlasCAPathEnvVar),
128+
})
129+
if err != nil {
130+
return err
131+
}
132+
c.HTTPClient.Transport = t
115133
return nil
116134
}
117135

0 commit comments

Comments
 (0)