Skip to content

Commit

Permalink
fileservice: return AWS region detection error in ObjectStorageArgume…
Browse files Browse the repository at this point in the history
…nts.validate
  • Loading branch information
reusee committed Feb 5, 2025
1 parent afefc47 commit 1204c64
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
10 changes: 4 additions & 6 deletions pkg/fileservice/object_storage_arguments.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"strings"

"github.com/matrixorigin/matrixone/pkg/common/moerr"
"github.com/matrixorigin/matrixone/pkg/logutil"
"go.uber.org/zap"
)

type ObjectStorageArguments struct {
Expand Down Expand Up @@ -153,23 +151,23 @@ func (o *ObjectStorageArguments) validate() error {
// region
if o.Region == "" {

// 腾讯云
if o.Endpoint != "" && strings.Contains(o.Endpoint, "myqcloud.com") {
// 腾讯云
matches := qcloudEndpointPattern.FindStringSubmatch(o.Endpoint)
if len(matches) > 0 {
o.Region = matches[1]
}

} else {
} else if o.Endpoint != "" && strings.Contains(o.Endpoint, "amazonaws.com") {
// AWS
// try to get region from bucket
// only works for AWS S3
resp, err := http.Head("https://" + o.Bucket + ".s3.amazonaws.com")
if err == nil {
if value := resp.Header.Get("x-amz-bucket-region"); value != "" {
o.Region = value
}
} else {
logutil.Debug("error", zap.Error(err))
return err
}
}

Expand Down
19 changes: 18 additions & 1 deletion pkg/fileservice/object_storage_arguments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,25 @@ func TestQCloudRegion(t *testing.T) {

func TestAWSRegion(t *testing.T) {
args := ObjectStorageArguments{
Endpoint: "amazonaws.com",

Bucket: "aws", // hope it will not change its region
}
args.validate()
assert.Nil(t, args.validate())
assert.Equal(t, "us-east-1", args.Region)

args = ObjectStorageArguments{
Endpoint: "amazonaws.com",

Bucket: "fdsafdsafasdfsdafsadfsdafdsafewrewqrweqrewrwerwqrew", // invalid bucket
}
assert.Nil(t, args.validate())
assert.Equal(t, "", args.Region)

args = ObjectStorageArguments{
Endpoint: "amazonaws.com",

Bucket: "a/b/c", // invalid bucket
}
assert.NotNil(t, args.validate())
}

0 comments on commit 1204c64

Please sign in to comment.