Skip to content

Commit 6126eea

Browse files
authored
object/oss: support oss private link endpoint (#6686)
Signed-off-by: Changxin Miao <[email protected]>
1 parent 93b3c28 commit 6126eea

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

pkg/object/oss.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,14 +388,26 @@ func newOSS(endpoint, accessKey, secretKey, token string) (ObjectStorage, error)
388388
if regionID = os.Getenv("ALICLOUD_REGION_ID"); regionID == "" {
389389
index := strings.Index(domain, ".")
390390
if index <= 0 {
391-
return nil, fmt.Errorf("invalid endpoint: %s", domain)
391+
return nil, fmt.Errorf("invalid endpoint: %q", domain)
392392
}
393393
if strings.HasSuffix(domain, ".aliyuncs.com") {
394-
old := strings.TrimPrefix(strings.TrimPrefix(domain[:index], "http://"), "https://")
395-
regionID = strings.TrimPrefix(old, "oss-")
396-
regionID = strings.TrimSuffix(regionID, "-internal")
397-
regionID = strings.TrimSuffix(regionID, "-vpc")
398-
useV4 = old != regionID
394+
if strings.Contains(domain, ".privatelink.") {
395+
// <id>.oss.<region>.privatelink.aliyuncs.com
396+
parts := strings.Split(domain, ".")
397+
if len(parts) < 3 {
398+
return nil, fmt.Errorf("invalid private link endpoint: %q", domain)
399+
}
400+
regionID = parts[2]
401+
useV4 = true
402+
} else {
403+
// oss-<region>.aliyuncs.com
404+
// oss-<region>-internal.aliyuncs.com
405+
old := strings.TrimPrefix(strings.TrimPrefix(domain[:index], "http://"), "https://")
406+
regionID = strings.TrimPrefix(old, "oss-")
407+
regionID = strings.TrimSuffix(regionID, "-internal")
408+
regionID = strings.TrimSuffix(regionID, "-vpc")
409+
useV4 = old != regionID
410+
}
399411
}
400412
}
401413
config := oss.LoadDefaultConfig()
@@ -406,6 +418,7 @@ func newOSS(endpoint, accessKey, secretKey, token string) (ObjectStorage, error)
406418
} else {
407419
config.WithSignatureVersion(oss.SignatureVersionV1)
408420
}
421+
config.UsePathStyle = oss.Ptr(strings.Contains(domain, ".privatelink."))
409422
config.RetryMaxAttempts = oss.Ptr(1)
410423
config.ConnectTimeout = oss.Ptr(time.Second * 2)
411424
config.ReadWriteTimeout = oss.Ptr(time.Second * 5)

0 commit comments

Comments
 (0)