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

Allow set S3ForcePathStyle #906

Merged
merged 4 commits into from
Oct 27, 2023
Merged
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
34 changes: 34 additions & 0 deletions amazon.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,40 @@ func NewAmazonS3Backend(bucket string, prefix string, region string, endpoint st
return b
}

type AmazonS3Options struct {
S3ForcePathStyle *bool
}

func NewAmazonS3BackendWithOptions(bucket string, prefix string, region string, endpoint string, sse string, options *AmazonS3Options) *AmazonS3Backend {
client := http.DefaultClient
if os.Getenv("AWS_INSECURE_SKIP_VERIFY") == "true" {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client = &http.Client{Transport: tr}
}
s3ForcePathStyle := endpoint != ""
if options != nil && options.S3ForcePathStyle != nil {
s3ForcePathStyle = *options.S3ForcePathStyle
}
service := s3.New(session.New(), &aws.Config{
HTTPClient: client,
Region: aws.String(region),
Endpoint: aws.String(endpoint),
DisableSSL: aws.Bool(strings.HasPrefix(endpoint, "http://")),
S3ForcePathStyle: aws.Bool(s3ForcePathStyle),
})
b := &AmazonS3Backend{
Bucket: bucket,
Client: service,
Downloader: s3manager.NewDownloaderWithClient(service),
Prefix: cleanPrefix(prefix),
Uploader: s3manager.NewUploaderWithClient(service),
SSE: sse,
}
return b
}

// NewAmazonS3BackendWithCredentials creates a new instance of AmazonS3Backend with credentials
func NewAmazonS3BackendWithCredentials(bucket string, prefix string, region string, endpoint string, sse string, credentials *credentials.Credentials) *AmazonS3Backend {
client := http.DefaultClient
Expand Down
Loading