Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed May 7, 2024
1 parent 3b03840 commit ead6212
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions pkg/rbac/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ func (r *Rule) key() ruleKey {
}
}

func (r *Rule) KeyWithoutResources() string {
func (r *Rule) keyWithGroupResourceNamesURLsVerbs() string {
key := r.key()
verbs := strings.Join(r.Verbs, "&")
return fmt.Sprintf("%s + %s + %s + %s", key.Groups, key.ResourceNames, key.URLs, verbs)
}

func (r *Rule) KeyWithoutGroups() string {
func (r *Rule) keyWithResourcesResourceNamesURLsVerbs() string {
key := r.key()
verbs := strings.Join(r.Verbs, "&")
return fmt.Sprintf("%s + %s + %s + %s", key.Resources, key.ResourceNames, key.URLs, verbs)
Expand Down Expand Up @@ -187,7 +187,7 @@ func GenerateRoles(ctx *genall.GenerationContext, roleName string) ([]interface{
root.AddError(err)
}

// group RBAC markers by namespace and resource
// group RBAC markers by namespace and separate by resource
for _, markerValue := range markerSet[RuleDefinition.Name] {
rule := markerValue.(Rule)
for _, resource := range rule.Resources {
Expand All @@ -200,10 +200,6 @@ func GenerateRoles(ctx *genall.GenerationContext, roleName string) ([]interface{
Verbs: rule.Verbs,
}
namespace := r.Namespace
if _, ok := rulesByNSResource[namespace]; !ok {
rules := make([]*Rule, 0)
rulesByNSResource[namespace] = rules
}
rulesByNSResource[namespace] = append(rulesByNSResource[namespace], &r)
}
}
Expand All @@ -227,11 +223,7 @@ func GenerateRoles(ctx *genall.GenerationContext, roleName string) ([]interface{
ruleMapWithoutResources := make(map[string][]*Rule)
for _, rule := range ruleMap {
// unset Resources on the key
key := rule.KeyWithoutResources()
if _, ok := ruleMapWithoutResources[key]; !ok {
rules := make([]*Rule, 0)
ruleMapWithoutResources[key] = rules
}
key := rule.keyWithGroupResourceNamesURLsVerbs()
ruleMapWithoutResources[key] = append(ruleMapWithoutResources[key], rule)
}
// 2. merge to ruleMap
Expand All @@ -251,7 +243,7 @@ func GenerateRoles(ctx *genall.GenerationContext, roleName string) ([]interface{
ruleMapWithoutGroup := make(map[string][]*Rule)
for _, rule := range ruleMap {
// unset Resources on the key
key := rule.KeyWithoutGroups()
key := rule.keyWithResourcesResourceNamesURLsVerbs()
if _, ok := ruleMapWithoutGroup[key]; !ok {
rules := make([]*Rule, 0)
ruleMapWithoutGroup[key] = rules
Expand Down

0 comments on commit ead6212

Please sign in to comment.