Skip to content

Commit

Permalink
object/OVH: support OVH region (#3133)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhijian-pro authored Dec 30, 2022
1 parent 5289fab commit fe20ebc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
23 changes: 21 additions & 2 deletions pkg/object/object_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,19 +378,38 @@ func TestS3(t *testing.T) {
}

func TestOracleCompileRegexp(t *testing.T) {
ep := "zhijian-test.axntujn0ebj1.compat.objectstorage.ap-singapore-1.oraclecloud.com"
ep := "axntujn0ebj1.compat.objectstorage.ap-singapore-1.oraclecloud.com"
oracleCompile := regexp.MustCompile(oracleCompileRegexp)
if oracleCompile.MatchString(ep) {
if submatch := oracleCompile.FindStringSubmatch(ep); len(submatch) == 2 {
if submatch := oracleCompile.FindStringSubmatch(ep); len(submatch) >= 2 {
if submatch[1] != "ap-singapore-1" {
t.Fatalf("oracle endpoint parse failed")
}
} else {
t.Fatalf("oracle endpoint parse failed")
}
} else {
t.Fatalf("oracle endpoint parse failed")
}
}

func TestOVHCompileRegexp(t *testing.T) {
for _, ep := range []string{"s3.gra.cloud.ovh.net", "s3.gra.perf.cloud.ovh.net", "s3.gra.io.cloud.ovh.net"} {
ovhCompile := regexp.MustCompile(OVHCompileRegexp)
if ovhCompile.MatchString(ep) {
if submatch := ovhCompile.FindStringSubmatch(ep); len(submatch) >= 2 {
if submatch[1] != "gra" {
t.Fatalf("ovh endpoint parse failed")
}
} else {
t.Fatalf("ovh endpoint parse failed")
}
} else {
t.Fatalf("ovh endpoint parse failed")
}
}
}

func TestOSS(t *testing.T) {
if os.Getenv("ALICLOUD_ACCESS_KEY_ID") == "" {
t.SkipNow()
Expand Down
13 changes: 9 additions & 4 deletions pkg/object/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ func parseRegion(endpoint string) string {
}

var oracleCompileRegexp = `.*\.compat.objectstorage\.(.*)\.oraclecloud\.com`
var OVHCompileRegexp = `^s3\.(\w*)(\.\w*)?\.cloud\.ovh\.net$`

func newS3(endpoint, accessKey, secretKey, token string) (ObjectStorage, error) {
if !strings.Contains(endpoint, "://") {
Expand Down Expand Up @@ -419,10 +420,14 @@ func newS3(endpoint, accessKey, secretKey, token string) (ObjectStorage, error)
// compatible s3
bucketName = hostParts[0]
ep = hostParts[1]
oracleCompile := regexp.MustCompile(oracleCompileRegexp)
if oracleCompile.MatchString(ep) {
if submatch := oracleCompile.FindStringSubmatch(ep); len(submatch) == 2 {
region = submatch[1]

for _, compileRegexp := range []string{oracleCompileRegexp, OVHCompileRegexp} {
compile := regexp.MustCompile(compileRegexp)
if compile.MatchString(ep) {
if submatch := compile.FindStringSubmatch(ep); len(submatch) >= 2 {
region = submatch[1]
break
}
}
}
}
Expand Down

0 comments on commit fe20ebc

Please sign in to comment.