mirror of
https://github.com/mulgadc/spinifex.git
synced 2026-10-19 10:52:04 +00:00
refactor: use slices.Sorted(maps.Keys()) for sorted action name lists
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user