From 8525b0bf7c53f0f0269cd4b62e9e91115f58682c Mon Sep 17 00:00:00 2001 From: Jason Tackaberry Date: Thu, 4 Jan 2024 20:06:55 -0500 Subject: [PATCH] Support non-AWS S3 URL formats in S3Client --- aws/s3.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/aws/s3.go b/aws/s3.go index 81a4d15b..ecabc44e 100644 --- a/aws/s3.go +++ b/aws/s3.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "io" + "strings" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/credentials" @@ -53,7 +54,16 @@ func NewS3Client(endpoint, region, accessKey, secretKey, bucket, key string, for // String returns a string representation of the S3Client. func (s *S3Client) String() string { - return fmt.Sprintf("s3://%s/%s", s.bucket, s.key) + if s.endpoint == "" || strings.HasSuffix(s.endpoint, "amazonaws.com") { + // Native Amazon S3, use AWS's S3 URL format + return fmt.Sprintf("s3://%s/%s", s.bucket, s.key) + } else if !s.forcePathStyle { + // Endpoint specified but not using path style (e.g. Wasabi) + return fmt.Sprintf("s3://%s.%s/%s", s.bucket, s.endpoint, s.key) + } else { + // Endpoint specified and using path style (e.g. MinIO) + return fmt.Sprintf("s3://%s/%s/%s", s.endpoint, s.bucket, s.key) + } } // Upload uploads data to S3.