From 7e88f1713e085fc4e5a94654fed1ebfc634ee428 Mon Sep 17 00:00:00 2001 From: Dror Kronstein Date: Wed, 22 Jul 2020 14:35:31 +0300 Subject: [PATCH 1/2] add http proxy support as a config option --- config.go | 1 + session.go | 12 +++++++++++- session_test.go | 8 ++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/config.go b/config.go index c5f9daaf..74ff0f61 100644 --- a/config.go +++ b/config.go @@ -16,6 +16,7 @@ type Config struct { DebugLogging bool IamEndpoint string Insecure bool + HTTPProxy string MaxRetries int Profile string Region string diff --git a/session.go b/session.go index d4e56910..136c70a3 100644 --- a/session.go +++ b/session.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "net/http" + "net/url" "os" "github.com/aws/aws-sdk-go/aws" @@ -50,13 +51,22 @@ func GetSessionOptions(c *Config) (*session.Options, error) { // add the validated credentials to the session options options.Config.Credentials = creds + transport := options.Config.HTTPClient.Transport.(*http.Transport) if c.Insecure { - transport := options.Config.HTTPClient.Transport.(*http.Transport) transport.TLSClientConfig = &tls.Config{ InsecureSkipVerify: true, } } + if c.HTTPProxy != "" { + proxyUrl, err := url.Parse(c.HTTPProxy) + if err != nil { + return nil, err + } + + transport.Proxy = http.ProxyURL(proxyUrl) + } + if c.DebugLogging { options.Config.LogLevel = aws.LogLevel(aws.LogDebugWithHTTPBody | aws.LogDebugWithRequestRetries | aws.LogDebugWithRequestErrors) options.Config.Logger = DebugLogger{} diff --git a/session_test.go b/session_test.go index 51929557..2bc54a27 100644 --- a/session_test.go +++ b/session_test.go @@ -34,6 +34,14 @@ func TestGetSessionOptions(t *testing.T) { &Config{AccessKey: "MockAccessKey", SecretKey: "MockSecretKey", Insecure: true, DebugLogging: true}, false, }, + {"ConfigWithHTTPProxy", + &Config{AccessKey: "MockAccessKey", SecretKey: "MockSecretKey", HTTPProxy: "https://127.0.0.1:8888"}, + false, + }, + {"ConfigWithHTTPBadProxy", + &Config{AccessKey: "MockAccessKey", SecretKey: "MockSecretKey", HTTPProxy: "127.0.0.1:8888"}, + true, + }, } for _, testCase := range testCases { From a6b4c0541903e0f4ef1d4b643e2a6d77dba7a4d1 Mon Sep 17 00:00:00 2001 From: Graham Davison Date: Thu, 23 Sep 2021 12:03:09 -0700 Subject: [PATCH 2/2] Wraps HTTP proxy URL parsing error --- session.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/session.go b/session.go index 136c70a3..52c918cb 100644 --- a/session.go +++ b/session.go @@ -61,7 +61,7 @@ func GetSessionOptions(c *Config) (*session.Options, error) { if c.HTTPProxy != "" { proxyUrl, err := url.Parse(c.HTTPProxy) if err != nil { - return nil, err + return nil, fmt.Errorf("error parsing HTTP proxy URL: %w", err) } transport.Proxy = http.ProxyURL(proxyUrl)