Skip to content

Commit

Permalink
Merge pull request #906 from warjiang/feat/s3-force-path-style
Browse files Browse the repository at this point in the history
Allow set S3ForcePathStyle
  • Loading branch information
scbizu authored Oct 27, 2023
2 parents 1b025e9 + 4b4a57e commit 4a95d4e
Showing 1 changed file with 34 additions and 0 deletions.
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

0 comments on commit 4a95d4e

Please sign in to comment.