Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Commit

Permalink
base rule id on properties
Browse files Browse the repository at this point in the history
  • Loading branch information
waynz0r committed Nov 13, 2023
1 parent 7ea860c commit 4114d5f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pkg/rules/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,7 @@ func (r *Rule) UnmarshalYAML(unmarshal func(interface{}) error) error {
return err
}

y, err := yaml.Marshal(rule)
if err != nil {
return err
}

r.ID = uuid.NewSHA1(uuid.Nil, y).String()
r.ID = Rule(rule).getID()
r.Policy = rule.Policy
r.Properties = rule.Properties
r.Selectors = rule.Selectors
Expand All @@ -110,6 +105,15 @@ func (r *Rule) UnmarshalYAML(unmarshal func(interface{}) error) error {
return nil
}

func (r Rule) getID() string {
y, err := yaml.Marshal(r.Properties)
if err != nil {
return ""
}

return uuid.NewSHA1(uuid.Nil, y).String()
}

func IsMapSubset[K, V comparable](m, sub map[K]V) bool {
if len(sub) > len(m) {
return false
Expand Down

0 comments on commit 4114d5f

Please sign in to comment.