|
|
|
|
@ -34,6 +34,11 @@ const (
|
|
|
|
|
// load trusted certs from a directory
|
|
|
|
|
atlasCAPathEnvVar = "ATLAS_CAPATH"
|
|
|
|
|
|
|
|
|
|
// atlasTLSNoVerifyEnvVar disables TLS verification, similar to curl -k
|
|
|
|
|
// This defaults to false (verify) and will change to true (skip
|
|
|
|
|
// verification) with any non-empty value
|
|
|
|
|
atlasTLSNoVerifyEnvVar = "ATLAS_TLS_NOVERIFY"
|
|
|
|
|
|
|
|
|
|
// atlasTokenHeader is the header key used for authenticating with Atlas
|
|
|
|
|
atlasTokenHeader = "X-Atlas-Token"
|
|
|
|
|
)
|
|
|
|
|
@ -70,6 +75,10 @@ type Client struct {
|
|
|
|
|
|
|
|
|
|
// HTTPClient is the underlying http client with which to make requests.
|
|
|
|
|
HTTPClient *http.Client
|
|
|
|
|
|
|
|
|
|
// DefaultHeaders is a set of headers that will be added to every request.
|
|
|
|
|
// This minimally includes the atlas user-agent string.
|
|
|
|
|
DefaultHeader http.Header
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DefaultClient returns a client that connects to the Atlas API.
|
|
|
|
|
@ -108,10 +117,13 @@ func NewClient(urlString string) (*Client, error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
client := &Client{
|
|
|
|
|
URL: parsedURL,
|
|
|
|
|
Token: token,
|
|
|
|
|
URL: parsedURL,
|
|
|
|
|
Token: token,
|
|
|
|
|
DefaultHeader: make(http.Header),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
client.DefaultHeader.Set("User-Agent", userAgent)
|
|
|
|
|
|
|
|
|
|
if err := client.init(); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
@ -123,6 +135,9 @@ func NewClient(urlString string) (*Client, error) {
|
|
|
|
|
func (c *Client) init() error {
|
|
|
|
|
c.HTTPClient = cleanhttp.DefaultClient()
|
|
|
|
|
tlsConfig := &tls.Config{}
|
|
|
|
|
if os.Getenv(atlasTLSNoVerifyEnvVar) != "" {
|
|
|
|
|
tlsConfig.InsecureSkipVerify = true
|
|
|
|
|
}
|
|
|
|
|
err := rootcerts.ConfigureTLS(tlsConfig, &rootcerts.Config{
|
|
|
|
|
CAFile: os.Getenv(atlasCAFileEnvVar),
|
|
|
|
|
CAPath: os.Getenv(atlasCAPathEnvVar),
|
|
|
|
|
@ -227,10 +242,12 @@ func (c *Client) rawRequest(verb string, u *url.URL, ro *RequestOptions) (*http.
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set the User-Agent
|
|
|
|
|
request.Header.Set("User-Agent", userAgent)
|
|
|
|
|
// set our default headers first
|
|
|
|
|
for k, v := range c.DefaultHeader {
|
|
|
|
|
request.Header[k] = v
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add any headers (auth will be here if set)
|
|
|
|
|
// Add any request headers (auth will be here if set)
|
|
|
|
|
for k, v := range ro.Headers {
|
|
|
|
|
request.Header.Add(k, v)
|
|
|
|
|
}
|
|
|
|
|
|