Skip to content

Commit

Permalink
Merge pull request #19 from aserto-dev/visitor
Browse files Browse the repository at this point in the history
ANTLR Parser
  • Loading branch information
ronenh authored Dec 7, 2023
2 parents c7bef70 + 92393bc commit acd8c3b
Show file tree
Hide file tree
Showing 42 changed files with 6,301 additions and 2,429 deletions.
31 changes: 17 additions & 14 deletions cache/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ func (c *Cache) ExpandRelation(on model.ObjectName, rn model.RelationName) []mod
}

// get relation set for given object:relation.
rs := c.model.Objects[on].Relations[rn]
r := c.model.Objects[on].Relations[rn]

// include given permission in result set
results = append(results, rn)

// iterate through relation set, determine if it "unions" with the given relation.
for _, r := range rs {
for _, rt := range r.Union {
switch {
case r.Subject != nil && r.Subject.Object == on:
results = append(results, r.Subject.Relation)
case r.Direct != "":
results = append(results, c.ExpandRelation(on, model.RelationName(r.Direct))...)
case rt.Subject != nil && rt.Subject.Object == on:
results = append(results, rt.Subject.Relation)
case rt.Direct != nil:
results = append(results, c.ExpandRelation(on, model.RelationName(rt.Direct.Object))...)
}
}

Expand Down Expand Up @@ -70,18 +70,21 @@ func (c *Cache) ExpandPermission(on model.ObjectName, pn model.PermissionName) [
}

// convert union []string to []model.RelationName.
func (c *Cache) expandUnion(o *model.Object, u ...string) []model.RelationName {
func (c *Cache) expandUnion(o *model.Object, u ...*model.PermissionRef) []model.RelationName {
result := []model.RelationName{}
for _, v := range u {
rn := model.RelationName(v)
for _, ref := range u {
if ref.Base != "" {
panic("expandUnion: arrow permissions not supported yet")
}
rn := model.RelationName(ref.RelOrPerm)
result = append(result, rn)

exp := lo.FilterMap(o.Relations[rn], func(r *model.Relation, _ int) (string, bool) {
if r.Direct == "" {
return "", false
exp := lo.FilterMap(o.Relations[rn].Union, func(r *model.RelationTerm, _ int) (*model.PermissionRef, bool) {
if r.Direct == nil {
return &model.PermissionRef{}, false
}
_, ok := o.Relations[model.RelationName(r.Direct)]
return string(r.Direct), ok
_, ok := o.Relations[model.RelationName(r.Direct.Object)]
return &model.PermissionRef{RelOrPerm: string(r.Direct.Object)}, ok

})
result = append(result, c.expandUnion(o, exp...)...)
Expand Down
4 changes: 2 additions & 2 deletions cache/expand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/aserto-dev/azm/cache"
"github.com/aserto-dev/azm/model"
v3 "github.com/aserto-dev/azm/v3"
v2 "github.com/aserto-dev/azm/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -35,7 +35,7 @@ func loadFromManifest(t *testing.T, path string) *cache.Cache { // nolint:unused
require.NoError(t, err)
defer r.Close()

m, err := v3.Load(r)
m, err := v2.Load(r)
require.NoError(t, err)

cachefile := strings.TrimSuffix(path, filepath.Ext(path)) + ".json"
Expand Down
Loading

0 comments on commit acd8c3b

Please sign in to comment.