Skip to content

Commit

Permalink
Move check for empty .spec.to at top
Browse files Browse the repository at this point in the history
  • Loading branch information
creydr committed Jun 14, 2024
1 parent 526bb83 commit ab537e8
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pkg/auth/event_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ func GetEventPoliciesForResource(lister listerseventingv1alpha1.EventPolicyListe
resourceAPIVersion := fmt.Sprintf("%s/%s", resourceGVK.Group, resourceGVK.Version)

for _, policy := range policies {
for _, to := range policy.Spec.To {
if len(policy.Spec.To) == 0 {
// policy applies to all resources in namespace
relevantPolicies = append(relevantPolicies, policy)
}

for _, to := range policy.Spec.To {
if to.Ref != nil &&
strings.EqualFold(to.Ref.Name, resourceObjectMeta.GetName()) &&
strings.EqualFold(to.Ref.APIVersion, resourceAPIVersion) &&
Expand All @@ -66,11 +70,6 @@ func GetEventPoliciesForResource(lister listerseventingv1alpha1.EventPolicyListe
}
}
}

if len(policy.Spec.To) == 0 {
// policy applies to all resources in namespace
relevantPolicies = append(relevantPolicies, policy)
}
}

return relevantPolicies, nil
Expand Down

0 comments on commit ab537e8

Please sign in to comment.