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

Automated cherry pick of #1151: fix: s3 cli support set sign version #1153

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
30 changes: 29 additions & 1 deletion pkg/multicloud/objectstore/objectstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,23 @@ import (
"yunion.io/x/cloudmux/pkg/multicloud"
)

type S3SignVersion string

const (
S3SignAlgDefault = S3SignVersion("")
S3SignAlgV4 = S3SignVersion("v4")
S3SignAlgV2 = S3SignVersion("v2")
)

type ObjectStoreClientConfig struct {
cpcfg cloudprovider.ProviderConfig

endpoint string
accessKey string
accessSecret string

signVer S3SignVersion

debug bool
}

Expand All @@ -58,6 +68,11 @@ func (cfg *ObjectStoreClientConfig) CloudproviderConfig(cpcfg cloudprovider.Prov
return cfg
}

func (cfg *ObjectStoreClientConfig) SignVersion(signVer S3SignVersion) *ObjectStoreClientConfig {
cfg.signVer = signVer
return cfg
}

func (cfg *ObjectStoreClientConfig) Debug(debug bool) *ObjectStoreClientConfig {
cfg.debug = debug
return cfg
Expand Down Expand Up @@ -115,7 +130,20 @@ func NewObjectStoreClientAndFetch(cfg *ObjectStoreClientConfig, doFetch bool) (*
if parts.Scheme == "https" {
useSsl = true
}
cli, err := s3cli.New(
s3cliNewFunc := s3cli.New

switch cfg.signVer {
case S3SignAlgV4:
log.Debugf("Use v4 signing algorithm")
s3cliNewFunc = s3cli.NewV4
case S3SignAlgV2:
log.Debugf("Use v2 signing algorithm")
s3cliNewFunc = s3cli.NewV2
default:
log.Debugf("s3 sign algirithm version not set, use default")
}

cli, err := s3cliNewFunc(
parts.Host,
client.accessKey,
client.accessSecret,
Expand Down
3 changes: 2 additions & 1 deletion pkg/multicloud/objectstore/s3cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type BaseOptions struct {
AccessKey string `help:"Access key" default:"$S3_ACCESS_KEY" metavar:"S3_ACCESS_KEY"`
Secret string `help:"Secret" default:"$S3_SECRET" metavar:"S3_SECRET"`
Backend string `help:"Backend driver" default:"$S3_BACKEND" metavar:"S3_BACKEND"`
SignVer string `help:"Signing Algorithm Version" default:"$S3_SIGN_VER" metavar:"S3_SIGN_VER"`
SUBCOMMAND string `help:"s3cli subcommand" subcommand:"true"`
}

Expand Down Expand Up @@ -96,7 +97,7 @@ func newClient(options *BaseOptions) (cloudprovider.ICloudRegion, error) {
return objectstore.NewObjectStoreClient(
objectstore.NewObjectStoreClientConfig(
options.AccessUrl, options.AccessKey, options.Secret,
).Debug(options.Debug),
).Debug(options.Debug).SignVersion(objectstore.S3SignVersion(options.SignVer)),
)
}

Expand Down
Loading