From b212b965008ca40e9f59eddc75620e8a3fdb44e4 Mon Sep 17 00:00:00 2001 From: Jake Trotman Date: Tue, 6 Jun 2017 08:48:02 -0500 Subject: [PATCH 1/2] adding TLS Client config --- api/client.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/api/client.go b/api/client.go index 936ffef1..08f06d62 100644 --- a/api/client.go +++ b/api/client.go @@ -1,6 +1,7 @@ package api import ( + "crypto/tls" "fmt" "github.com/tomnomnom/linkheader" @@ -32,9 +33,10 @@ type ErrorDetail struct { // Config contains all the configuration data for the API Client type Config struct { - APIKey string - BaseURL string - Debug bool + APIKey string + BaseURL string + Debug bool + TLSConfig *tls.Config } // New returns a new Client for the specified apiKey. @@ -49,6 +51,9 @@ func New(config Config) Client { r.SetHeader("X-Api-Key", config.APIKey) r.SetHostURL(baseURL) + if config.TLSConfig != nil { + r.SetTLSClientConfig(config.TLSConfig) + } if config.Debug { r.SetDebug(true) } From 7c5c37993ad44d133b4fb986a5c431e6105f673b Mon Sep 17 00:00:00 2001 From: Jake Trotman Date: Tue, 6 Jun 2017 08:59:39 -0500 Subject: [PATCH 2/2] added a test for including a TLSConfig --- api/client_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/api/client_test.go b/api/client_test.go index ad8429f5..dbf88893 100644 --- a/api/client_test.go +++ b/api/client_test.go @@ -1,6 +1,7 @@ package api import ( + "crypto/tls" "net/http" "net/http/httptest" ) @@ -16,3 +17,19 @@ func newTestAPIClient(handler http.Handler) *Client { return &c } + +func newTestAPIClientTLSConfig(handler http.Handler) *Client { + ts := httptest.NewServer(handler) + + tlsCfg := &tls.Config{} + tlsCfg.InsecureSkipVerify = true + + c := New(Config{ + APIKey: "123456", + BaseURL: ts.URL, + Debug: false, + TLSConfig: tlsCfg, + }) + + return &c +}