diff --git a/amazon.go b/amazon.go index 8a2225b..731cc08 100644 --- a/amazon.go +++ b/amazon.go @@ -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