Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add http proxy support as a config option #46

Merged
merged 2 commits into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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{}
Expand Down
8 changes: 8 additions & 0 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down