Skip to content

Commit

Permalink
object: enable vhost style via JFS_S3_VHOST_STYLE=1 (#4697)
Browse files Browse the repository at this point in the history
  • Loading branch information
davies authored Apr 15, 2024
1 parent 70011ff commit 8ee5279
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/object/eos.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func newEos(endpoint, accessKey, secretKey, token string) (ObjectStorage, error)
Endpoint: &endpoint,
Region: &region,
DisableSSL: aws.Bool(!ssl),
S3ForcePathStyle: aws.Bool(true),
S3ForcePathStyle: aws.Bool(defaultPathStyle()),
HTTPClient: httpClient,
Credentials: credentials.NewStaticCredentials(accessKey, secretKey, token),
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/object/ibmcos.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func newIBMCOS(endpoint, apiKey, serviceInstanceID, token string) (ObjectStorage
WithEndpoint(serviceEndpoint).
WithCredentials(ibmiam.NewStaticCredentials(aws.NewConfig(),
authEndpoint, apiKey, serviceInstanceID)).
WithS3ForcePathStyle(true)
WithS3ForcePathStyle(defaultPathStyle())
sess := session.Must(session.NewSession())
client := s3.New(sess, conf)
return &ibmcos{bucket: bucket, s3: client}, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/object/ks3.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func newKS3(endpoint, accessKey, secretKey, token string) (ObjectStorage, error)
bucket := hostParts[0]
region := hostParts[1][3:]
region = strings.TrimLeft(region, "-")
var pathStyle bool = true
var pathStyle bool = defaultPathStyle()
if strings.HasSuffix(uri.Host, "ksyun.com") || strings.HasSuffix(uri.Host, "ksyuncs.com") {
region = strings.TrimSuffix(region, "-internal")
region = ks3Regions[region]
Expand Down
2 changes: 1 addition & 1 deletion pkg/object/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func newMinio(endpoint, accessKey, secretKey, token string) (ObjectStorage, erro
Region: aws.String(region),
Endpoint: &uri.Host,
DisableSSL: aws.Bool(!ssl),
S3ForcePathStyle: aws.Bool(true),
S3ForcePathStyle: aws.Bool(defaultPathStyle()),
HTTPClient: httpClient,
}
if accessKey == "" {
Expand Down
4 changes: 2 additions & 2 deletions pkg/object/oos.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ func newOOS(endpoint, accessKey, secretKey, token string) (ObjectStorage, error)
bucket := hostParts[0]
region := hostParts[1][4:]
endpoint = uri.Host[len(bucket)+1:]
forcePathStyle := strings.Contains(strings.ToLower(endpoint), "xstore.ctyun.cn")
forcePathStyle := !strings.Contains(strings.ToLower(endpoint), "xstore.ctyun.cn")

awsConfig := &aws.Config{
Region: &region,
Endpoint: &endpoint,
DisableSSL: aws.Bool(!ssl),
S3ForcePathStyle: aws.Bool(!forcePathStyle),
S3ForcePathStyle: aws.Bool(forcePathStyle),
HTTPClient: httpClient,
Credentials: credentials.NewStaticCredentials(accessKey, secretKey, token),
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/object/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@ func parseRegion(endpoint string) string {
return region
}

func defaultPathStyle() bool {
v := os.Getenv("JFS_S3_VHOST_STYLE")
return v == "" || v == "0" || v == "false"
}

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

Expand Down Expand Up @@ -554,7 +559,7 @@ func newS3(endpoint, accessKey, secretKey, token string) (ObjectStorage, error)
}
if ep != "" {
awsConfig.Endpoint = aws.String(ep)
awsConfig.S3ForcePathStyle = aws.Bool(true)
awsConfig.S3ForcePathStyle = aws.Bool(defaultPathStyle())
}

ses, err := session.NewSession(awsConfig)
Expand Down

0 comments on commit 8ee5279

Please sign in to comment.