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: client validation #238

Merged
merged 4 commits into from
Nov 14, 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
10 changes: 5 additions & 5 deletions scw/client_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ func (s *settings) validate() error {
return NewClientValidationError("access key cannot be empty")
}
if !validation.IsAccessKey(token.AccessKey) {
return NewClientValidationError("bad access key format")
return NewClientValidationError("invalid access key format '%s', must be: SCWXXXXXXXXXXXXXXXXX", token.AccessKey)
}
if token.SecretKey == "" {
return NewClientValidationError("secret key cannot be empty")
}
if !validation.IsSecretKey(token.SecretKey) {
return NewClientValidationError("bad secret key format")
return NewClientValidationError("invalid access key format '%s', must be: SCWXXXXXXXXXXXXXXXXX", token.AccessKey)
QuentinBrosse marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand All @@ -197,7 +197,7 @@ func (s *settings) validate() error {
return NewClientValidationError("default organization ID cannot be empty")
}
if !validation.IsOrganizationID(*s.defaultOrganizationID) {
return NewClientValidationError("default organization ID must be a valid UUID")
return NewClientValidationError("invalid organization ID format '%s', must be an UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", *s.defaultOrganizationID)
QuentinBrosse marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand All @@ -211,7 +211,7 @@ func (s *settings) validate() error {
for _, r := range AllRegions {
regions = append(regions, string(r))
}
return NewClientValidationError("bad default region format, available regions are: %s", strings.Join(regions, ", "))
return NewClientValidationError("invalid default region format '%s', available regions are: %s", *s.defaultRegion, strings.Join(regions, ", "))
}
}

Expand All @@ -225,7 +225,7 @@ func (s *settings) validate() error {
for _, z := range AllZones {
zones = append(zones, string(z))
}
return NewClientValidationError("bad default zone format, available zones are: %s", strings.Join(zones, ", "))
return NewClientValidationError("invalid default zone format '%s', available zones are: %s", *s.defaultZone, strings.Join(zones, ", "))
}
}

Expand Down
10 changes: 5 additions & 5 deletions scw/client_option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestClientOptions(t *testing.T) {
clientOption: func(s *settings) {
s.token = auth.NewToken(v2InvalidAccessKey, v2ValidSecretKey)
},
errStr: "scaleway-sdk-go: bad access key format",
errStr: "scaleway-sdk-go: invalid access key format 'invalid', must be: SCWXXXXXXXXXXXXXXXXX",
},
{
name: "Should throw an empty secret key error",
Expand All @@ -62,7 +62,7 @@ func TestClientOptions(t *testing.T) {
clientOption: func(s *settings) {
s.token = auth.NewToken(v2ValidAccessKey, v2InvalidSecretKey)
},
errStr: "scaleway-sdk-go: bad secret key format",
errStr: "scaleway-sdk-go: invalid access key format 'SCW1234567890ABCDEFG', must be: SCWXXXXXXXXXXXXXXXXX",
},
{
name: "Should throw an url error",
Expand All @@ -86,7 +86,7 @@ func TestClientOptions(t *testing.T) {
s.token = auth.NewToken(v2ValidAccessKey, v2ValidSecretKey)
s.defaultOrganizationID = StringPtr(v2InvalidDefaultOrganizationID)
},
errStr: "scaleway-sdk-go: default organization ID must be a valid UUID",
errStr: "scaleway-sdk-go: invalid organization ID format 'invalid', must be an UUID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
},
{
name: "Should throw a region error",
Expand All @@ -104,7 +104,7 @@ func TestClientOptions(t *testing.T) {
s.token = auth.NewToken(testAccessKey, testSecretKey)
s.defaultRegion = &v
},
errStr: "scaleway-sdk-go: bad default region format, available regions are: fr-par, nl-ams",
errStr: "scaleway-sdk-go: invalid default region format 'invalid', available regions are: fr-par, nl-ams",
},
{
name: "Should throw a zone error",
Expand All @@ -122,7 +122,7 @@ func TestClientOptions(t *testing.T) {
s.token = auth.NewToken(testAccessKey, testSecretKey)
s.defaultZone = &v
},
errStr: "scaleway-sdk-go: bad default zone format, available zones are: fr-par-1, fr-par-2, nl-ams-1",
errStr: "scaleway-sdk-go: invalid default zone format 'invalid', available zones are: fr-par-1, fr-par-2, nl-ams-1",
},
}

Expand Down