|
@@ -4,6 +4,7 @@ import (
|
4
|
4
|
"bytes"
|
5
|
5
|
"fmt"
|
6
|
6
|
"io/ioutil"
|
|
7
|
+ "crypto/tls"
|
7
|
8
|
"net/http"
|
8
|
9
|
"strings"
|
9
|
10
|
|
|
@@ -19,17 +20,24 @@ type Client struct {
|
19
|
20
|
}
|
20
|
21
|
|
21
|
22
|
// NewClient returns a new Grafana API client from a given base URL and API key.
|
22
|
|
-func NewClient(baseURL string, apiKey string) (c *Client) {
|
|
23
|
+func NewClient(baseURL string, apiKey string, insecure bool) (c *Client) {
|
23
|
24
|
// Grafana doesn't support double slashes in the API routes, so we strip the
|
24
|
25
|
// last slash if there's one, because request() will append one anyway.
|
25
|
26
|
if strings.HasSuffix(baseURL, "/") {
|
26
|
27
|
baseURL = baseURL[:len(baseURL)-1]
|
27
|
28
|
}
|
28
|
29
|
|
|
30
|
+ cl := new(http.Client)
|
|
31
|
+ if insecure {
|
|
32
|
+ tr := &http.Transport{
|
|
33
|
+ TLSClientConfig: &tls.Config{InsecureSkipVerify : true},
|
|
34
|
+ }
|
|
35
|
+ cl.Transport = tr
|
|
36
|
+ }
|
29
|
37
|
return &Client{
|
30
|
38
|
BaseURL: baseURL,
|
31
|
39
|
APIKey: apiKey,
|
32
|
|
- httpClient: new(http.Client),
|
|
40
|
+ httpClient: cl,
|
33
|
41
|
}
|
34
|
42
|
}
|
35
|
43
|
|