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(core): add send_usage setting in the config #273

Merged
merged 3 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions scw/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ const configFileTemplate = `# Scaleway configuration file
# This single default configuration is suitable for most use cases.
{{ if .ActiveProfile }}active_profile: {{ .ActiveProfile }}{{ else }}# active_profile: myProfile{{ end }}

# Help us improve your experience by automatically sending diagnostic and usage data.
# ;-) we solemnly swear that we will only use this data to make the world a better place.
{{ if .SendUsage }}send_usage: true{{ else }}# send_usage: false{{ end }}

# To work with multiple projects or authorization accounts, you can set up multiple configurations with scw config configurations create and switch among them accordingly.
# You can use a profile by either:
# - Define the profile you want to use as the SCW_PROFILE environment variable
Expand Down Expand Up @@ -94,6 +98,7 @@ profiles:
type Config struct {
Profile `yaml:",inline"`
ActiveProfile *string `yaml:"active_profile,omitempty"`
SendUsage bool `yaml:"send_usage,omitempty"`
Profiles map[string]*Profile `yaml:"profiles,omitempty"`
}

Expand Down
24 changes: 24 additions & 0 deletions scw/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var (
v2ValidSecretKey2 = "6f6e6574-6f72-756c-6c74-68656d616c6c" // hint: | xxd -ps -r
v2ValidAPIURL2 = "api-fr-par.scaleway.com"
v2ValidInsecure2 = "true"
v2ValidSendUsage2 = "true"
v2ValidDefaultOrganizationID2 = "6d6f7264-6f72-6772-6561-74616761696e" // hint: | xxd -ps -r
v2ValidDefaultRegion2 = string(RegionFrPar)
v2ValidDefaultZone2 = string(ZoneFrPar2)
Expand All @@ -27,6 +28,7 @@ var (
v2ValidSecretKey = "7363616c-6577-6573-6862-6f7579616161" // hint: | xxd -ps -r
v2ValidAPIURL = "api.scaleway.com"
v2ValidInsecure = "false"
v2ValidSendUsage = "true"
v2ValidDefaultOrganizationID = "6170692e-7363-616c-6577-61792e636f6d" // hint: | xxd -ps -r
v2ValidDefaultRegion = string(RegionNlAms)
v2ValidDefaultZone = string(ZoneNlAms1)
Expand Down Expand Up @@ -62,6 +64,7 @@ profiles:
secret_key: ` + v2ValidSecretKey2 + `
api_url: ` + v2ValidAPIURL2 + `
insecure: ` + v2ValidInsecure2 + `
send_usage: ` + v2ValidSendUsage2 + `
default_organization_id: ` + v2ValidDefaultOrganizationID2 + `
default_region: ` + v2ValidDefaultRegion2 + `
default_zone: ` + v2ValidDefaultZone2 + `
Expand All @@ -72,6 +75,7 @@ access_key: ` + v2ValidAccessKey + `
secret_key: ` + v2ValidSecretKey + `
api_url: ` + v2ValidAPIURL + `
insecure: ` + v2ValidInsecure + `
send_usage: ` + v2ValidSendUsage2 + `
default_organization_id: ` + v2ValidDefaultOrganizationID + `
default_region: ` + v2ValidDefaultRegion + `
default_zone: ` + v2ValidDefaultZone + `
Expand All @@ -92,6 +96,7 @@ access_key: ` + v2ValidAccessKey + `
secret_key: ` + v2ValidSecretKey + `
api_url: ` + v2ValidAPIURL + `
insecure: ` + v2ValidInsecure + `
send_usage: ` + v2ValidSendUsage + `
default_organization_id: ` + v2ValidDefaultOrganizationID + `
default_region: ` + v2ValidDefaultRegion + `
default_zone: ` + v2ValidDefaultZone + `
Expand Down Expand Up @@ -254,6 +259,7 @@ func TestLoadProfileAndActiveProfile(t *testing.T) {
expectedSecretKey *string
expectedAPIURL *string
expectedInsecure *bool
expectedSendUsage bool
expectedDefaultOrganizationID *string
expectedDefaultRegion *string
expectedDefaultZone *string
Expand Down Expand Up @@ -362,6 +368,7 @@ func TestLoadProfileAndActiveProfile(t *testing.T) {
expectedDefaultOrganizationID: s(v2ValidDefaultOrganizationID2),
expectedDefaultRegion: s(v2ValidDefaultRegion2),
expectedDefaultZone: s(v2ValidDefaultZone2),
expectedSendUsage: true,
},
{
name: "Mixed config with active profile",
Expand All @@ -378,6 +385,7 @@ func TestLoadProfileAndActiveProfile(t *testing.T) {
expectedDefaultOrganizationID: s(v2ValidDefaultOrganizationID),
expectedDefaultRegion: s(v2ValidDefaultRegion),
expectedDefaultZone: s(v2ValidDefaultZone),
expectedSendUsage: true,
},
{
name: "Complete config with active profile env variable",
Expand Down Expand Up @@ -459,6 +467,7 @@ func TestLoadProfileAndActiveProfile(t *testing.T) {
testhelpers.Equals(t, test.expectedDefaultRegion, p.DefaultRegion)
testhelpers.Equals(t, test.expectedDefaultZone, p.DefaultZone)
testhelpers.Equals(t, test.expectedInsecure, p.Insecure)
testhelpers.Equals(t, test.expectedSendUsage, config.SendUsage)
} else {
testhelpers.Equals(t, test.expectedError, err.Error())
}
Expand All @@ -474,6 +483,7 @@ func TestConfigString(t *testing.T) {
SecretKey: s(v2ValidSecretKey),
},
ActiveProfile: s(v2ValidProfile),
SendUsage: true,
Profiles: map[string]*Profile{
v2ValidProfile: {
AccessKey: s(v2ValidAccessKey2),
Expand All @@ -485,6 +495,7 @@ func TestConfigString(t *testing.T) {
testhelpers.Equals(t, `access_key: SCW1234567890ABCDEFG
secret_key: 7363616c-xxxx-xxxx-xxxx-xxxxxxxxxxxx
active_profile: flantier
send_usage: true
profiles:
flantier:
access_key: SCW234567890ABCDEFGH
Expand Down Expand Up @@ -644,6 +655,10 @@ func TestConfig_ConfigFile(t *testing.T) {
# This single default configuration is suitable for most use cases.
# active_profile: myProfile

# Help us improve your experience by automatically sending diagnostic and usage data.
# ;-) we solemnly swear that we will only use this data to make the world a better place.
# send_usage: false

# To work with multiple projects or authorization accounts, you can set up multiple configurations with scw config configurations create and switch among them accordingly.
# You can use a profile by either:
# - Define the profile you want to use as the SCW_PROFILE environment variable
Expand Down Expand Up @@ -709,6 +724,10 @@ access_key: SCW1234567890ABCDEFG
# This single default configuration is suitable for most use cases.
# active_profile: myProfile

# Help us improve your experience by automatically sending diagnostic and usage data.
# ;-) we solemnly swear that we will only use this data to make the world a better place.
# send_usage: false

# To work with multiple projects or authorization accounts, you can set up multiple configurations with scw config configurations create and switch among them accordingly.
# You can use a profile by either:
# - Define the profile you want to use as the SCW_PROFILE environment variable
Expand Down Expand Up @@ -736,6 +755,7 @@ access_key: SCW1234567890ABCDEFG
SecretKey: s(v2ValidSecretKey),
},
ActiveProfile: s(v2ValidProfile),
SendUsage: true,
Profiles: map[string]*Profile{
"profile1": {
AccessKey: s(v2ValidAccessKey2),
Expand Down Expand Up @@ -787,6 +807,10 @@ secret_key: 7363616c-6577-6573-6862-6f7579616161
# This single default configuration is suitable for most use cases.
active_profile: flantier

# Help us improve your experience by automatically sending diagnostic and usage data.
# ;-) we solemnly swear that we will only use this data to make the world a better place.
send_usage: true

# To work with multiple projects or authorization accounts, you can set up multiple configurations with scw config configurations create and switch among them accordingly.
# You can use a profile by either:
# - Define the profile you want to use as the SCW_PROFILE environment variable
Expand Down