Kaynağa Gözat

optionnaly fix TLS certificate problems with new insecure option

Yves Mettier 4 yıl önce
ebeveyn
işleme
20796af22e
5 değiştirilmiş dosya ile 17 ekleme ve 4 silme
  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 Dosyayı Görüntüle

@@ -9,6 +9,10 @@ grafana:
9 9
     # ignored by both the puller and the pusher. This setting is
10 10
     # case-insensitive and optional.
11 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 18
 # Settings to interact with the Git repository. Currently only SSH repos are

+ 1
- 0
src/config/config.go Dosyayı Görüntüle

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

+ 10
- 2
src/grafana/client.go Dosyayı Görüntüle

@@ -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
 

+ 1
- 1
src/puller/main.go Dosyayı Görüntüle

@@ -38,7 +38,7 @@ func main() {
38 38
 	}).Info("Sync mode set")
39 39
 
40 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 42
 	// Run the puller.
43 43
 	if err := PullGrafanaAndCommit(client, cfg); err != nil {
44 44
 		logrus.Panic(err)

+ 1
- 1
src/pusher/main.go Dosyayı Görüntüle

@@ -40,7 +40,7 @@ func main() {
40 40
 	}
41 41
 
42 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 45
 	// Set up either a webhook or a poller depending on the mode specified in the
46 46
 	// configuration file.