瀏覽代碼

optionnaly fix TLS certificate problems with new insecure option

Yves Mettier 4 年之前
父節點
當前提交
20796af22e
共有 5 個檔案被更改,包括 17 行新增4 行删除
  1. 4
    0
      config.example.yaml
  2. 1
    0
      src/config/config.go
  3. 10
    2
      src/grafana/client.go
  4. 1
    1
      src/puller/main.go
  5. 1
    1
      src/pusher/main.go

+ 4
- 0
config.example.yaml 查看文件

9
     # ignored by both the puller and the pusher. This setting is
9
     # ignored by both the puller and the pusher. This setting is
10
     # case-insensitive and optional.
10
     # case-insensitive and optional.
11
     ignore_prefix: test
11
     ignore_prefix: test
12
+    # If set, skip verification of the TLS certificates
13
+    # You should not set it in Production environments
14
+    # boolean and optional.
15
+    insecure: false
12
 
16
 
13
 
17
 
14
 # Settings to interact with the Git repository. Currently only SSH repos are
18
 # Settings to interact with the Git repository. Currently only SSH repos are

+ 1
- 0
src/config/config.go 查看文件

28
 // GrafanaSettings contains the data required to talk to the Grafana HTTP API.
28
 // GrafanaSettings contains the data required to talk to the Grafana HTTP API.
29
 type GrafanaSettings struct {
29
 type GrafanaSettings struct {
30
 	BaseURL      string `yaml:"base_url"`
30
 	BaseURL      string `yaml:"base_url"`
31
+	Insecure     bool   `yaml:"insecure,omitempty"`
31
 	APIKey       string `yaml:"api_key"`
32
 	APIKey       string `yaml:"api_key"`
32
 	IgnorePrefix string `yaml:"ignore_prefix,omitempty"`
33
 	IgnorePrefix string `yaml:"ignore_prefix,omitempty"`
33
 }
34
 }

+ 10
- 2
src/grafana/client.go 查看文件

4
 	"bytes"
4
 	"bytes"
5
 	"fmt"
5
 	"fmt"
6
 	"io/ioutil"
6
 	"io/ioutil"
7
+	"crypto/tls"
7
 	"net/http"
8
 	"net/http"
8
 	"strings"
9
 	"strings"
9
 
10
 
19
 }
20
 }
20
 
21
 
21
 // NewClient returns a new Grafana API client from a given base URL and API key.
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
 	// Grafana doesn't support double slashes in the API routes, so we strip the
24
 	// Grafana doesn't support double slashes in the API routes, so we strip the
24
 	// last slash if there's one, because request() will append one anyway.
25
 	// last slash if there's one, because request() will append one anyway.
25
 	if strings.HasSuffix(baseURL, "/") {
26
 	if strings.HasSuffix(baseURL, "/") {
26
 		baseURL = baseURL[:len(baseURL)-1]
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
 	return &Client{
37
 	return &Client{
30
 		BaseURL:    baseURL,
38
 		BaseURL:    baseURL,
31
 		APIKey:     apiKey,
39
 		APIKey:     apiKey,
32
-		httpClient: new(http.Client),
40
+		httpClient: cl,
33
 	}
41
 	}
34
 }
42
 }
35
 
43
 

+ 1
- 1
src/puller/main.go 查看文件

38
 	}).Info("Sync mode set")
38
 	}).Info("Sync mode set")
39
 
39
 
40
 	// Initialise the Grafana API client.
40
 	// Initialise the Grafana API client.
41
-	client := grafana.NewClient(cfg.Grafana.BaseURL, cfg.Grafana.APIKey)
41
+	client := grafana.NewClient(cfg.Grafana.BaseURL, cfg.Grafana.APIKey, cfg.Grafana.Insecure)
42
 	// Run the puller.
42
 	// Run the puller.
43
 	if err := PullGrafanaAndCommit(client, cfg); err != nil {
43
 	if err := PullGrafanaAndCommit(client, cfg); err != nil {
44
 		logrus.Panic(err)
44
 		logrus.Panic(err)

+ 1
- 1
src/pusher/main.go 查看文件

40
 	}
40
 	}
41
 
41
 
42
 	// Initialise the Grafana API client.
42
 	// Initialise the Grafana API client.
43
-	grafanaClient := grafana.NewClient(cfg.Grafana.BaseURL, cfg.Grafana.APIKey)
43
+	grafanaClient := grafana.NewClient(cfg.Grafana.BaseURL, cfg.Grafana.APIKey, cfg.Grafana.Insecure)
44
 
44
 
45
 	// Set up either a webhook or a poller depending on the mode specified in the
45
 	// Set up either a webhook or a poller depending on the mode specified in the
46
 	// configuration file.
46
 	// configuration file.