Skip to content

Commit

Permalink
feat(object): add support for IAM Access Key syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
remyleone committed Feb 25, 2025
1 parent 3306535 commit 293a269
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 15 deletions.
6 changes: 6 additions & 0 deletions internal/namespaces/object/v1/custom_config_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ func configGetCommand() *core.Command {
Required: false,
Default: core.DefaultValueSetter("scaleway"),
},
{
Name: "project-id",
Short: "Scaleway project ID to use with IAM Access Key syntax",
Required: false,
ValidateFunc: core.ValidateProjectID(),
},
core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms),
},
Examples: []*core.Example{
Expand Down
1 change: 1 addition & 0 deletions internal/namespaces/object/v1/custom_config_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func Test_ConfigGet(t *testing.T) {
"11111111-1111-1111-1111-111111111111",
),
scw.WithDefaultOrganizationID("11111111-1111-1111-1111-111111111111"),
scw.WithDefaultProjectID("11111111-1111-1111-1111-111111111111"),
scw.WithDefaultZone(scw.ZoneFrPar1),
scw.WithDefaultRegion(scw.RegionFrPar),
)
Expand Down
6 changes: 6 additions & 0 deletions internal/namespaces/object/v1/custom_config_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ func configInstallCommand() *core.Command {
Required: false,
Default: core.DefaultValueSetter("scaleway"),
},
{
Name: "project-id",
Short: "Scaleway project ID to use with IAM Access Key syntax",
Required: false,
ValidateFunc: core.ValidateProjectID(),
},
core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms),
},
Examples: []*core.Example{
Expand Down
16 changes: 13 additions & 3 deletions internal/namespaces/object/v1/s3configfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type s3config struct {
Region scw.Region
Name string
ctx context.Context
ProjectID string
}

const (
Expand All @@ -55,7 +56,7 @@ const s3cmdTemplate = `# Generated by scaleway-cli command
# Configuration file for s3cmd https://s3tools.org/s3cmd
# Default location: $HOME/.s3cfg
[default]
access_key = {{ .AccessKey }}
access_key = {{ .AccessKey }}@{{ .ProjectID }}
bucket_location = {{ .Region }}
host_base = s3.{{ .Region }}.scw.cloud
host_bucket = %(bucket)s.s3.{{ .Region }}.scw.cloud
Expand All @@ -71,7 +72,7 @@ type = s3
provider = Scaleway
env_auth = false
endpoint = s3.{{ .Region }}.scw.cloud
access_key_id = {{ .AccessKey }}
access_key_id = {{ .AccessKey }}@{{ .ProjectID }}
secret_access_key = {{ .SecretKey }}
region = {{ .Region }}
location_constraint =
Expand All @@ -87,16 +88,24 @@ func newS3Config(ctx context.Context, region scw.Region, name string) (s3config,
if !accessExists {
return s3config{}, errors.New("no access key found")
}

secretKey, secretExists := client.GetSecretKey()
if !secretExists {
return s3config{}, errors.New("no secret key found")
}

projectID, exists := client.GetDefaultProjectID()
if !exists {
return s3config{}, errors.New("no project ID found")
}

config := s3config{
AccessKey: accessKey,
SecretKey: secretKey,
Region: region,
Name: name,
ctx: ctx,
ProjectID: projectID,
}

return config, nil
Expand Down Expand Up @@ -144,6 +153,7 @@ func (c s3config) getConfigFile(tool s3tool) (core.RawResult, error) {
AccessKey string `json:"accessKey"`
SecretKey string `json:"secretKey"`
API string `json:"api"`
ProjectID string `json:"projectID"`
}
m := struct {
Version string `json:"version"`
Expand All @@ -153,7 +163,7 @@ func (c s3config) getConfigFile(tool s3tool) (core.RawResult, error) {
Hosts: map[string]hostconfig{
c.Name: {
URL: "https://s3." + c.Region.String() + ".scw.cloud",
AccessKey: c.AccessKey,
AccessKey: c.AccessKey + "@" + c.ProjectID,
SecretKey: c.SecretKey,
API: "S3v4",
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟩🟩🟩 STDOUT️ 🟩🟩🟩️
{"version":"9","hosts":{"scaleway":{"url":"https://s3.fr-par.scw.cloud","accessKey":"SCWXXXXXXXXXXXXXXXXX","secretKey":"11111111-1111-1111-1111-111111111111","api":"S3v4"}}}
{"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":""}}}
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
{"version":"9","hosts":{"scaleway":{"url":"https://s3.fr-par.scw.cloud","accessKey":"SCWXXXXXXXXXXXXXXXXX","secretKey":"11111111-1111-1111-1111-111111111111","api":"S3v4"}}}
{"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":""}}}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type = s3
provider = Scaleway
env_auth = false
endpoint = s3.fr-par.scw.cloud
access_key_id = SCWXXXXXXXXXXXXXXXXX
access_key_id = SCWXXXXXXXXXXXXXXXXX@11111111-1111-1111-1111-111111111111
secret_access_key = 11111111-1111-1111-1111-111111111111
region = fr-par
location_constraint =
Expand All @@ -25,7 +25,7 @@ type = s3
provider = Scaleway
env_auth = false
endpoint = s3.fr-par.scw.cloud
access_key_id = SCWXXXXXXXXXXXXXXXXX
access_key_id = SCWXXXXXXXXXXXXXXXXX@11111111-1111-1111-1111-111111111111
secret_access_key = 11111111-1111-1111-1111-111111111111
region = fr-par
location_constraint =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Configuration file for s3cmd https://s3tools.org/s3cmd
# Default location: $HOME/.s3cfg
[default]
access_key = SCWXXXXXXXXXXXXXXXXX
access_key = SCWXXXXXXXXXXXXXXXXX@11111111-1111-1111-1111-111111111111
bucket_location = fr-par
host_base = s3.fr-par.scw.cloud
host_bucket = %(bucket)s.s3.fr-par.scw.cloud
Expand All @@ -15,7 +15,7 @@ use_https = True
# Configuration file for s3cmd https://s3tools.org/s3cmd
# Default location: $HOME/.s3cfg
[default]
access_key = SCWXXXXXXXXXXXXXXXXX
access_key = SCWXXXXXXXXXXXXXXXXX@11111111-1111-1111-1111-111111111111
bucket_location = fr-par
host_base = s3.fr-par.scw.cloud
host_bucket = %(bucket)s.s3.fr-par.scw.cloud
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟩🟩🟩 STDOUT️ 🟩🟩🟩️
{"version":"9","hosts":{"scaleway":{"url":"https://s3.nl-ams.scw.cloud","accessKey":"SCWXXXXXXXXXXXXXXXXX","secretKey":"11111111-1111-1111-1111-111111111111","api":"S3v4"}}}
{"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":""}}}
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
{"version":"9","hosts":{"scaleway":{"url":"https://s3.nl-ams.scw.cloud","accessKey":"SCWXXXXXXXXXXXXXXXXX","secretKey":"11111111-1111-1111-1111-111111111111","api":"S3v4"}}}
{"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":""}}}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type = s3
provider = Scaleway
env_auth = false
endpoint = s3.nl-ams.scw.cloud
access_key_id = SCWXXXXXXXXXXXXXXXXX
access_key_id = SCWXXXXXXXXXXXXXXXXX@11111111-1111-1111-1111-111111111111
secret_access_key = 11111111-1111-1111-1111-111111111111
region = nl-ams
location_constraint =
Expand All @@ -25,7 +25,7 @@ type = s3
provider = Scaleway
env_auth = false
endpoint = s3.nl-ams.scw.cloud
access_key_id = SCWXXXXXXXXXXXXXXXXX
access_key_id = SCWXXXXXXXXXXXXXXXXX@11111111-1111-1111-1111-111111111111
secret_access_key = 11111111-1111-1111-1111-111111111111
region = nl-ams
location_constraint =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Configuration file for s3cmd https://s3tools.org/s3cmd
# Default location: $HOME/.s3cfg
[default]
access_key = SCWXXXXXXXXXXXXXXXXX
access_key = SCWXXXXXXXXXXXXXXXXX@11111111-1111-1111-1111-111111111111
bucket_location = nl-ams
host_base = s3.nl-ams.scw.cloud
host_bucket = %(bucket)s.s3.nl-ams.scw.cloud
Expand All @@ -15,7 +15,7 @@ use_https = True
# Configuration file for s3cmd https://s3tools.org/s3cmd
# Default location: $HOME/.s3cfg
[default]
access_key = SCWXXXXXXXXXXXXXXXXX
access_key = SCWXXXXXXXXXXXXXXXXX@11111111-1111-1111-1111-111111111111
bucket_location = nl-ams
host_base = s3.nl-ams.scw.cloud
host_bucket = %(bucket)s.s3.nl-ams.scw.cloud
Expand Down

0 comments on commit 293a269

Please sign in to comment.