From 30815e33ea995afd45fa2dee26a3a636ca62956d Mon Sep 17 00:00:00 2001 From: Julian Sommer <115516918+juliansommer@users.noreply.github.com> Date: Tue, 1 Sep 2026 11:54:01 +1000 Subject: [PATCH] refactor: use slices.Sorted(maps.Keys()) for sorted action name lists --- spinifex/gateway/acm/authz.go | 10 +++------- spinifex/gateway/admin.go | 10 +++------- spinifex/gateway/bedrock/authz.go | 9 ++------- spinifex/gateway/ec2/authz.go | 10 +++------- spinifex/gateway/ecrapi/authz.go | 10 +++------- spinifex/gateway/ecs/authz.go | 10 +++------- spinifex/gateway/eks/authz.go | 9 ++------- spinifex/gateway/elbv2/authz.go | 10 +++------- spinifex/gateway/iam/authz.go | 10 +++------- 9 files changed, 25 insertions(+), 63 deletions(-) diff --git a/spinifex/gateway/acm/authz.go b/spinifex/gateway/acm/authz.go index 87af5a63e..fd34e0317 100644 --- a/spinifex/gateway/acm/authz.go +++ b/spinifex/gateway/acm/authz.go @@ -3,7 +3,8 @@ package gateway_acm import ( "errors" "log/slog" - "sort" + "maps" + "slices" "github.com/mulgadc/spinifex/spinifex/arn" "github.com/mulgadc/spinifex/spinifex/awserrors" @@ -67,12 +68,7 @@ func HasScope(action string) bool { // ScopedActions returns every action represented in the ACM scope table. func ScopedActions() []string { - actions := make([]string, 0, len(acmScopes)) - for action := range acmScopes { - actions = append(actions, action) - } - sort.Strings(actions) - return actions + return slices.Sorted(maps.Keys(acmScopes)) } // ResourceARNs resolves the resources an ACM request authorizes against from the diff --git a/spinifex/gateway/admin.go b/spinifex/gateway/admin.go index c2f6f1f11..9add6c21a 100644 --- a/spinifex/gateway/admin.go +++ b/spinifex/gateway/admin.go @@ -5,8 +5,9 @@ import ( "errors" "io" "log/slog" + "maps" "net/http" - "sort" + "slices" "strings" "uuid" @@ -32,12 +33,7 @@ var adminMethods = map[string]bool{ // Tooling that mints a credential grants these by name, so the list has to come // from the router rather than from a copy that can drift out of step with it. func AdminMethodNames() []string { - names := make([]string, 0, len(adminMethods)) - for name := range adminMethods { - names = append(names, name) - } - sort.Strings(names) - return names + return slices.Sorted(maps.Keys(adminMethods)) } // adminPathPrefix is the private admin surface's URL prefix. It is matched diff --git a/spinifex/gateway/bedrock/authz.go b/spinifex/gateway/bedrock/authz.go index c06df5fc0..be7a8ee0a 100644 --- a/spinifex/gateway/bedrock/authz.go +++ b/spinifex/gateway/bedrock/authz.go @@ -4,8 +4,8 @@ import ( "errors" "fmt" "log/slog" + "maps" "slices" - "sort" "github.com/mulgadc/spinifex/spinifex/awserrors" "github.com/mulgadc/spinifex/spinifex/gateway/bodyscope" @@ -122,12 +122,7 @@ func HasScope(service, action string) bool { // ScopedActions returns every action represented in service's scope table. func ScopedActions(service string) []string { scopes := bedrockScopes[service] - actions := make([]string, 0, len(scopes)) - for action := range scopes { - actions = append(actions, action) - } - sort.Strings(actions) - return actions + return slices.Sorted(maps.Keys(scopes)) } // ResourceARNs resolves the resources a Bedrock-family request authorizes diff --git a/spinifex/gateway/ec2/authz.go b/spinifex/gateway/ec2/authz.go index 2a4ec3fc3..6b379a2a6 100644 --- a/spinifex/gateway/ec2/authz.go +++ b/spinifex/gateway/ec2/authz.go @@ -5,7 +5,8 @@ package gateway_ec2 import ( "errors" - "sort" + "maps" + "slices" "github.com/mulgadc/spinifex/spinifex/arn" "github.com/mulgadc/spinifex/spinifex/awsec2query" @@ -298,12 +299,7 @@ func HasScope(action string) bool { // ScopedActions returns every action the scope table covers, so a scope left // behind by a deleted or renamed action fails the completeness test too. func ScopedActions() []string { - actions := make([]string, 0, len(ec2Scopes)) - for action := range ec2Scopes { - actions = append(actions, action) - } - sort.Strings(actions) - return actions + return slices.Sorted(maps.Keys(ec2Scopes)) } // ResourceARNs builds every resource the action's policy check evaluates from diff --git a/spinifex/gateway/ecrapi/authz.go b/spinifex/gateway/ecrapi/authz.go index d1a1972e2..7c3baa08b 100644 --- a/spinifex/gateway/ecrapi/authz.go +++ b/spinifex/gateway/ecrapi/authz.go @@ -4,7 +4,8 @@ import ( "errors" "fmt" "log/slog" - "sort" + "maps" + "slices" "strings" "github.com/mulgadc/spinifex/spinifex/awsec2query" @@ -105,12 +106,7 @@ func HasScope(action string) bool { // ScopedActions returns every action represented in the ECR scope table. func ScopedActions() []string { - actions := make([]string, 0, len(ecrScopes)) - for action := range ecrScopes { - actions = append(actions, action) - } - sort.Strings(actions) - return actions + return slices.Sorted(maps.Keys(ecrScopes)) } // ResourceARNs resolves the resources an ECR control-plane request authorizes diff --git a/spinifex/gateway/ecs/authz.go b/spinifex/gateway/ecs/authz.go index 1fb2d7916..fdfc60886 100644 --- a/spinifex/gateway/ecs/authz.go +++ b/spinifex/gateway/ecs/authz.go @@ -3,7 +3,8 @@ package gateway_ecs import ( "errors" "log/slog" - "sort" + "maps" + "slices" "github.com/mulgadc/spinifex/spinifex/awsec2query" "github.com/mulgadc/spinifex/spinifex/awserrors" @@ -130,12 +131,7 @@ func HasScope(action string) bool { // ScopedActions returns every action represented in the ECS scope table. func ScopedActions() []string { - actions := make([]string, 0, len(ecsScopes)) - for action := range ecsScopes { - actions = append(actions, action) - } - sort.Strings(actions) - return actions + return slices.Sorted(maps.Keys(ecsScopes)) } // ResourceARNs resolves the resources an ECS request authorizes against from diff --git a/spinifex/gateway/eks/authz.go b/spinifex/gateway/eks/authz.go index cd6bb4d94..c010de189 100644 --- a/spinifex/gateway/eks/authz.go +++ b/spinifex/gateway/eks/authz.go @@ -4,8 +4,8 @@ import ( "encoding/json" "errors" "log/slog" + "maps" "slices" - "sort" "strings" "github.com/aws/aws-sdk-go/aws" @@ -118,12 +118,7 @@ func HasScope(action string) bool { // ScopedActions returns every action represented in the EKS scope table. func ScopedActions() []string { - actions := make([]string, 0, len(eksScopes)) - for action := range eksScopes { - actions = append(actions, action) - } - sort.Strings(actions) - return actions + return slices.Sorted(maps.Keys(eksScopes)) } // ResourceARNs resolves the resources an EKS request authorizes against from diff --git a/spinifex/gateway/elbv2/authz.go b/spinifex/gateway/elbv2/authz.go index 6da5995db..5d2903a2f 100644 --- a/spinifex/gateway/elbv2/authz.go +++ b/spinifex/gateway/elbv2/authz.go @@ -3,7 +3,8 @@ package gateway_elbv2 import ( "errors" "log/slog" - "sort" + "maps" + "slices" "strings" "github.com/mulgadc/spinifex/spinifex/arn" @@ -112,12 +113,7 @@ func HasScope(action string) bool { // ScopedActions returns every action represented in the ELBv2 scope table, so a // scope left behind by a deleted or renamed action fails completeness too. func ScopedActions() []string { - actions := make([]string, 0, len(elbv2Scopes)) - for action := range elbv2Scopes { - actions = append(actions, action) - } - sort.Strings(actions) - return actions + return slices.Sorted(maps.Keys(elbv2Scopes)) } // ResourceARNs resolves the resources an ELBv2 request authorizes against from diff --git a/spinifex/gateway/iam/authz.go b/spinifex/gateway/iam/authz.go index f6d99bbf0..7dfb69d08 100644 --- a/spinifex/gateway/iam/authz.go +++ b/spinifex/gateway/iam/authz.go @@ -4,8 +4,9 @@ package gateway_iam import ( "errors" "log/slog" + "maps" "reflect" - "sort" + "slices" "github.com/mulgadc/spinifex/spinifex/arn" "github.com/mulgadc/spinifex/spinifex/awserrors" @@ -140,12 +141,7 @@ func HasScope(action string) bool { // ScopedActions returns every action represented in the IAM scope table. func ScopedActions() []string { - actions := make([]string, 0, len(iamScopes)) - for action := range iamScopes { - actions = append(actions, action) - } - sort.Strings(actions) - return actions + return slices.Sorted(maps.Keys(iamScopes)) } // ResourceARNs resolves the resource an IAM request authorizes against from