Skip to content

Commit

Permalink
Changed policiesList and rolesList from declaration to definition to …
Browse files Browse the repository at this point in the history
…fix nil error in encoding/json. golang/go#27589 (comment)
  • Loading branch information
xlanor committed Oct 1, 2020
1 parent d3894f2 commit 94e981d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions engine/ladon/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,7 @@ func (e *Engine) Register(r *httprouter.Router) {
}

func (e *Engine) rolesList(ctx context.Context, r *http.Request, ps httprouter.Params) (*kstorage.ListRequest, error) {
var p kstorage.Roles

p := make([]kstorage.Role, 0)
f, err := flavor(ps)
if err != nil {
return nil, err
Expand Down Expand Up @@ -428,8 +427,8 @@ func (e *Engine) policiesCreate(ctx context.Context, r *http.Request, ps httprou
}

func (e *Engine) policiesList(ctx context.Context, r *http.Request, ps httprouter.Params) (*kstorage.ListRequest, error) {
var p kstorage.Policies

p := make([]kstorage.Policy, 0)
f, err := flavor(ps)
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions storage/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ func (l *ListRequest) Filter(m map[string][]string) *ListRequest {

func ListByQuery(l *ListRequest, m map[string][]string) {
switch val := l.Value.(type) {
case *Roles:
var res Roles
case *[]Role:
res := make([]Role, 0)
for _, role := range *val {
filteredRole := role.withMembers(m["member"]).withIDs(m["id"])
if filteredRole != nil {
res = append(res, *filteredRole)
}
}
l.Value = &res
case *Policies:
var res Policies
case *[]Policy:
res := make([]Policy, 0)
for _, policy := range *val {
filteredPolicy := policy.withSubjects(m["subject"]).withResources(m["resource"]).withActions(m["action"]).withIDs(m["id"])
if filteredPolicy != nil {
Expand Down

0 comments on commit 94e981d

Please sign in to comment.