Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support path-style of bucket for s3 storage backend #1189

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading