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

feat: add proxy support #177

Merged
merged 5 commits into from
Aug 18, 2023
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 .github/workflows/pr_test-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
go-version: '1.19'
- name: Test
run: TEST_DB=1 TEST_MQ=1 go test ./... -coverprofile=cover.out
timeout-minutes: 5
- name: Install dependencies
run: go install github.com/axw/gocov/gocov@v1.1.0 && go install github.com/AlekSi/gocov-xml@v1.1.0
- run: gocov convert cover.out | gocov-xml > coverage.xml
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pr_test-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
go-version: ${{ matrix.go }}
- name: Test
run: TEST_DB=1 TEST_MQ=1 go test ./...
timeout-minutes: 5
- name: Build
run: go build -v ./...
windows-matrix:
Expand Down
9 changes: 8 additions & 1 deletion provider/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/sa7mon/s3scanner/bucket"
log "github.com/sirupsen/logrus"
"net/http"
)

type providerAWS struct {
Expand Down Expand Up @@ -106,6 +107,9 @@ func (*providerAWS) newAnonClientNoRegion() (*s3.Client, error) {
context.TODO(),
config.WithDefaultRegion("us-west-2"),
config.WithCredentialsProvider(aws.AnonymousCredentials{}),
config.WithHTTPClient(&http.Client{Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
}}),
)
if err != nil {
return nil, err
Expand All @@ -123,7 +127,10 @@ func (a *providerAWS) newClient(region string) (*s3.Client, error) {
cfg, err := config.LoadDefaultConfig(
context.TODO(),
config.WithRegion(region),
config.WithCredentialsProvider(aws.AnonymousCredentials{}))
config.WithCredentialsProvider(aws.AnonymousCredentials{}),
config.WithHTTPClient(&http.Client{Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
}}))

if err != nil {
return nil, err
Expand Down
20 changes: 14 additions & 6 deletions provider/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ func NewProvider(name string) (StorageProvider, error) {
}

func newNonAWSClient(sp StorageProvider, regionURL string) (*s3.Client, error) {
var httpClient s3.HTTPClient

if sp.Insecure() {
httpClient = &http.Client{Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}}
} else {
httpClient = &http.Client{Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
}}
}

cfg, err := config.LoadDefaultConfig(
context.TODO(),
config.WithEndpointResolverWithOptions(
Expand All @@ -73,17 +86,12 @@ func newNonAWSClient(sp StorageProvider, regionURL string) (*s3.Client, error) {
}, nil
})),
config.WithCredentialsProvider(aws.AnonymousCredentials{}),
config.WithHTTPClient(httpClient),
)
if err != nil {
return nil, err
}

if sp.Insecure() {
cfg.HTTPClient = &http.Client{Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}}
}

addrStyleOption := func(o *s3.Options) { o.UsePathStyle = false }
if sp.AddressStyle() == PathStyle {
addrStyleOption = func(o *s3.Options) { o.UsePathStyle = true }
Expand Down