From 34d837c723efab2631fc99b62779d9bcedc4fb51 Mon Sep 17 00:00:00 2001 From: hoangndst Date: Thu, 27 Jun 2024 18:43:20 +0700 Subject: [PATCH] feat: force path-style --- pkg/apis/api.kusion.io/v1/types.go | 6 ++++++ pkg/backend/storages/s3.go | 2 +- pkg/config/validation.go | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pkg/apis/api.kusion.io/v1/types.go b/pkg/apis/api.kusion.io/v1/types.go index e0132ac68..2cf2099fd 100644 --- a/pkg/apis/api.kusion.io/v1/types.go +++ b/pkg/apis/api.kusion.io/v1/types.go @@ -463,6 +463,7 @@ const ( BackendGenericOssBucket = "bucket" BackendGenericOssPrefix = "prefix" BackendS3Region = "region" + BackendS3ForcePathStyle = "forcePathStyle" BackendTypeLocal = "local" BackendTypeOss = "oss" @@ -533,6 +534,9 @@ type GenericBackendObjectStorageConfig struct { // Prefix of the key to store the files. Prefix string `yaml:"prefix,omitempty" json:"prefix,omitempty"` + + // ForcePathStyle indicates whether to use path-style access for all operations. + ForcePathStyle bool `yaml:"forcePathStyle,omitempty" json:"forcePathStyle,omitempty"` } // ToLocalBackend converts BackendConfig to structured BackendLocalConfig, works only when the Type @@ -581,6 +585,7 @@ func (b *BackendConfig) ToS3Backend() *BackendS3Config { bucket, _ := b.Configs[BackendGenericOssBucket].(string) prefix, _ := b.Configs[BackendGenericOssPrefix].(string) region, _ := b.Configs[BackendS3Region].(string) + forcePathStyle, _ := b.Configs[BackendS3ForcePathStyle].(bool) return &BackendS3Config{ GenericBackendObjectStorageConfig: &GenericBackendObjectStorageConfig{ Endpoint: endpoint, @@ -588,6 +593,7 @@ func (b *BackendConfig) ToS3Backend() *BackendS3Config { AccessKeySecret: accessKeySecret, Bucket: bucket, Prefix: prefix, + ForcePathStyle: forcePathStyle, }, Region: region, } diff --git a/pkg/backend/storages/s3.go b/pkg/backend/storages/s3.go index 396b4b1f9..3a68bc395 100644 --- a/pkg/backend/storages/s3.go +++ b/pkg/backend/storages/s3.go @@ -27,7 +27,7 @@ func NewS3Storage(config *v1.BackendS3Config) (*S3Storage, error) { Credentials: credentials.NewStaticCredentials(config.AccessKeyID, config.AccessKeySecret, ""), Region: aws.String(config.Region), DisableSSL: aws.Bool(true), - S3ForcePathStyle: aws.Bool(false), + S3ForcePathStyle: aws.Bool(config.ForcePathStyle), } if config.Endpoint != "" { c.Endpoint = aws.String(config.Endpoint) diff --git a/pkg/config/validation.go b/pkg/config/validation.go index 2b23a0d30..8f8842ded 100644 --- a/pkg/config/validation.go +++ b/pkg/config/validation.go @@ -199,6 +199,7 @@ func checkBasalBackendConfig(config *v1.BackendConfig) error { v1.BackendGenericOssBucket: checkString, v1.BackendGenericOssPrefix: checkString, v1.BackendS3Region: checkString, + v1.BackendS3ForcePathStyle: checkBool, } if err := checkBasalBackendConfigItems(config, items); err != nil { return err @@ -285,3 +286,10 @@ func checkString(val any) error { } return nil } + +func checkBool(val any) error { + if _, ok := val.(bool); !ok { + return ErrNotBool + } + return nil +}