Skip to content

Commit 293a269

Browse files
committed
1 parent 3306535 commit 293a269

10 files changed

+38
-15
lines changed

internal/namespaces/object/v1/custom_config_get.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ func configGetCommand() *core.Command {
3737
Required: false,
3838
Default: core.DefaultValueSetter("scaleway"),
3939
},
40+
{
41+
Name: "project-id",
42+
Short: "Scaleway project ID to use with IAM Access Key syntax",
43+
Required: false,
44+
ValidateFunc: core.ValidateProjectID(),
45+
},
4046
core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms),
4147
},
4248
Examples: []*core.Example{

internal/namespaces/object/v1/custom_config_get_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ func Test_ConfigGet(t *testing.T) {
1616
"11111111-1111-1111-1111-111111111111",
1717
),
1818
scw.WithDefaultOrganizationID("11111111-1111-1111-1111-111111111111"),
19+
scw.WithDefaultProjectID("11111111-1111-1111-1111-111111111111"),
1920
scw.WithDefaultZone(scw.ZoneFrPar1),
2021
scw.WithDefaultRegion(scw.RegionFrPar),
2122
)

internal/namespaces/object/v1/custom_config_install.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ func configInstallCommand() *core.Command {
4141
Required: false,
4242
Default: core.DefaultValueSetter("scaleway"),
4343
},
44+
{
45+
Name: "project-id",
46+
Short: "Scaleway project ID to use with IAM Access Key syntax",
47+
Required: false,
48+
ValidateFunc: core.ValidateProjectID(),
49+
},
4450
core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms),
4551
},
4652
Examples: []*core.Example{

internal/namespaces/object/v1/s3configfile.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type s3config struct {
3737
Region scw.Region
3838
Name string
3939
ctx context.Context
40+
ProjectID string
4041
}
4142

4243
const (
@@ -55,7 +56,7 @@ const s3cmdTemplate = `# Generated by scaleway-cli command
5556
# Configuration file for s3cmd https://s3tools.org/s3cmd
5657
# Default location: $HOME/.s3cfg
5758
[default]
58-
access_key = {{ .AccessKey }}
59+
access_key = {{ .AccessKey }}@{{ .ProjectID }}
5960
bucket_location = {{ .Region }}
6061
host_base = s3.{{ .Region }}.scw.cloud
6162
host_bucket = %(bucket)s.s3.{{ .Region }}.scw.cloud
@@ -71,7 +72,7 @@ type = s3
7172
provider = Scaleway
7273
env_auth = false
7374
endpoint = s3.{{ .Region }}.scw.cloud
74-
access_key_id = {{ .AccessKey }}
75+
access_key_id = {{ .AccessKey }}@{{ .ProjectID }}
7576
secret_access_key = {{ .SecretKey }}
7677
region = {{ .Region }}
7778
location_constraint =
@@ -87,16 +88,24 @@ func newS3Config(ctx context.Context, region scw.Region, name string) (s3config,
8788
if !accessExists {
8889
return s3config{}, errors.New("no access key found")
8990
}
91+
9092
secretKey, secretExists := client.GetSecretKey()
9193
if !secretExists {
9294
return s3config{}, errors.New("no secret key found")
9395
}
96+
97+
projectID, exists := client.GetDefaultProjectID()
98+
if !exists {
99+
return s3config{}, errors.New("no project ID found")
100+
}
101+
94102
config := s3config{
95103
AccessKey: accessKey,
96104
SecretKey: secretKey,
97105
Region: region,
98106
Name: name,
99107
ctx: ctx,
108+
ProjectID: projectID,
100109
}
101110

102111
return config, nil
@@ -144,6 +153,7 @@ func (c s3config) getConfigFile(tool s3tool) (core.RawResult, error) {
144153
AccessKey string `json:"accessKey"`
145154
SecretKey string `json:"secretKey"`
146155
API string `json:"api"`
156+
ProjectID string `json:"projectID"`
147157
}
148158
m := struct {
149159
Version string `json:"version"`
@@ -153,7 +163,7 @@ func (c s3config) getConfigFile(tool s3tool) (core.RawResult, error) {
153163
Hosts: map[string]hostconfig{
154164
c.Name: {
155165
URL: "https://s3." + c.Region.String() + ".scw.cloud",
156-
AccessKey: c.AccessKey,
166+
AccessKey: c.AccessKey + "@" + c.ProjectID,
157167
SecretKey: c.SecretKey,
158168
API: "S3v4",
159169
},
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
22
🟩🟩🟩 STDOUT️ 🟩🟩🟩️
3-
{"version":"9","hosts":{"scaleway":{"url":"https://s3.fr-par.scw.cloud","accessKey":"SCWXXXXXXXXXXXXXXXXX","secretKey":"11111111-1111-1111-1111-111111111111","api":"S3v4"}}}
3+
{"version":"9","hosts":{"scaleway":{"url":"https://s3.fr-par.scw.cloud","accessKey":"SCWXXXXXXXXXXXXXXXXX@11111111-1111-1111-1111-111111111111","secretKey":"11111111-1111-1111-1111-111111111111","api":"S3v4","projectID":""}}}
44
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
5-
{"version":"9","hosts":{"scaleway":{"url":"https://s3.fr-par.scw.cloud","accessKey":"SCWXXXXXXXXXXXXXXXXX","secretKey":"11111111-1111-1111-1111-111111111111","api":"S3v4"}}}
5+
{"version":"9","hosts":{"scaleway":{"url":"https://s3.fr-par.scw.cloud","accessKey":"SCWXXXXXXXXXXXXXXXXX@11111111-1111-1111-1111-111111111111","secretKey":"11111111-1111-1111-1111-111111111111","api":"S3v4","projectID":""}}}

internal/namespaces/object/v1/testdata/test-config-get-default-rclone.golden

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type = s3
88
provider = Scaleway
99
env_auth = false
1010
endpoint = s3.fr-par.scw.cloud
11-
access_key_id = SCWXXXXXXXXXXXXXXXXX
11+
access_key_id = SCWXXXXXXXXXXXXXXXXX@11111111-1111-1111-1111-111111111111
1212
secret_access_key = 11111111-1111-1111-1111-111111111111
1313
region = fr-par
1414
location_constraint =
@@ -25,7 +25,7 @@ type = s3
2525
provider = Scaleway
2626
env_auth = false
2727
endpoint = s3.fr-par.scw.cloud
28-
access_key_id = SCWXXXXXXXXXXXXXXXXX
28+
access_key_id = SCWXXXXXXXXXXXXXXXXX@11111111-1111-1111-1111-111111111111
2929
secret_access_key = 11111111-1111-1111-1111-111111111111
3030
region = fr-par
3131
location_constraint =

internal/namespaces/object/v1/testdata/test-config-get-default-s3cmd.golden

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Configuration file for s3cmd https://s3tools.org/s3cmd
55
# Default location: $HOME/.s3cfg
66
[default]
7-
access_key = SCWXXXXXXXXXXXXXXXXX
7+
access_key = SCWXXXXXXXXXXXXXXXXX@11111111-1111-1111-1111-111111111111
88
bucket_location = fr-par
99
host_base = s3.fr-par.scw.cloud
1010
host_bucket = %(bucket)s.s3.fr-par.scw.cloud
@@ -15,7 +15,7 @@ use_https = True
1515
# Configuration file for s3cmd https://s3tools.org/s3cmd
1616
# Default location: $HOME/.s3cfg
1717
[default]
18-
access_key = SCWXXXXXXXXXXXXXXXXX
18+
access_key = SCWXXXXXXXXXXXXXXXXX@11111111-1111-1111-1111-111111111111
1919
bucket_location = fr-par
2020
host_base = s3.fr-par.scw.cloud
2121
host_bucket = %(bucket)s.s3.fr-par.scw.cloud
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
22
🟩🟩🟩 STDOUT️ 🟩🟩🟩️
3-
{"version":"9","hosts":{"scaleway":{"url":"https://s3.nl-ams.scw.cloud","accessKey":"SCWXXXXXXXXXXXXXXXXX","secretKey":"11111111-1111-1111-1111-111111111111","api":"S3v4"}}}
3+
{"version":"9","hosts":{"scaleway":{"url":"https://s3.nl-ams.scw.cloud","accessKey":"SCWXXXXXXXXXXXXXXXXX@11111111-1111-1111-1111-111111111111","secretKey":"11111111-1111-1111-1111-111111111111","api":"S3v4","projectID":""}}}
44
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
5-
{"version":"9","hosts":{"scaleway":{"url":"https://s3.nl-ams.scw.cloud","accessKey":"SCWXXXXXXXXXXXXXXXXX","secretKey":"11111111-1111-1111-1111-111111111111","api":"S3v4"}}}
5+
{"version":"9","hosts":{"scaleway":{"url":"https://s3.nl-ams.scw.cloud","accessKey":"SCWXXXXXXXXXXXXXXXXX@11111111-1111-1111-1111-111111111111","secretKey":"11111111-1111-1111-1111-111111111111","api":"S3v4","projectID":""}}}

internal/namespaces/object/v1/testdata/test-config-get-with-region-rclone.golden

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type = s3
88
provider = Scaleway
99
env_auth = false
1010
endpoint = s3.nl-ams.scw.cloud
11-
access_key_id = SCWXXXXXXXXXXXXXXXXX
11+
access_key_id = SCWXXXXXXXXXXXXXXXXX@11111111-1111-1111-1111-111111111111
1212
secret_access_key = 11111111-1111-1111-1111-111111111111
1313
region = nl-ams
1414
location_constraint =
@@ -25,7 +25,7 @@ type = s3
2525
provider = Scaleway
2626
env_auth = false
2727
endpoint = s3.nl-ams.scw.cloud
28-
access_key_id = SCWXXXXXXXXXXXXXXXXX
28+
access_key_id = SCWXXXXXXXXXXXXXXXXX@11111111-1111-1111-1111-111111111111
2929
secret_access_key = 11111111-1111-1111-1111-111111111111
3030
region = nl-ams
3131
location_constraint =

internal/namespaces/object/v1/testdata/test-config-get-with-region-s3cmd.golden

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Configuration file for s3cmd https://s3tools.org/s3cmd
55
# Default location: $HOME/.s3cfg
66
[default]
7-
access_key = SCWXXXXXXXXXXXXXXXXX
7+
access_key = SCWXXXXXXXXXXXXXXXXX@11111111-1111-1111-1111-111111111111
88
bucket_location = nl-ams
99
host_base = s3.nl-ams.scw.cloud
1010
host_bucket = %(bucket)s.s3.nl-ams.scw.cloud
@@ -15,7 +15,7 @@ use_https = True
1515
# Configuration file for s3cmd https://s3tools.org/s3cmd
1616
# Default location: $HOME/.s3cfg
1717
[default]
18-
access_key = SCWXXXXXXXXXXXXXXXXX
18+
access_key = SCWXXXXXXXXXXXXXXXXX@11111111-1111-1111-1111-111111111111
1919
bucket_location = nl-ams
2020
host_base = s3.nl-ams.scw.cloud
2121
host_bucket = %(bucket)s.s3.nl-ams.scw.cloud

0 commit comments

Comments
 (0)