-
Notifications
You must be signed in to change notification settings - Fork 44
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
Add scope property to policy #687
Add scope property to policy #687
Conversation
c08a86c
to
6c4ff3c
Compare
6c4ff3c
to
64fe077
Compare
Ran gofmt on policy.go and changed "pass" to "match (on)" in new tests. |
schema/policy.go
Outdated
func (policy *Policy) parseTokenScope(typeData map[string]interface{}) error { | ||
if scopeRaw, ok := typeData["scope"]; ok { | ||
var types []interface{} | ||
if scope, ok := scopeRaw.(string); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a difference in semantics in string
and 1-element array of strings? if not, wouldn't it be simpler to support just lists?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no difference. I can remove support for single strings.
} | ||
|
||
func (policy *Policy) parseTokenScope(typeData map[string]interface{}) error { | ||
if scopeRaw, ok := typeData["scope"]; ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flipping the if
condition will reduce indents:
if scopeRaw, ok := typeData["scope"]; !ok {
policy.tokenScope = allTokenTypes
return nil
}
likewise in other places: in fact I prefer the style of
if fail() {
return errFail
}
if otherFail() {
return errOtherFail
}
//happy path follows
over
if !fail(){
if !otherFail() {
// happy path
} else {
return errOtherFail
}
} else {
return errFail
}
schema/policy_test.go
Outdated
|
||
It("should fail to create when non-string is provided in scope list", func() { | ||
givenPolicyWithScope([]interface{}{"admin", 123}) | ||
thenCreationShouldFail("Token type at position 1 in scope list should be a string") | ||
}) | ||
|
||
It("should fail to create when invalid token type is provided", func() { | ||
givenPolicyWithScope("flower") | ||
It("should fail to create when a string is provided", func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fail because of a string (not list of strings) is covered in the second Entry
of should fail to create when invalid value type is provided
. here we're checking if creation fails because of an invalid value
fbea807
to
bbc2c7f
Compare
Squashed commits, waiting for CI |
An alternative to is_domain_owner (#686)