sort service role actions on init
This commit is contained in:
@@ -3,6 +3,7 @@ package service
|
|||||||
import (
|
import (
|
||||||
"go.infratographer.com/x/gidx"
|
"go.infratographer.com/x/gidx"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
|
|
||||||
"go.equinixmetal.net/infra9-metal-bridge/internal/metal"
|
"go.equinixmetal.net/infra9-metal-bridge/internal/metal"
|
||||||
"go.equinixmetal.net/infra9-metal-bridge/internal/permissions"
|
"go.equinixmetal.net/infra9-metal-bridge/internal/permissions"
|
||||||
@@ -64,7 +65,13 @@ func WithRootTenant(sid string) Option {
|
|||||||
// WithRoles defines the role to action mapping.
|
// WithRoles defines the role to action mapping.
|
||||||
func WithRoles(roles map[string][]string) Option {
|
func WithRoles(roles map[string][]string) Option {
|
||||||
return func(s *service) error {
|
return func(s *service) error {
|
||||||
s.roles = roles
|
s.roles = make(map[string][]string, len(roles))
|
||||||
|
|
||||||
|
for role, actions := range roles {
|
||||||
|
slices.Sort(actions)
|
||||||
|
|
||||||
|
s.roles[role] = actions
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,8 +180,6 @@ func (s *service) mapResourceWants(memberships []ResourceMemberships) (map[strin
|
|||||||
roleActionsKey := make(map[string]string)
|
roleActionsKey := make(map[string]string)
|
||||||
|
|
||||||
for role, actions := range s.roles {
|
for role, actions := range s.roles {
|
||||||
slices.Sort(actions)
|
|
||||||
|
|
||||||
roleActionsKey[role] = strings.Join(actions, "|")
|
roleActionsKey[role] = strings.Join(actions, "|")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user