Skip to content

Commit

Permalink
Unify listing rule formats
Browse files Browse the repository at this point in the history
  • Loading branch information
bersace committed May 14, 2024
1 parent d687d61 commit 69a3c13
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
23 changes: 14 additions & 9 deletions internal/wanted/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ type GrantRule struct {
}

func (r GrantRule) IsStatic() bool {
return r.Database.IsStatic() &&
r.Object.IsStatic() &&
r.Owner.IsStatic() &&
r.Schema.IsStatic() &&
r.To.IsStatic() &&
r.Privilege.IsStatic()
return lists.And(r.Formats(), func(f pyfmt.Format) bool { return f.IsStatic() })
}

func (r GrantRule) Formats() []pyfmt.Format {
return []pyfmt.Format{r.Owner, r.Privilege, r.Database, r.Schema, r.Object, r.To}
}

func (r GrantRule) Generate(results *ldap.Result, privileges privilege.RefMap) <-chan privilege.Grant {
Expand Down Expand Up @@ -94,9 +93,15 @@ type RoleRule struct {
}

func (r RoleRule) IsStatic() bool {
return r.Name.IsStatic() &&
r.Comment.IsStatic() &&
lists.And(r.Parents, func(m MembershipRule) bool { return m.IsStatic() })
return lists.And(r.Formats(), func(f pyfmt.Format) bool { return f.IsStatic() })
}

func (r RoleRule) Formats() []pyfmt.Format {
fmts := []pyfmt.Format{r.Name, r.Comment}
for _, p := range r.Parents {
fmts = append(fmts, p.Name)
}
return fmts
}

func (r RoleRule) Generate(results *ldap.Result) <-chan role.Role {
Expand Down
15 changes: 2 additions & 13 deletions internal/wanted/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,14 @@ func (s Step) IterFields() <-chan *pyfmt.Field {
go func() {
defer close(ch)
for _, rule := range s.RoleRules {
allFormats := []pyfmt.Format{
rule.Name, rule.Comment,
}
for _, p := range rule.Parents {
allFormats = append(allFormats, p.Name)
}

for _, f := range allFormats {
for _, f := range rule.Formats() {
for _, field := range f.Fields {
ch <- field
}
}
}
for _, rule := range s.GrantRules {
allFormats := []pyfmt.Format{
rule.Privilege, rule.Database, rule.Schema, rule.Object, rule.To,
}

for _, f := range allFormats {
for _, f := range rule.Formats() {
for _, field := range f.Fields {
ch <- field
}
Expand Down

0 comments on commit 69a3c13

Please sign in to comment.