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
}
}
// compare source tenants ignoring their order
{
// compare source tenants
if len(g.sourceTenants) != len(ng.sourceTenants) {
return false
}
thisSourceTenants := make(map[string]struct{}, len(g.sourceTenants))
for _, tenant := range g.sourceTenants {
thisSourceTenants[tenant] = struct{}{}
copyAndSort := func(x []string) []string {
copied := make([]string, len(x))
copy(copied, x)
sort.Strings(copied)
return copied
}
for _, tenant := range ng.sourceTenants {
if _, ok := thisSourceTenants[tenant]; !ok {
ngSourceTenantsCopy := copyAndSort(ng.sourceTenants)
gSourceTenantsCopy := copyAndSort(g.sourceTenants)
for i := range ngSourceTenantsCopy {
if gSourceTenantsCopy[i] != ngSourceTenantsCopy[i] {
return false
}
}
}
return true
}