Skip to content

Commit 6b444bd

Browse files
committed
try to fix virtual host bucket URL style in s3 access disk
Signed-off-by: Slach <[email protected]>
1 parent e7047ce commit 6b444bd

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

ChangeLog.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# v2.6.15
22
BUG FIXES
33
- fix wrong cleanup *.state2 file in ResumeOperationsAfterRestart, after 2.6.12 [1126](https://github.com/Altinity/clickhouse-backup/issues/1126), fix [1133](https://github.com/Altinity/clickhouse-backup/issues/1133)
4+
- fix virtual host bucket URL style in s3 access disk
45

56
# v2.6.14
67
BUG FIXES

pkg/storage/object_disk/object_disk.go

+10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net/url"
1010
"os"
1111
"path"
12+
"regexp"
1213
"strconv"
1314
"strings"
1415
"sync"
@@ -445,6 +446,9 @@ func getObjectDisksCredentials(ctx context.Context, ch *clickhouse.ClickHouse) e
445446
return nil
446447
}
447448

449+
// S3VirtualHostBucketRE https://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html#virtual-hosted-style-access
450+
var S3VirtualHostBucketRE = regexp.MustCompile(`((.+)\.(s3express[\-a-z0-9]+|s3|cos|obs|oss-data-acc|oss|eos)([.\-][a-z0-9\-.:]+))`)
451+
448452
func makeObjectDiskConnection(ctx context.Context, ch *clickhouse.ClickHouse, cfg *config.Config, diskName string) (*ObjectStorageConnection, error) {
449453
creds, exists := DisksCredentials.Load(diskName)
450454
if !exists {
@@ -546,6 +550,12 @@ func makeObjectDiskConnection(ctx context.Context, ch *clickhouse.ClickHouse, cf
546550
s3cfg.Bucket = s3URL.Host
547551
s3cfg.Path = s3URL.Path
548552
s3cfg.ForcePathStyle = false
553+
} else if S3VirtualHostBucketRE.MatchString(s3URL.Host) {
554+
hostParts := strings.Split(s3URL.Host, ".")
555+
s3cfg.Bucket = hostParts[0]
556+
s3cfg.Endpoint = s3URL.Scheme + "://" + strings.Join(hostParts[1:], ".")
557+
s3cfg.Path = strings.Trim(s3URL.Path, "/")
558+
s3cfg.ForcePathStyle = false
549559
} else {
550560
s3cfg.Endpoint = s3URL.Scheme + "://" + s3URL.Host
551561
pathItems := strings.Split(strings.Trim(s3URL.Path, "/"), "/")

0 commit comments

Comments
 (0)