Skip to content

Commit

Permalink
remove endpoints package
Browse files Browse the repository at this point in the history
  • Loading branch information
tinnywang committed Sep 30, 2024
1 parent 26bfd7d commit d41ff6d
Show file tree
Hide file tree
Showing 19 changed files with 23 additions and 48,619 deletions.
5 changes: 5 additions & 0 deletions ecs-init/config/awsrulesfn/partitions.gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package awsrulesfn

// aws-sdk-go-v2 does not export partition metadata, so copy the files from vendor to make it accessible.

//go:generate cp ../../vendor/github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn/partition.go ../../vendor/github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn/partitions.go .
27 changes: 14 additions & 13 deletions ecs-init/config/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ import (
"runtime"
"strings"

"github.com/aws/amazon-ecs-agent/ecs-init/config/awsrulesfn"
"github.com/cihub/seelog"

"github.com/aws/aws-sdk-go/aws/endpoints"
godocker "github.com/fsouza/go-dockerclient"
"github.com/pkg/errors"
)
Expand Down Expand Up @@ -53,7 +52,7 @@ const (

// DefaultRegionName is the default region to fall back if the user's region is not a region containing
// the agent bucket
DefaultRegionName = endpoints.UsEast1RegionID
DefaultRegionName = "us-east-1"

// dockerJSONLogMaxSize is the maximum allowed size of the
// individual backing json log files for the managed container.
Expand Down Expand Up @@ -114,11 +113,11 @@ const (
// partitionBucketRegion provides the "partitional" bucket region
// suitable for downloading agent from.
var partitionBucketRegion = map[string]string{
endpoints.AwsPartitionID: endpoints.UsEast1RegionID,
endpoints.AwsCnPartitionID: endpoints.CnNorth1RegionID,
endpoints.AwsUsGovPartitionID: endpoints.UsGovWest1RegionID,
endpoints.AwsIsoPartitionID: endpoints.UsIsoEast1RegionID,
endpoints.AwsIsoBPartitionID: endpoints.UsIsobEast1RegionID,
"aws": DefaultRegionName,
"aws-cn": "cn-north-1",
"aws-us-gov": "us-gov-west-1",
"aws-iso": "us-iso-east-1",
"aws-iso-b": "us-isob-east-1",
}

// goarch is an injectable GOARCH runtime string. This controls the
Expand All @@ -140,14 +139,16 @@ var validDrivers = map[string]struct{}{

// GetAgentPartitionBucketRegion returns the s3 bucket region where ECS Agent artifact is located
func GetAgentPartitionBucketRegion(region string) (string, error) {
regionPartition, ok := endpoints.PartitionForRegion(endpoints.DefaultPartitions(), region)
if !ok {
return "", errors.Errorf("could not resolve partition ID for region %q", region)
// If the AWS SDK cannot match the region to a partition, it returns the default partition (aws).
// It only returns nil if the default partition is undefined.
partition := awsrulesfn.GetPartition(region)
if partition == nil {
return "", errors.Errorf("could not resolve partition for region %q", region)
}

bucketRegion, ok := partitionBucketRegion[regionPartition.ID()]
bucketRegion, ok := partitionBucketRegion[partition.Name]
if !ok {
return "", errors.Errorf("no bucket available for partition ID %q", regionPartition.ID())
return "", errors.Errorf("no bucket available for partition %q", partition.Name)
}

return bucketRegion, nil
Expand Down
13 changes: 4 additions & 9 deletions ecs-init/config/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func TestGetAgentPartitionBucketRegion(t *testing.T) {
testCases := []struct {
region string
destination string
err error
}{
{
region: "us-west-2",
Expand All @@ -76,21 +75,17 @@ func TestGetAgentPartitionBucketRegion(t *testing.T) {
region: "cn-north-1",
destination: "cn-north-1",
}, {
region: "invalid",
err: fmt.Errorf("Partition not found"),
region: "invalid",
destination: "us-east-1",
},
}

for _, testcase := range testCases {
t.Run(fmt.Sprintf("%s -> %s", testcase.region, testcase.destination),
func(t *testing.T) {
region, err := GetAgentPartitionBucketRegion(testcase.region)
if region != "" && region != testcase.destination && err != nil {
t.Errorf("GetAgentBucketRegion returned unexpected region: %s, err: %v", region, err)
}
if testcase.err != nil && err == nil {
t.Error("GetAgentBucketRegion should return an error if the destination is not found")
}
assert.NoError(t, err)
assert.Equal(t, testcase.destination, region)
})
}
}
Expand Down
5 changes: 0 additions & 5 deletions ecs-init/config/partitions.gen.go

This file was deleted.

1 change: 0 additions & 1 deletion ecs-init/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ toolchain go1.22.2

require (
github.com/NVIDIA/gpu-monitoring-tools v0.0.0-20180829222009-86f2a9fac6c5
github.com/aws/aws-sdk-go v1.51.3
github.com/aws/aws-sdk-go-v2 v1.31.0
github.com/aws/aws-sdk-go-v2/config v1.27.37
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.14
Expand Down
4 changes: 0 additions & 4 deletions ecs-init/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ github.com/Microsoft/hcsshim v0.9.10 h1:TxXGNmcbQxBKVWvjvTocNb6jrPyeHlk5EiDhhgHg
github.com/Microsoft/hcsshim v0.9.10/go.mod h1:7pLA8lDk46WKDWlVsENo92gC0XFa8rbKfyFRBqxEbCc=
github.com/NVIDIA/gpu-monitoring-tools v0.0.0-20180829222009-86f2a9fac6c5 h1:WLyvLAM0QfjAarRzRTG9EgT5McqGWNZMvqqSUSoyUUY=
github.com/NVIDIA/gpu-monitoring-tools v0.0.0-20180829222009-86f2a9fac6c5/go.mod h1:nMOvShGpWaf0bXwXmeu4k+O4uziuaEI8pWzIj3BUrOA=
github.com/aws/aws-sdk-go v1.51.3 h1:OqSyEXcJwf/XhZNVpMRgKlLA9nmbo5X8dwbll4RWxq8=
github.com/aws/aws-sdk-go v1.51.3/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/aws/aws-sdk-go-v2 v1.31.0 h1:3V05LbxTSItI5kUqNwhJrrrY1BAXxXt0sN0l72QmG5U=
github.com/aws/aws-sdk-go-v2 v1.31.0/go.mod h1:ztolYtaEUtdpf9Wftr31CJfLVjOnD/CVRkKOOYgF8hA=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.5 h1:xDAuZTn4IMm8o1LnBZvmrL8JA1io4o3YWNXgohbf20g=
Expand Down Expand Up @@ -79,8 +77,6 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY=
Expand Down
202 changes: 0 additions & 202 deletions ecs-init/vendor/github.com/aws/aws-sdk-go/LICENSE.txt

This file was deleted.

3 changes: 0 additions & 3 deletions ecs-init/vendor/github.com/aws/aws-sdk-go/NOTICE.txt

This file was deleted.

Loading

0 comments on commit d41ff6d

Please sign in to comment.