sort service role actions on init

This commit is contained in:
Mike Mason
2023-07-21 18:47:40 +00:00
parent b421163ae2
commit a6aa3674cd
2 changed files with 8 additions and 3 deletions

View File

@@ -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
}