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..52c918cb 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, fmt.Errorf("error parsing HTTP proxy URL: %w", 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 {