Skip to content
Snippets Groups Projects
Commit 4e6fe6c7 authored by Rohith's avatar Rohith
Browse files

- adding the require-any-roles attributes to the resource

parent ff204ed5
Branches
No related tags found
No related merge requests found
...@@ -130,6 +130,8 @@ type Resource struct { ...@@ -130,6 +130,8 @@ type Resource struct {
Methods []string `json:"methods" yaml:"methods"` Methods []string `json:"methods" yaml:"methods"`
// WhiteListed permits the prefix through // WhiteListed permits the prefix through
WhiteListed bool `json:"white-listed" yaml:"white-listed"` WhiteListed bool `json:"white-listed" yaml:"white-listed"`
// RequireAnyRole indicates that ANY of the roles are required, the default is all
RequireAnyRole bool `json:"require-any-role yaml:"require-any-role"`
// Roles the roles required to access this url // Roles the roles required to access this url
Roles []string `json:"roles" yaml:"roles"` Roles []string `json:"roles" yaml:"roles"`
// Groups is a list of groups the user is in // Groups is a list of groups the user is in
......
...@@ -51,6 +51,12 @@ func (r *Resource) parse(resource string) (*Resource, error) { ...@@ -51,6 +51,12 @@ func (r *Resource) parse(resource string) (*Resource, error) {
r.Methods = allHTTPMethods r.Methods = allHTTPMethods
} }
} }
case "require-any-role":
v, err := strconv.ParseBool(kp[1])
if err != nil {
return nil, err
}
r.RequireAnyRole = v
case "roles": case "roles":
r.Roles = strings.Split(kp[1], ",") r.Roles = strings.Split(kp[1], ",")
case "groups": case "groups":
......
...@@ -30,6 +30,7 @@ func TestDecodeResourceBad(t *testing.T) { ...@@ -30,6 +30,7 @@ func TestDecodeResourceBad(t *testing.T) {
{Option: "uri"}, {Option: "uri"},
{Option: "uri=hello"}, {Option: "uri=hello"},
{Option: "uri=/|white-listed=ERROR"}, {Option: "uri=/|white-listed=ERROR"},
{Option: "uri=/|require-any-role=BAD"},
} }
for i, c := range cs { for i, c := range cs {
if _, err := newResource().parse(c.Option); err == nil { if _, err := newResource().parse(c.Option); err == nil {
...@@ -79,6 +80,10 @@ func TestResourceParseOk(t *testing.T) { ...@@ -79,6 +80,10 @@ func TestResourceParseOk(t *testing.T) {
Option: "uri=/*|groups=admin", Option: "uri=/*|groups=admin",
Resource: &Resource{URL: "/*", Methods: allHTTPMethods, Groups: []string{"admin"}}, Resource: &Resource{URL: "/*", Methods: allHTTPMethods, Groups: []string{"admin"}},
}, },
{
Option: "uri=/*|require-any-role=true",
Resource: &Resource{URL: "/*", Methods: allHTTPMethods, RequireAnyRole: true},
},
} }
for i, x := range cs { for i, x := range cs {
r, err := newResource().parse(x.Option) r, err := newResource().parse(x.Option)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment