From a6aa3674cd6e74c77a11383cb8237e7a6113d42c Mon Sep 17 00:00:00 2001 From: Mike Mason Date: Fri, 21 Jul 2023 18:47:40 +0000 Subject: [PATCH] sort service role actions on init --- internal/service/options.go | 9 ++++++++- internal/service/process_memberships.go | 2 -- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/service/options.go b/internal/service/options.go index fc7b8a3..8ac12a9 100644 --- a/internal/service/options.go +++ b/internal/service/options.go @@ -3,6 +3,7 @@ package service import ( "go.infratographer.com/x/gidx" "go.uber.org/zap" + "golang.org/x/exp/slices" "go.equinixmetal.net/infra9-metal-bridge/internal/metal" "go.equinixmetal.net/infra9-metal-bridge/internal/permissions" @@ -64,7 +65,13 @@ func WithRootTenant(sid string) Option { // WithRoles defines the role to action mapping. func WithRoles(roles map[string][]string) Option { 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 } diff --git a/internal/service/process_memberships.go b/internal/service/process_memberships.go index cbe4ff4..611c4dc 100644 --- a/internal/service/process_memberships.go +++ b/internal/service/process_memberships.go @@ -180,8 +180,6 @@ func (s *service) mapResourceWants(memberships []ResourceMemberships) (map[strin roleActionsKey := make(map[string]string) for role, actions := range s.roles { - slices.Sort(actions) - roleActionsKey[role] = strings.Join(actions, "|") }