mirror of
https://github.com/portainer/portainer.git
synced 2025-07-21 22:39:41 +02:00
fix(uac): ignore duplicates, spaces and casing in portainer labels (#4823)
* fix: ignore duplicates, spaces and casing in portainer labels * cleanup * fix: rebase error
This commit is contained in:
parent
6c8276c65c
commit
f03cf2a6e4
4 changed files with 90 additions and 7 deletions
|
@ -31,6 +31,23 @@ type (
|
|||
}
|
||||
)
|
||||
|
||||
func getUniqueElements(items string) []string {
|
||||
result := []string{}
|
||||
seen := make(map[string]struct{})
|
||||
for _, item := range strings.Split(items, ",") {
|
||||
v := strings.TrimSpace(item)
|
||||
if v == "" {
|
||||
continue
|
||||
}
|
||||
if _, ok := seen[v]; !ok {
|
||||
result = append(result, v)
|
||||
seen[v] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (transport *Transport) newResourceControlFromPortainerLabels(labelsObject map[string]interface{}, resourceID string, resourceType portainer.ResourceControlType) (*portainer.ResourceControl, error) {
|
||||
if labelsObject[resourceLabelForPortainerPublicResourceControl] != nil {
|
||||
resourceControl := authorization.NewPublicResourceControl(resourceID, resourceType)
|
||||
|
@ -47,12 +64,12 @@ func (transport *Transport) newResourceControlFromPortainerLabels(labelsObject m
|
|||
userNames := make([]string, 0)
|
||||
if labelsObject[resourceLabelForPortainerTeamResourceControl] != nil {
|
||||
concatenatedTeamNames := labelsObject[resourceLabelForPortainerTeamResourceControl].(string)
|
||||
teamNames = strings.Split(concatenatedTeamNames, ",")
|
||||
teamNames = getUniqueElements(concatenatedTeamNames)
|
||||
}
|
||||
|
||||
if labelsObject[resourceLabelForPortainerUserResourceControl] != nil {
|
||||
concatenatedUserNames := labelsObject[resourceLabelForPortainerUserResourceControl].(string)
|
||||
userNames = strings.Split(concatenatedUserNames, ",")
|
||||
userNames = getUniqueElements(concatenatedUserNames)
|
||||
}
|
||||
|
||||
if len(teamNames) > 0 || len(userNames) > 0 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue