Skip to content

Commit b5c4f5d

Browse files
committed
removed endpoints package
1 parent 3ea20b8 commit b5c4f5d

File tree

4 files changed

+23
-28
lines changed

4 files changed

+23
-28
lines changed

cmd/aws-iam-authenticator/root.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"slices"
2424
"strings"
2525

26+
"sigs.k8s.io/aws-iam-authenticator/pkg/arn"
2627
"sigs.k8s.io/aws-iam-authenticator/pkg/config"
2728
"sigs.k8s.io/aws-iam-authenticator/pkg/mapper"
2829

@@ -35,16 +36,6 @@ import (
3536

3637
var cfgFile string
3738

38-
var PartitionKeys = []string{
39-
"aws",
40-
"aws-cn",
41-
"aws-us-gov",
42-
"aws-iso",
43-
"aws-iso-b",
44-
"aws-iso-e",
45-
"aws-iso-f",
46-
}
47-
4839
var rootCmd = &cobra.Command{
4940
Use: "aws-iam-authenticator",
5041
Short: "A tool to authenticate to Kubernetes using AWS IAM credentials",
@@ -167,8 +158,8 @@ func getConfig() (config.Config, error) {
167158
return cfg, errors.New("cluster ID cannot be empty")
168159
}
169160

170-
if slices.Contains(PartitionKeys, cfg.PartitionID) {
171-
return cfg, errors.New("Invalid partition")
161+
if !slices.Contains(arn.PartitionKeys, cfg.PartitionID) {
162+
return cfg, errors.New("Invalid partition when getting config")
172163
}
173164

174165
// DynamicFile BackendMode and DynamicFilePath are mutually inclusive.

cmd/aws-iam-authenticator/server.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
"k8s.io/sample-controller/pkg/signals"
2727
"sigs.k8s.io/aws-iam-authenticator/pkg"
28+
"sigs.k8s.io/aws-iam-authenticator/pkg/arn"
2829
"sigs.k8s.io/aws-iam-authenticator/pkg/mapper"
2930
"sigs.k8s.io/aws-iam-authenticator/pkg/metrics"
3031
"sigs.k8s.io/aws-iam-authenticator/pkg/server"
@@ -67,7 +68,7 @@ var serverCmd = &cobra.Command{
6768

6869
func init() {
6970
serverCmd.Flags().String("partition", "aws",
70-
fmt.Sprintf("The AWS partition. Must be one of: %v", PartitionKeys))
71+
fmt.Sprintf("The AWS partition. Must be one of: %v", arn.PartitionKeys))
7172
viper.BindPFlag("server.partition", serverCmd.Flags().Lookup("partition"))
7273

7374
serverCmd.Flags().String("generate-kubeconfig",

pkg/arn/arn.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package arn
22

33
import (
44
"fmt"
5+
"slices"
56
"strings"
67

78
awsarn "github.com/aws/aws-sdk-go-v2/aws/arn"
8-
"github.com/aws/aws-sdk-go/aws/endpoints"
99
)
1010

1111
type PrincipalType int
@@ -20,6 +20,16 @@ const (
2020
ASSUMED_ROLE
2121
)
2222

23+
var PartitionKeys = []string{
24+
"aws",
25+
"aws-cn",
26+
"aws-us-gov",
27+
"aws-iso",
28+
"aws-iso-b",
29+
"aws-iso-e",
30+
"aws-iso-f",
31+
}
32+
2333
// Canonicalize validates IAM resources are appropriate for the authenticator
2434
// and converts STS assumed roles into the IAM role resource.
2535
//
@@ -101,10 +111,8 @@ func StripPath(arn string) (string, error) {
101111
}
102112

103113
func checkPartition(partition string) error {
104-
for _, p := range endpoints.DefaultPartitions() {
105-
if partition == p.ID() {
106-
return nil
107-
}
114+
if !slices.Contains(PartitionKeys, partition) {
115+
return fmt.Errorf("partition %s is not recognized", partition)
108116
}
109-
return fmt.Errorf("partition %s is not recognized", partition)
117+
return nil
110118
}

tests/integration/testutils/testserver.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import (
77
"net/http"
88
"os"
99
"path/filepath"
10+
"slices"
1011
"testing"
1112
"time"
1213

13-
"github.com/aws/aws-sdk-go/aws/endpoints"
1414
"github.com/prometheus/client_golang/prometheus"
1515
utilerrors "k8s.io/apimachinery/pkg/util/errors"
1616
"k8s.io/apimachinery/pkg/util/wait"
@@ -20,6 +20,7 @@ import (
2020
"k8s.io/kubernetes/pkg/controlplane"
2121
"k8s.io/kubernetes/test/integration/framework"
2222

23+
"sigs.k8s.io/aws-iam-authenticator/pkg/arn"
2324
"sigs.k8s.io/aws-iam-authenticator/pkg/config"
2425
"sigs.k8s.io/aws-iam-authenticator/pkg/mapper"
2526
"sigs.k8s.io/aws-iam-authenticator/pkg/metrics"
@@ -149,14 +150,8 @@ func testConfig(t *testing.T, setup AuthenticatorTestFrameworkSetup) (config.Con
149150
return cfg, errors.New("cluster ID cannot be empty")
150151
}
151152

152-
partitionKeys := []string{}
153-
partitionMap := map[string]endpoints.Partition{}
154-
for _, p := range endpoints.DefaultPartitions() {
155-
partitionMap[p.ID()] = p
156-
partitionKeys = append(partitionKeys, p.ID())
157-
}
158-
if _, ok := partitionMap[cfg.PartitionID]; !ok {
159-
return cfg, errors.New("Invalid partition")
153+
if !slices.Contains(arn.PartitionKeys, cfg.PartitionID) {
154+
return cfg, errors.New("Invalid partition in test config")
160155
}
161156

162157
if errs := mapper.ValidateBackendMode(cfg.BackendMode); len(errs) > 0 {

0 commit comments

Comments
 (0)