From 6e2c00092d5bd03202a70e0a69a337e992262a07 Mon Sep 17 00:00:00 2001 From: _Jabbar_ Date: Fri, 3 Mar 2023 20:07:35 +0800 Subject: [PATCH 1/2] fix: getBucketLocation using virtual hosted style for Ksyun KS3 --- bucket-cache.go | 4 ++-- pkg/s3utils/utils.go | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bucket-cache.go b/bucket-cache.go index cafb4568b..0202a0c14 100644 --- a/bucket-cache.go +++ b/bucket-cache.go @@ -194,8 +194,8 @@ func (c *Client) getBucketLocationRequest(ctx context.Context, bucketName string var urlStr string - // only support Aliyun OSS for virtual hosted path, compatible Amazon & Google Endpoint - if isVirtualHost && s3utils.IsAliyunOSSEndpoint(targetURL) { + // only support Aliyun OSS & Ksyun KS3 for virtual hosted path, compatible Amazon & Google Endpoint + if isVirtualHost && s3utils.IsAliyunOSSEndpoint(targetURL) && s3utils.IsKsyunKS3Endpoint(targetURL) { urlStr = c.endpointURL.Scheme + "://" + bucketName + "." + targetURL.Host + "/?location" } else { targetURL.Path = path.Join(bucketName, "") + "/" diff --git a/pkg/s3utils/utils.go b/pkg/s3utils/utils.go index 79c129466..b262b2dba 100644 --- a/pkg/s3utils/utils.go +++ b/pkg/s3utils/utils.go @@ -78,7 +78,7 @@ func IsVirtualHostSupported(endpointURL url.URL, bucketName string) bool { return false } // Return true for all other cases - return IsAmazonEndpoint(endpointURL) || IsGoogleEndpoint(endpointURL) || IsAliyunOSSEndpoint(endpointURL) + return IsAmazonEndpoint(endpointURL) || IsGoogleEndpoint(endpointURL) || IsAliyunOSSEndpoint(endpointURL) || IsKsyunKS3Endpoint(endpointURL) } // Refer for region styles - https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region @@ -172,6 +172,11 @@ func IsAliyunOSSEndpoint(endpointURL url.URL) bool { return strings.HasSuffix(endpointURL.Host, "aliyuncs.com") } +// IsKsyunKS3Endpoint - Match if it is exactly Ksyun KS3 endpoint. +func IsKsyunKS3Endpoint(endpointURL url.URL) bool { + return strings.HasSuffix(endpointURL.Host, "ksyuncs.com") || strings.HasSuffix(endpointURL.Host, "ksyun.com") +} + // IsAmazonEndpoint - Match if it is exactly Amazon S3 endpoint. func IsAmazonEndpoint(endpointURL url.URL) bool { if endpointURL.Host == "s3-external-1.amazonaws.com" || endpointURL.Host == "s3.amazonaws.com" { From c7db2b6c71fd48dc4a823ed0ce89b970b08cb67c Mon Sep 17 00:00:00 2001 From: _Jabbar_ Date: Fri, 3 Mar 2023 21:34:40 +0800 Subject: [PATCH 2/2] fix: getBucketLocation using virtual hosted style for Ksyun KS3 --- bucket-cache.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bucket-cache.go b/bucket-cache.go index 0202a0c14..8258212be 100644 --- a/bucket-cache.go +++ b/bucket-cache.go @@ -195,7 +195,7 @@ func (c *Client) getBucketLocationRequest(ctx context.Context, bucketName string var urlStr string // only support Aliyun OSS & Ksyun KS3 for virtual hosted path, compatible Amazon & Google Endpoint - if isVirtualHost && s3utils.IsAliyunOSSEndpoint(targetURL) && s3utils.IsKsyunKS3Endpoint(targetURL) { + if isVirtualHost && (s3utils.IsAliyunOSSEndpoint(targetURL) || s3utils.IsKsyunKS3Endpoint(targetURL)) { urlStr = c.endpointURL.Scheme + "://" + bucketName + "." + targetURL.Host + "/?location" } else { targetURL.Path = path.Join(bucketName, "") + "/"