mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-19 02:12:02 +02:00
improve additional teams lookup (#2445)
* improve additional teams lookup --------- Co-authored-by: Jan Mussler <janm81@gmail.com>
This commit is contained in:
co-authored by
Jan Mussler
parent
8ae769a567
commit
f41c14f468
@@ -66,13 +66,20 @@ func (ptm *PostgresTeamMap) fetchAdditionalTeams(team string, superuserTeams boo
|
||||
teams = (*ptm)[team].AdditionalTeams
|
||||
}
|
||||
if transitive {
|
||||
exclude = append(exclude, team)
|
||||
for _, additionalTeam := range teams {
|
||||
if !(util.SliceContains(exclude, additionalTeam)) {
|
||||
// remember to not check team and additionalTeam again
|
||||
exclude = append(exclude, additionalTeam)
|
||||
transitiveTeams := (*ptm).fetchAdditionalTeams(additionalTeam, superuserTeams, transitive, exclude)
|
||||
for _, transitiveTeam := range transitiveTeams {
|
||||
if !(util.SliceContains(exclude, transitiveTeam)) && !(util.SliceContains(teams, transitiveTeam)) {
|
||||
teams = append(teams, transitiveTeam)
|
||||
if !(util.SliceContains(exclude, transitiveTeam)) {
|
||||
// remember to not check transitive team again in case
|
||||
// it is one of the next additional teams of the outer loop
|
||||
exclude = append(exclude, transitiveTeam)
|
||||
if !(util.SliceContains(teams, transitiveTeam)) {
|
||||
// found a new transitive additional team
|
||||
teams = append(teams, transitiveTeam)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,12 +91,12 @@ func (ptm *PostgresTeamMap) fetchAdditionalTeams(team string, superuserTeams boo
|
||||
|
||||
// GetAdditionalTeams function to retrieve list of additional teams
|
||||
func (ptm *PostgresTeamMap) GetAdditionalTeams(team string, transitive bool) []string {
|
||||
return ptm.fetchAdditionalTeams(team, false, transitive, []string{})
|
||||
return ptm.fetchAdditionalTeams(team, false, transitive, []string{team})
|
||||
}
|
||||
|
||||
// GetAdditionalSuperuserTeams function to retrieve list of additional superuser teams
|
||||
func (ptm *PostgresTeamMap) GetAdditionalSuperuserTeams(team string, transitive bool) []string {
|
||||
return ptm.fetchAdditionalTeams(team, true, transitive, []string{})
|
||||
return ptm.fetchAdditionalTeams(team, true, transitive, []string{team})
|
||||
}
|
||||
|
||||
// Load function to import data from PostgresTeam CRD
|
||||
|
||||
Reference in New Issue
Block a user