Account for repeating tenants when comparing rules

This commit is contained in:
Dimitar Dimitrov 2022-01-21 14:21:50 +01:00
parent bc7a802871
commit 16faee8b78
No known key found for this signature in database
GPG key ID: 4541B04E6C90EBC3

View file

@ -875,23 +875,28 @@ func (g *Group) Equals(ng *Group) bool {
return false return false
} }
} }
{
// compare source tenants ignoring their order // compare source tenants
if len(g.sourceTenants) != len(ng.sourceTenants) { if len(g.sourceTenants) != len(ng.sourceTenants) {
return false return false
} }
thisSourceTenants := make(map[string]struct{}, len(g.sourceTenants)) copyAndSort := func(x []string) []string {
copied := make([]string, len(x))
for _, tenant := range g.sourceTenants { copy(copied, x)
thisSourceTenants[tenant] = struct{}{} sort.Strings(copied)
return copied
} }
for _, tenant := range ng.sourceTenants { ngSourceTenantsCopy := copyAndSort(ng.sourceTenants)
if _, ok := thisSourceTenants[tenant]; !ok { gSourceTenantsCopy := copyAndSort(g.sourceTenants)
for i := range ngSourceTenantsCopy {
if gSourceTenantsCopy[i] != ngSourceTenantsCopy[i] {
return false return false
} }
} }
}
return true return true
} }