From 3c0ed11922f17bb48ac14c76e3242070d3b82f2e Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Fri, 16 Oct 2015 17:17:35 -0400 Subject: [PATCH 1/3] Remove usage of http.DefaultClient --- state/remote/atlas.go | 9 ++++++--- state/remote/http_test.go | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/state/remote/atlas.go b/state/remote/atlas.go index f52d834a2c..2c2c48895a 100644 --- a/state/remote/atlas.go +++ b/state/remote/atlas.go @@ -83,7 +83,8 @@ func (c *AtlasClient) Get() (*Payload, error) { } // Request the url - resp, err := http.DefaultClient.Do(req) + client := &http.Client{} + resp, err := client.Do(req) if err != nil { return nil, err } @@ -161,7 +162,8 @@ func (c *AtlasClient) Put(state []byte) error { req.ContentLength = int64(len(state)) // Make the request - resp, err := http.DefaultClient.Do(req) + client := &http.Client{} + resp, err := client.Do(req) if err != nil { return fmt.Errorf("Failed to upload state: %v", err) } @@ -186,7 +188,8 @@ func (c *AtlasClient) Delete() error { } // Make the request - resp, err := http.DefaultClient.Do(req) + client := &http.Client{} + resp, err := client.Do(req) if err != nil { return fmt.Errorf("Failed to delete state: %v", err) } diff --git a/state/remote/http_test.go b/state/remote/http_test.go index e6e7297c19..74ed1755a2 100644 --- a/state/remote/http_test.go +++ b/state/remote/http_test.go @@ -24,7 +24,7 @@ func TestHTTPClient(t *testing.T) { t.Fatalf("err: %s", err) } - client := &HTTPClient{URL: url, Client: http.DefaultClient} + client := &HTTPClient{URL: url, Client: &http.Client{}} testClient(t, client) } From b0ceffc322efabc3ad2ff4bf41090eab25053bbe Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Mon, 19 Oct 2015 12:04:10 -0400 Subject: [PATCH 2/3] Remove usage from dependencies as well. Other dependencies need upstream merging to completely solve this. --- builtin/providers/aws/config.go | 3 +++ builtin/providers/dme/config.go | 6 +++++- state/remote/s3.go | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/config.go b/builtin/providers/aws/config.go index f8f443b73d..8b9428fbc2 100644 --- a/builtin/providers/aws/config.go +++ b/builtin/providers/aws/config.go @@ -3,6 +3,7 @@ package aws import ( "fmt" "log" + "net/http" "strings" "github.com/hashicorp/go-multierror" @@ -98,6 +99,7 @@ func (c *Config) Client() (interface{}, error) { Credentials: creds, Region: aws.String(c.Region), MaxRetries: aws.Int(c.MaxRetries), + HTTPClient: &http.Client{}, } log.Println("[INFO] Initializing IAM Connection") @@ -123,6 +125,7 @@ func (c *Config) Client() (interface{}, error) { Credentials: creds, Region: aws.String("us-east-1"), MaxRetries: aws.Int(c.MaxRetries), + HTTPClient: &http.Client{}, } log.Println("[INFO] Initializing DynamoDB connection") diff --git a/builtin/providers/dme/config.go b/builtin/providers/dme/config.go index 514df0d101..2d387673fe 100644 --- a/builtin/providers/dme/config.go +++ b/builtin/providers/dme/config.go @@ -2,8 +2,10 @@ package dme import ( "fmt" - "github.com/soniah/dnsmadeeasy" "log" + "net/http" + + "github.com/soniah/dnsmadeeasy" ) // Config contains DNSMadeEasy provider settings @@ -20,6 +22,8 @@ func (c *Config) Client() (*dnsmadeeasy.Client, error) { return nil, fmt.Errorf("Error setting up client: %s", err) } + client.HTTP = &http.Client{} + if c.UseSandbox { client.URL = dnsmadeeasy.SandboxURL } diff --git a/state/remote/s3.go b/state/remote/s3.go index bdc6a63cf9..f6cfdfbde2 100644 --- a/state/remote/s3.go +++ b/state/remote/s3.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "log" + "net/http" "os" "strconv" @@ -75,6 +76,7 @@ func s3Factory(conf map[string]string) (Client, error) { awsConfig := &aws.Config{ Credentials: credentialsProvider, Region: aws.String(regionName), + HTTPClient: &http.Client{}, } nativeClient := s3.New(awsConfig) From 5fa5c4bc535c7798b0ec792e02dda4495e0854bc Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Mon, 19 Oct 2015 13:03:28 -0400 Subject: [PATCH 3/3] Use new packngo API allowing passing in a custom http.Client --- builtin/providers/packet/config.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/builtin/providers/packet/config.go b/builtin/providers/packet/config.go index 659ee9ebc8..b7d408c626 100644 --- a/builtin/providers/packet/config.go +++ b/builtin/providers/packet/config.go @@ -1,6 +1,8 @@ package packet import ( + "net/http" + "github.com/packethost/packngo" ) @@ -14,5 +16,5 @@ type Config struct { // Client() returns a new client for accessing packet. func (c *Config) Client() *packngo.Client { - return packngo.NewClient(consumerToken, c.AuthToken) + return packngo.NewClient(consumerToken, c.AuthToken, &http.Client{}) }