Skip to content

Commit

Permalink
Merge pull request #46 from dkronst/master
Browse files Browse the repository at this point in the history
Add http proxy support as a config option
  • Loading branch information
gdavison authored Sep 23, 2021
2 parents fb93f44 + a6b4c05 commit 1872b23
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Config struct {
DebugLogging bool
IamEndpoint string
Insecure bool
HTTPProxy string
MaxRetries int
Profile string
Region string
Expand Down
12 changes: 11 additions & 1 deletion session.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"net/http"
"net/url"
"os"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -56,13 +57,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{}
Expand Down
8 changes: 8 additions & 0 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,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 {
Expand Down

0 comments on commit 1872b23

Please sign in to comment.