Add forcepathstyle parameter for s3

Signed-off-by: duanhongyi <duanhongyi@doopai.com>
This commit is contained in:
duanhongyi 2022-04-19 22:49:19 +08:00
parent cd51f38d53
commit 15de9e21ba
4 changed files with 35 additions and 2 deletions

View file

@ -88,6 +88,7 @@ type DriverParameters struct {
Bucket string
Region string
RegionEndpoint string
ForcePathStyle bool
Encrypt bool
KeyID string
Secure bool
@ -189,6 +190,23 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) {
regionEndpoint = ""
}
forcePathStyleBool := true
forcePathStyle := parameters["forcepathstyle"]
switch forcePathStyle := forcePathStyle.(type) {
case string:
b, err := strconv.ParseBool(forcePathStyle)
if err != nil {
return nil, fmt.Errorf("the forcePathStyle parameter should be a boolean")
}
forcePathStyleBool = b
case bool:
forcePathStyleBool = forcePathStyle
case nil:
// do nothing
default:
return nil, fmt.Errorf("the forcePathStyle parameter should be a boolean")
}
regionName := parameters["region"]
if regionName == nil || fmt.Sprint(regionName) == "" {
return nil, fmt.Errorf("no region parameter provided")
@ -401,6 +419,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) {
fmt.Sprint(bucket),
region,
fmt.Sprint(regionEndpoint),
forcePathStyleBool,
encryptBool,
fmt.Sprint(keyID),
secureBool,
@ -473,8 +492,8 @@ func New(params DriverParameters) (*Driver, error) {
}
if params.RegionEndpoint != "" {
awsConfig.WithS3ForcePathStyle(true)
awsConfig.WithEndpoint(params.RegionEndpoint)
awsConfig.WithS3ForcePathStyle(params.ForcePathStyle)
}
awsConfig.WithS3UseAccelerate(params.Accelerate)