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(object): add support for IAM Access Key syntax #4543

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions docs/commands/object.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ scw object config get [arg=value ...]
|------|---|-------------|
| type | Required<br />One of: `rclone`, `s3cmd`, `mc` | Type of S3 tool you want to generate a config for |
| name | Default: `scaleway` | Name of the s3 remote you want to generate |
| project-id | | Scaleway project ID to use with IAM Access Key syntax |
| region | Default: `fr-par`<br />One of: `fr-par`, `nl-ams` | Region to target. If none is passed will use default region from the config |


Expand Down Expand Up @@ -187,6 +188,7 @@ scw object config install [arg=value ...]
|------|---|-------------|
| type | Required<br />One of: `rclone`, `s3cmd`, `mc` | Type of S3 tool you want to generate a config for |
| name | Default: `scaleway` | Name of the s3 remote you want to generate |
| project-id | | Scaleway project ID to use with IAM Access Key syntax |
| region | Default: `fr-par`<br />One of: `fr-par`, `nl-ams` | Region to target. If none is passed will use default region from the config |


Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func Test_ConfigInstall(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
16 changes: 14 additions & 2 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 Down Expand Up @@ -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,10 +88,20 @@ 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")
}
Comment on lines +97 to +100
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it should be optional


if projectID != "" {
accessKey+="@"+projectID
}
config := s3config{
AccessKey: accessKey,
SecretKey: secretKey,
Expand Down Expand Up @@ -144,6 +155,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 +165,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
Loading