Skip to content

Commit

Permalink
feat: force path-style
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangndst committed Jun 27, 2024
1 parent 634aed5 commit 34d837c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pkg/apis/api.kusion.io/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ const (
BackendGenericOssBucket = "bucket"
BackendGenericOssPrefix = "prefix"
BackendS3Region = "region"
BackendS3ForcePathStyle = "forcePathStyle"

BackendTypeLocal = "local"
BackendTypeOss = "oss"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -581,13 +585,15 @@ 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,
AccessKeyID: accessKeyID,
AccessKeySecret: accessKeySecret,
Bucket: bucket,
Prefix: prefix,
ForcePathStyle: forcePathStyle,
},
Region: region,
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/backend/storages/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions pkg/config/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit 34d837c

Please sign in to comment.