From b4bc74322a371e5928b064f01d3e50d75d9147ac Mon Sep 17 00:00:00 2001 From: Shubheksha Jalan Date: Thu, 11 Jan 2018 02:47:24 +0530 Subject: [PATCH 1/3] export HTTPClientConfig's validate() method --- config/http_config.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/config/http_config.go b/config/http_config.go index ff5837fa..95525901 100644 --- a/config/http_config.go +++ b/config/http_config.go @@ -22,7 +22,7 @@ import ( "net/url" "strings" - yaml "gopkg.in/yaml.v2" + "gopkg.in/yaml.v2" ) // BasicAuth contains basic HTTP authentication credentials. @@ -79,7 +79,9 @@ type HTTPClientConfig struct { XXX map[string]interface{} `yaml:",inline"` } -func (c *HTTPClientConfig) validate() error { +// Validate validates the HTTPClientConfig to check only one of BearerToken, +// BasicAuth and BearerTokenFile is configured. +func (c *HTTPClientConfig) Validate() error { if len(c.BearerToken) > 0 && len(c.BearerTokenFile) > 0 { return fmt.Errorf("at most one of bearer_token & bearer_token_file must be configured") } @@ -96,9 +98,9 @@ func (c *HTTPClientConfig) UnmarshalYAML(unmarshal func(interface{}) error) erro if err != nil { return err } - err = c.validate() + err = c.Validate() if err != nil { - return c.validate() + return c.Validate() } return checkOverflow(c.XXX, "http_client_config") } @@ -210,7 +212,7 @@ func cloneRequest(r *http.Request) *http.Request { func NewTLSConfig(cfg *TLSConfig) (*tls.Config, error) { tlsConfig := &tls.Config{InsecureSkipVerify: cfg.InsecureSkipVerify} - // If a CA cert is provided then let's read it in so we can validate the + // If a CA cert is provided then let's read it in so we can Validate the // scrape target's certificate properly. if len(cfg.CAFile) > 0 { caCertPool := x509.NewCertPool() From 93dfbf7d11147acbd020f8e0cf1e8377c107d567 Mon Sep 17 00:00:00 2001 From: Shubheksha Jalan Date: Thu, 11 Jan 2018 02:51:36 +0530 Subject: [PATCH 2/3] nit: fix case in comment --- config/http_config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/http_config.go b/config/http_config.go index 95525901..ea231bf8 100644 --- a/config/http_config.go +++ b/config/http_config.go @@ -212,7 +212,7 @@ func cloneRequest(r *http.Request) *http.Request { func NewTLSConfig(cfg *TLSConfig) (*tls.Config, error) { tlsConfig := &tls.Config{InsecureSkipVerify: cfg.InsecureSkipVerify} - // If a CA cert is provided then let's read it in so we can Validate the + // If a CA cert is provided then let's read it in so we can validate the // scrape target's certificate properly. if len(cfg.CAFile) > 0 { caCertPool := x509.NewCertPool() From 9b1efffa3e2b6a17ab0ec6ec87783ec88b2392f4 Mon Sep 17 00:00:00 2001 From: Shubheksha Jalan Date: Thu, 11 Jan 2018 02:58:27 +0530 Subject: [PATCH 3/3] fix tests to use exported method Validate() --- config/http_config_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/http_config_test.go b/config/http_config_test.go index 1e2490bb..4b13e101 100644 --- a/config/http_config_test.go +++ b/config/http_config_test.go @@ -114,7 +114,7 @@ func TestValidateHTTPConfig(t *testing.T) { if err != nil { t.Errorf("Error loading HTTP client config: %v", err) } - err = cfg.validate() + err = cfg.Validate() if err != nil { t.Fatalf("Error validating %s: %s", "testdata/http.conf.good.yml", err) }