From 1a44c70baf9b855b5674ec9958bfe330cc43941c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Tue, 21 Apr 2020 20:20:39 +0200 Subject: [PATCH] FIx --- ...sage-object-config-get-usage.stderr.golden | 31 +++++++++++++++++++ ...-object-config-install-usage.stderr.golden | 31 +++++++++++++++++++ ...ll-usage-object-config-usage.stderr.golden | 18 +++++++++++ .../test-all-usage-object-usage.stderr.golden | 17 ++++++++++ .../namespaces/object/v1/custom_config_get.go | 8 ++--- .../object/v1/custom_config_install.go | 8 ++--- internal/namespaces/object/v1/s3configfile.go | 8 +++++ .../test-config-get-default-mc.stdout.golden | 2 +- ...st-config-get-default-rclone.stdout.golden | 2 +- ...st-config-get-with-region-mc.stdout.golden | 2 +- ...onfig-get-with-region-rclone.stdout.golden | 2 +- 11 files changed, 117 insertions(+), 12 deletions(-) create mode 100644 cmd/scw/testdata/test-all-usage-object-config-get-usage.stderr.golden create mode 100644 cmd/scw/testdata/test-all-usage-object-config-install-usage.stderr.golden create mode 100644 cmd/scw/testdata/test-all-usage-object-config-usage.stderr.golden create mode 100644 cmd/scw/testdata/test-all-usage-object-usage.stderr.golden diff --git a/cmd/scw/testdata/test-all-usage-object-config-get-usage.stderr.golden b/cmd/scw/testdata/test-all-usage-object-config-get-usage.stderr.golden new file mode 100644 index 0000000000..f98f79e33f --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-object-config-get-usage.stderr.golden @@ -0,0 +1,31 @@ +Generate a S3 tool configuration file. + +USAGE: + scw object config get [arg=value ...] + +EXAMPLES: + Generate a s3cmd config file for Paris region + scw object config get region=fr-par type=s3cmd + + Generate a rclone config file for default region + scw object config get type=rclone + + Generate a mc (minio) config file for default region + scw object config get type=mc + +ARGS: + type Type of S3 tool you want to generate a config for (rclone | s3cmd | mc) + [name=scaleway] Name of the s3 remote you want to generate + [region] Region to target. If none is passed will use default region from the config (fr-par | nl-ams) + +FLAGS: + -h, --help help for get + +GLOBAL FLAGS: + -D, --debug Enable debug mode + -o, --output string Output format: json or human + -p, --profile string The config profile to use + +SEE ALSO: + # Install a S3 tool configuration file + scw object config install diff --git a/cmd/scw/testdata/test-all-usage-object-config-install-usage.stderr.golden b/cmd/scw/testdata/test-all-usage-object-config-install-usage.stderr.golden new file mode 100644 index 0000000000..efed199a2a --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-object-config-install-usage.stderr.golden @@ -0,0 +1,31 @@ +Install a S3 tool configuration file to its default location. + +USAGE: + scw object config install [arg=value ...] + +EXAMPLES: + Install a s3cmd config file for Paris region + scw object config install region=fr-par type=s3cmd + + Install a rclone config file for default region + scw object config install type=rclone + + Install a mc (minio) config file for default region + scw object config install type=mc + +ARGS: + type Type of S3 tool you want to generate a config for (rclone | s3cmd | mc) + [name=scaleway] Name of the s3 remote you want to generate + [region] Region to target. If none is passed will use default region from the config (fr-par | nl-ams) + +FLAGS: + -h, --help help for install + +GLOBAL FLAGS: + -D, --debug Enable debug mode + -o, --output string Output format: json or human + -p, --profile string The config profile to use + +SEE ALSO: + # Generate a S3 tool configuration file + scw object config get diff --git a/cmd/scw/testdata/test-all-usage-object-config-usage.stderr.golden b/cmd/scw/testdata/test-all-usage-object-config-usage.stderr.golden new file mode 100644 index 0000000000..e88be4d96d --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-object-config-usage.stderr.golden @@ -0,0 +1,18 @@ +Configuration generation for S3 tools. + +USAGE: + scw object config + +AVAILABLE COMMANDS: + get Generate a S3 tool configuration file + install Install a S3 tool configuration file to its default location + +FLAGS: + -h, --help help for config + +GLOBAL FLAGS: + -D, --debug Enable debug mode + -o, --output string Output format: json or human + -p, --profile string The config profile to use + +Use "scw object config [command] --help" for more information about a command. diff --git a/cmd/scw/testdata/test-all-usage-object-usage.stderr.golden b/cmd/scw/testdata/test-all-usage-object-usage.stderr.golden new file mode 100644 index 0000000000..c10d8db6d6 --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-object-usage.stderr.golden @@ -0,0 +1,17 @@ +Object-storage utils + +USAGE: + scw object + +AVAILABLE COMMANDS: + config Manage configuration files for popular S3 tools + +FLAGS: + -h, --help help for object + +GLOBAL FLAGS: + -D, --debug Enable debug mode + -o, --output string Output format: json or human + -p, --profile string The config profile to use + +Use "scw object [command] --help" for more information about a command. diff --git a/internal/namespaces/object/v1/custom_config_get.go b/internal/namespaces/object/v1/custom_config_get.go index a5ab21d533..7168882dd2 100644 --- a/internal/namespaces/object/v1/custom_config_get.go +++ b/internal/namespaces/object/v1/custom_config_get.go @@ -19,22 +19,22 @@ func configGetCommand() *core.Command { Namespace: "object", Resource: "config", Verb: "get", - Short: "Generate a S3 related configuration file", - Long: "Generate a S3 related configuration file.", + Short: "Generate a S3 tool configuration file", + Long: "Generate a S3 tool configuration file.", ArgsType: reflect.TypeOf(getArgs{}), ArgSpecs: []*core.ArgSpec{ { Name: "type", Short: "Type of S3 tool you want to generate a config for", Required: true, - EnumValues: supportedTools, + EnumValues: []string{rclone.String(), s3cmd.String(), mc.String()}, }, { Name: "name", Short: "Name of the s3 remote you want to generate", Required: false, Default: func() (value string, doc string) { - return "scaleway", "default value" + return "scaleway", "scaleway" }, }, core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms), diff --git a/internal/namespaces/object/v1/custom_config_install.go b/internal/namespaces/object/v1/custom_config_install.go index 5fce4fcaec..e04b923624 100644 --- a/internal/namespaces/object/v1/custom_config_install.go +++ b/internal/namespaces/object/v1/custom_config_install.go @@ -22,22 +22,22 @@ func configInstallCommand() *core.Command { Namespace: "object", Resource: "config", Verb: "install", - Short: "Install a S3 related configuration file to its default location", - Long: "Install a S3 related configuration file.", + Short: "Install a S3 tool configuration file to its default location", + Long: "Install a S3 tool configuration file to its default location.", ArgsType: reflect.TypeOf(installArgs{}), ArgSpecs: []*core.ArgSpec{ { Name: "type", Short: "Type of S3 tool you want to generate a config for", Required: true, - EnumValues: supportedTools, + EnumValues: []string{rclone.String(), s3cmd.String(), mc.String()}, }, { Name: "name", Short: "Name of the s3 remote you want to generate", Required: false, Default: func() (value string, doc string) { - return "scaleway", "default value" + return "scaleway", "scaleway" }, }, core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms), diff --git a/internal/namespaces/object/v1/s3configfile.go b/internal/namespaces/object/v1/s3configfile.go index e3af0eb827..4721ca1cee 100644 --- a/internal/namespaces/object/v1/s3configfile.go +++ b/internal/namespaces/object/v1/s3configfile.go @@ -15,6 +15,10 @@ import ( type s3tool string +func (c s3tool) String() string { + return string(c) +} + type s3config struct { AccessKey string SecretKey string @@ -71,6 +75,10 @@ func newS3Config(ctx context.Context, region scw.Region, name string) (s3config, if !secretExists { return s3config{}, fmt.Errorf("no secret key found") } + if region == "" { + defaultRegion, _ := client.GetDefaultRegion() + region = defaultRegion + } config := s3config{ AccessKey: accessKey, SecretKey: secretKey, diff --git a/internal/namespaces/object/v1/testdata/test-config-get-default-mc.stdout.golden b/internal/namespaces/object/v1/testdata/test-config-get-default-mc.stdout.golden index dd4c1b5ad0..25185e3ca1 100644 --- a/internal/namespaces/object/v1/testdata/test-config-get-default-mc.stdout.golden +++ b/internal/namespaces/object/v1/testdata/test-config-get-default-mc.stdout.golden @@ -1 +1 @@ -{"version":"9","hosts":{"scaleway_fr-par":{"url":"https://s3.fr-par.scw.cloud","accessKey":"SCWXXXXXXXXXXXXXXXXX","secretKey":"11111111-1111-1111-1111-111111111111","api":"S3v2"}}} +{"version":"9","hosts":{"scaleway":{"url":"https://s3.fr-par.scw.cloud","accessKey":"SCWXXXXXXXXXXXXXXXXX","secretKey":"11111111-1111-1111-1111-111111111111","api":"S3v2"}}} diff --git a/internal/namespaces/object/v1/testdata/test-config-get-default-rclone.stdout.golden b/internal/namespaces/object/v1/testdata/test-config-get-default-rclone.stdout.golden index 8a83c732e4..d565c758e3 100644 --- a/internal/namespaces/object/v1/testdata/test-config-get-default-rclone.stdout.golden +++ b/internal/namespaces/object/v1/testdata/test-config-get-default-rclone.stdout.golden @@ -1,7 +1,7 @@ # Generated by scaleway-cli command # Configuration file for rclone https://rclone.org/s3/#scaleway # Default location: $HOME/.config/rclone/rclone.conf -[scaleway_fr-par] +[scaleway] type = s3 env_auth = false endpoint = s3.fr-par.scw.cloud diff --git a/internal/namespaces/object/v1/testdata/test-config-get-with-region-mc.stdout.golden b/internal/namespaces/object/v1/testdata/test-config-get-with-region-mc.stdout.golden index 46bc3af73d..fb71129eca 100644 --- a/internal/namespaces/object/v1/testdata/test-config-get-with-region-mc.stdout.golden +++ b/internal/namespaces/object/v1/testdata/test-config-get-with-region-mc.stdout.golden @@ -1 +1 @@ -{"version":"9","hosts":{"scaleway_nl-ams":{"url":"https://s3.nl-ams.scw.cloud","accessKey":"SCWXXXXXXXXXXXXXXXXX","secretKey":"11111111-1111-1111-1111-111111111111","api":"S3v2"}}} +{"version":"9","hosts":{"scaleway":{"url":"https://s3.nl-ams.scw.cloud","accessKey":"SCWXXXXXXXXXXXXXXXXX","secretKey":"11111111-1111-1111-1111-111111111111","api":"S3v2"}}} diff --git a/internal/namespaces/object/v1/testdata/test-config-get-with-region-rclone.stdout.golden b/internal/namespaces/object/v1/testdata/test-config-get-with-region-rclone.stdout.golden index 003e893a8c..b58e9342ce 100644 --- a/internal/namespaces/object/v1/testdata/test-config-get-with-region-rclone.stdout.golden +++ b/internal/namespaces/object/v1/testdata/test-config-get-with-region-rclone.stdout.golden @@ -1,7 +1,7 @@ # Generated by scaleway-cli command # Configuration file for rclone https://rclone.org/s3/#scaleway # Default location: $HOME/.config/rclone/rclone.conf -[scaleway_nl-ams] +[scaleway] type = s3 env_auth = false endpoint = s3.nl-ams.scw.cloud