DeduplicatePermissions removes duplicate Permission entries while preserving the original order of the first occurrence for deterministic evaluation.
(perms []Permission)
| 946 | // DeduplicatePermissions removes duplicate Permission entries while preserving |
| 947 | // the original order of the first occurrence for deterministic evaluation. |
| 948 | func DeduplicatePermissions(perms []Permission) []Permission { |
| 949 | if len(perms) == 0 { |
| 950 | return perms |
| 951 | } |
| 952 | seen := make(map[string]struct{}, len(perms)) |
| 953 | deduped := make([]Permission, 0, len(perms)) |
| 954 | for _, perm := range perms { |
| 955 | key := perm.ResourceType + "\x00" + string(perm.Action) + "\x00" + strconv.FormatBool(perm.Negate) |
| 956 | if _, ok := seen[key]; ok { |
| 957 | continue |
| 958 | } |
| 959 | seen[key] = struct{}{} |
| 960 | deduped = append(deduped, perm) |
| 961 | } |
| 962 | return deduped |
| 963 | } |
| 964 | |
| 965 | // PermissionsEqual compares two permission slices as sets. Order and |
| 966 | // duplicate entries do not matter; it only checks that both slices |
no outgoing calls