Skip to content

Commit

Permalink
add config option to force s3 virtual addressing
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroshade committed Dec 13, 2024
1 parent 0b37479 commit 6861e09
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions io/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"net/url"
"os"
"slices"
"strconv"

"github.com/aws/aws-sdk-go-v2/aws"
awshttp "github.com/aws/aws-sdk-go-v2/aws/transport/http"
Expand All @@ -37,14 +38,15 @@ import (

// Constants for S3 configuration options
const (
S3Region = "s3.region"
S3SessionToken = "s3.session-token"
S3SecretAccessKey = "s3.secret-access-key"
S3AccessKeyID = "s3.access-key-id"
S3EndpointURL = "s3.endpoint"
S3ProxyURI = "s3.proxy-uri"
S3ConnectTimeout = "s3.connect-timeout"
S3SignerUri = "s3.signer.uri"
S3Region = "s3.region"
S3SessionToken = "s3.session-token"
S3SecretAccessKey = "s3.secret-access-key"
S3AccessKeyID = "s3.access-key-id"
S3EndpointURL = "s3.endpoint"
S3ProxyURI = "s3.proxy-uri"
S3ConnectTimeout = "s3.connect-timeout"
S3SignerUri = "s3.signer.uri"
S3ForceVirtualAddressing = "s3.force-virtual-addressing"
)

var unsupportedS3Props = []string{
Expand Down Expand Up @@ -115,11 +117,18 @@ func createS3Bucket(ctx context.Context, parsed *url.URL, props map[string]strin
endpoint = os.Getenv("AWS_S3_ENDPOINT")
}

usePathStyle := true
if forceVirtual, ok := props[S3ForceVirtualAddressing]; ok {
if cfgForceVirtual, err := strconv.ParseBool(forceVirtual); err == nil {
usePathStyle = !cfgForceVirtual
}
}

client := s3.NewFromConfig(*awscfg, func(o *s3.Options) {
if endpoint != "" {
o.BaseEndpoint = aws.String(endpoint)
}
o.UsePathStyle = true
o.UsePathStyle = usePathStyle
})

// Create a *blob.Bucket.
Expand Down

0 comments on commit 6861e09

Please sign in to comment.