diff --git a/pkg/s3utils/utils.go b/pkg/s3utils/utils.go index d818e8ad9c..fea25d6ef6 100644 --- a/pkg/s3utils/utils.go +++ b/pkg/s3utils/utils.go @@ -95,6 +95,9 @@ var amazonS3HostDot = regexp.MustCompile(`^s3.(.*?).amazonaws.com$`) // amazonS3ChinaHost - regular expression used to determine if the arg is s3 china host. var amazonS3ChinaHost = regexp.MustCompile(`^s3.(cn.*?).amazonaws.com.cn$`) +// amazonS3ChinaHostDualStack - regular expression used to determine if the arg is s3 china host dualstack. +var amazonS3ChinaHostDualStack = regexp.MustCompile(`^s3.dualstack.(cn.*?).amazonaws.com.cn$`) + // Regular expression used to determine if the arg is elb host. var elbAmazonRegex = regexp.MustCompile(`elb(.*?).amazonaws.com$`) @@ -128,6 +131,10 @@ func GetRegionFromURL(endpointURL url.URL) string { if len(parts) > 1 { return parts[1] } + parts = amazonS3ChinaHostDualStack.FindStringSubmatch(endpointURL.Host) + if len(parts) > 1 { + return parts[1] + } parts = amazonS3HostDot.FindStringSubmatch(endpointURL.Host) if len(parts) > 1 { return parts[1] diff --git a/pkg/s3utils/utils_test.go b/pkg/s3utils/utils_test.go index 125456031c..7212e534f0 100644 --- a/pkg/s3utils/utils_test.go +++ b/pkg/s3utils/utils_test.go @@ -38,10 +38,18 @@ func TestGetRegionFromURL(t *testing.T) { u: url.URL{Host: "s3.cn-north-1.amazonaws.com.cn"}, expectedRegion: "cn-north-1", }, + { + u: url.URL{Host: "s3.dualstack.cn-north-1.amazonaws.com.cn"}, + expectedRegion: "cn-north-1", + }, { u: url.URL{Host: "s3.cn-northwest-1.amazonaws.com.cn"}, expectedRegion: "cn-northwest-1", }, + { + u: url.URL{Host: "s3.dualstack.cn-northwest-1.amazonaws.com.cn"}, + expectedRegion: "cn-northwest-1", + }, { u: url.URL{Host: "s3-fips-us-gov-west-1.amazonaws.com"}, expectedRegion: "us-gov-west-1", diff --git a/s3-endpoints.go b/s3-endpoints.go index 125d862891..9c8f02c842 100644 --- a/s3-endpoints.go +++ b/s3-endpoints.go @@ -42,8 +42,8 @@ var awsS3EndpointMap = map[string]string{ "sa-east-1": "s3.dualstack.sa-east-1.amazonaws.com", "us-gov-west-1": "s3.dualstack.us-gov-west-1.amazonaws.com", "us-gov-east-1": "s3.dualstack.us-gov-east-1.amazonaws.com", - "cn-north-1": "s3.cn-north-1.amazonaws.com.cn", - "cn-northwest-1": "s3.cn-northwest-1.amazonaws.com.cn", + "cn-north-1": "s3.dualstack.cn-north-1.amazonaws.com.cn", + "cn-northwest-1": "s3.dualstack.cn-northwest-1.amazonaws.com.cn", } // getS3Endpoint get Amazon S3 endpoint based on the bucket location.