diff --git a/LICENSES b/LICENSES index 660f5fe8..7a25213d 100644 --- a/LICENSES +++ b/LICENSES @@ -8,13 +8,28 @@ github.com/Azure/go-autorest/autorest/to,https://github.com/Azure/go-autorest/bl github.com/Azure/go-autorest/autorest/validation,https://github.com/Azure/go-autorest/blob/autorest/validation/v0.3.1/autorest/validation/LICENSE,Apache-2.0 github.com/Azure/go-autorest/logger,https://github.com/Azure/go-autorest/blob/logger/v0.2.1/logger/LICENSE,Apache-2.0 github.com/Azure/go-autorest/tracing,https://github.com/Azure/go-autorest/blob/tracing/v0.6.0/tracing/LICENSE,Apache-2.0 -github.com/aws/aws-sdk-go,https://github.com/aws/aws-sdk-go/blob/v1.44.4/LICENSE.txt,Apache-2.0 -github.com/aws/aws-sdk-go/internal/sync/singleflight,https://github.com/aws/aws-sdk-go/blob/v1.44.4/internal/sync/singleflight/LICENSE,BSD-3-Clause +github.com/aws/aws-sdk-go-v2,https://github.com/aws/aws-sdk-go-v2/blob/v1.24.0/LICENSE.txt,Apache-2.0 +github.com/aws/aws-sdk-go-v2/config,https://github.com/aws/aws-sdk-go-v2/blob/config/v1.26.2/config/LICENSE.txt,Apache-2.0 +github.com/aws/aws-sdk-go-v2/credentials,https://github.com/aws/aws-sdk-go-v2/blob/credentials/v1.16.13/credentials/LICENSE.txt,Apache-2.0 +github.com/aws/aws-sdk-go-v2/feature/ec2/imds,https://github.com/aws/aws-sdk-go-v2/blob/feature/ec2/imds/v1.14.10/feature/ec2/imds/LICENSE.txt,Apache-2.0 +github.com/aws/aws-sdk-go-v2/internal/configsources,https://github.com/aws/aws-sdk-go-v2/blob/internal/configsources/v1.2.9/internal/configsources/LICENSE.txt,Apache-2.0 +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2,https://github.com/aws/aws-sdk-go-v2/blob/internal/endpoints/v2.5.9/internal/endpoints/v2/LICENSE.txt,Apache-2.0 +github.com/aws/aws-sdk-go-v2/internal/ini,https://github.com/aws/aws-sdk-go-v2/blob/internal/ini/v1.7.2/internal/ini/LICENSE.txt,Apache-2.0 +github.com/aws/aws-sdk-go-v2/internal/sync/singleflight,https://github.com/aws/aws-sdk-go-v2/blob/v1.24.0/internal/sync/singleflight/LICENSE,BSD-3-Clause +github.com/aws/aws-sdk-go-v2/service/autoscaling,https://github.com/aws/aws-sdk-go-v2/blob/service/autoscaling/v1.36.6/service/autoscaling/LICENSE.txt,Apache-2.0 +github.com/aws/aws-sdk-go-v2/service/ec2,https://github.com/aws/aws-sdk-go-v2/blob/service/ec2/v1.142.0/service/ec2/LICENSE.txt,Apache-2.0 +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding,https://github.com/aws/aws-sdk-go-v2/blob/service/internal/accept-encoding/v1.10.4/service/internal/accept-encoding/LICENSE.txt,Apache-2.0 +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url,https://github.com/aws/aws-sdk-go-v2/blob/service/internal/presigned-url/v1.10.9/service/internal/presigned-url/LICENSE.txt,Apache-2.0 +github.com/aws/aws-sdk-go-v2/service/sso,https://github.com/aws/aws-sdk-go-v2/blob/service/sso/v1.18.5/service/sso/LICENSE.txt,Apache-2.0 +github.com/aws/aws-sdk-go-v2/service/ssooidc,https://github.com/aws/aws-sdk-go-v2/blob/service/ssooidc/v1.21.5/service/ssooidc/LICENSE.txt,Apache-2.0 +github.com/aws/aws-sdk-go-v2/service/sts,https://github.com/aws/aws-sdk-go-v2/blob/service/sts/v1.26.6/service/sts/LICENSE.txt,Apache-2.0 +github.com/aws/smithy-go,https://github.com/aws/smithy-go/blob/v1.19.0/LICENSE,Apache-2.0 +github.com/aws/smithy-go/internal/sync/singleflight,https://github.com/aws/smithy-go/blob/v1.19.0/internal/sync/singleflight/LICENSE,BSD-3-Clause github.com/dimchansky/utfbom,https://github.com/dimchansky/utfbom/blob/v1.1.1/LICENSE,Apache-2.0 github.com/golang-jwt/jwt/v4,https://github.com/golang-jwt/jwt/blob/v4.2.0/LICENSE,MIT github.com/jmespath/go-jmespath,https://github.com/jmespath/go-jmespath/blob/v0.4.0/LICENSE,Apache-2.0 github.com/mitchellh/go-homedir,https://github.com/mitchellh/go-homedir/blob/v1.1.0/LICENSE,MIT github.com/nginxinc/nginx-asg-sync/cmd/sync,https://github.com/nginxinc/nginx-asg-sync/blob/HEAD/LICENSE,BSD-2-Clause -github.com/nginxinc/nginx-plus-go-client/client,https://github.com/nginxinc/nginx-plus-go-client/blob/v0.10.0/LICENSE,Apache-2.0 -golang.org/x/crypto/pkcs12,https://cs.opensource.google/go/x/crypto/+/v0.1.0:LICENSE,BSD-3-Clause +github.com/nginxinc/nginx-plus-go-client/client,https://github.com/nginxinc/nginx-plus-go-client/blob/v1.2.0/LICENSE,Apache-2.0 +golang.org/x/crypto/pkcs12,https://cs.opensource.google/go/x/crypto/+/v0.17.0:LICENSE,BSD-3-Clause gopkg.in/yaml.v2,https://github.com/go-yaml/yaml/blob/v2.4.0/LICENSE,Apache-2.0 diff --git a/cmd/sync/aws.go b/cmd/sync/aws.go index bcbb0311..5a271061 100644 --- a/cmd/sync/aws.go +++ b/cmd/sync/aws.go @@ -1,25 +1,25 @@ package main import ( + "context" "fmt" "net/http" "reflect" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/ec2metadata" - "github.com/aws/aws-sdk-go/aws/session" - "github.com/aws/aws-sdk-go/service/autoscaling" - "github.com/aws/aws-sdk-go/service/autoscaling/autoscalingiface" - "github.com/aws/aws-sdk-go/service/ec2" - "github.com/aws/aws-sdk-go/service/ec2/ec2iface" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/config" + "github.com/aws/aws-sdk-go-v2/feature/ec2/imds" + "github.com/aws/aws-sdk-go-v2/service/autoscaling" + "github.com/aws/aws-sdk-go-v2/service/ec2" + "github.com/aws/aws-sdk-go-v2/service/ec2/types" yaml "gopkg.in/yaml.v2" ) // AWSClient allows you to get the list of IP addresses of instances of an Auto Scaling group. It implements the CloudProvider interface type AWSClient struct { - svcEC2 ec2iface.EC2API - svcAutoscaling autoscalingiface.AutoScalingAPI + svcEC2 *ec2.Client + svcAutoscaling *autoscaling.Client config *awsConfig } @@ -33,23 +33,21 @@ func NewAWSClient(data []byte) (*AWSClient, error) { if cfg.Region == "self" { httpClient := &http.Client{Timeout: connTimeoutInSecs * time.Second} - params := &aws.Config{HTTPClient: httpClient} - metaSession, err := session.NewSession(params) + conf, err := config.LoadDefaultConfig(context.TODO()) if err != nil { return nil, err } - metaClient := ec2metadata.New(metaSession) - if !metaClient.Available() { - return nil, fmt.Errorf("ec2metadata service is unavailable") - } + client := imds.NewFromConfig(conf, func(o *imds.Options) { + o.HTTPClient = httpClient + }) - region, err := metaClient.Region() + response, err := client.GetRegion(context.TODO(), &imds.GetRegionInput{}) if err != nil { return nil, fmt.Errorf("unable to retrieve region from ec2metadata: %w", err) } - cfg.Region = region + cfg.Region = response.Region } awsClient.config = cfg @@ -85,15 +83,21 @@ func (client *AWSClient) GetUpstreams() []Upstream { // configure configures the AWSClient with necessary parameters func (client *AWSClient) configure() error { httpClient := &http.Client{Timeout: connTimeoutInSecs * time.Second} - cfg := &aws.Config{Region: aws.String(client.config.Region), HTTPClient: httpClient} - session, err := session.NewSession(cfg) + cfg, err := config.LoadDefaultConfig(context.TODO()) if err != nil { return err } - client.svcEC2 = ec2.New(session) - client.svcAutoscaling = autoscaling.New(session) + client.svcEC2 = ec2.NewFromConfig(cfg, func(o *ec2.Options) { + o.Region = client.config.Region + o.HTTPClient = httpClient + }) + + client.svcAutoscaling = autoscaling.NewFromConfig(cfg, func(o *autoscaling.Options) { + o.Region = client.config.Region + o.HTTPClient = httpClient + }) return nil } @@ -117,17 +121,17 @@ func parseAWSConfig(data []byte) (*awsConfig, error) { // CheckIfScalingGroupExists checks if the Auto Scaling group exists func (client *AWSClient) CheckIfScalingGroupExists(name string) (bool, error) { params := &ec2.DescribeInstancesInput{ - Filters: []*ec2.Filter{ + Filters: []types.Filter{ { Name: aws.String("tag:aws:autoscaling:groupName"), - Values: []*string{ - aws.String(name), + Values: []string{ + name, }, }, }, } - response, err := client.svcEC2.DescribeInstances(params) + response, err := client.svcEC2.DescribeInstances(context.Background(), params) if err != nil { return false, fmt.Errorf("couldn't check if an AutoScaling group exists: %w", err) } @@ -145,17 +149,17 @@ func (client *AWSClient) GetPrivateIPsForScalingGroup(name string) ([]string, er } } params := &ec2.DescribeInstancesInput{ - Filters: []*ec2.Filter{ + Filters: []types.Filter{ { Name: aws.String("tag:aws:autoscaling:groupName"), - Values: []*string{ - aws.String(name), + Values: []string{ + name, }, }, }, } - response, err := client.svcEC2.DescribeInstances(params) + response, err := client.svcEC2.DescribeInstances(context.Background(), params) if err != nil { return nil, err } @@ -193,10 +197,10 @@ func (client *AWSClient) getInstancesInService(insIDtoIP map[string]string) ([]s const maxItems = 50 var result []string keys := reflect.ValueOf(insIDtoIP).MapKeys() - instanceIds := make([]*string, len(keys)) + instanceIds := make([]string, len(keys)) for i := 0; i < len(keys); i++ { - instanceIds[i] = aws.String(keys[i].String()) + instanceIds[i] = keys[i].String() } batches := prepareBatches(maxItems, instanceIds) @@ -204,7 +208,7 @@ func (client *AWSClient) getInstancesInService(insIDtoIP map[string]string) ([]s params := &autoscaling.DescribeAutoScalingInstancesInput{ InstanceIds: batch, } - response, err := client.svcAutoscaling.DescribeAutoScalingInstances(params) + response, err := client.svcAutoscaling.DescribeAutoScalingInstances(context.Background(), params) if err != nil { return nil, err } @@ -219,8 +223,8 @@ func (client *AWSClient) getInstancesInService(insIDtoIP map[string]string) ([]s return result, nil } -func prepareBatches(maxItems int, items []*string) [][]*string { - var batches [][]*string +func prepareBatches(maxItems int, items []string) [][]string { + var batches [][]string min := func(a, b int) int { if a <= b { diff --git a/cmd/sync/aws_test.go b/cmd/sync/aws_test.go index 272b5990..5a8d114a 100644 --- a/cmd/sync/aws_test.go +++ b/cmd/sync/aws_test.go @@ -167,10 +167,10 @@ func areEqualUpstreamsAWS(u1 awsUpstream, u2 Upstream) bool { func TestPrepareBatches(t *testing.T) { const maxItems = 3 ids := []string{"i-394ujfs", "i-dfdinf", "i-fsfsf", "i-8hr83hfwif", "i-nsnsnan"} - instanceIds := make([]*string, len(ids)) + instanceIds := make([]string, len(ids)) for i := 0; i < len(ids); i++ { - instanceIds[i] = &ids[i] + instanceIds[i] = ids[i] } batches := prepareBatches(maxItems, instanceIds) diff --git a/go.mod b/go.mod index cb15191f..0ae59a50 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,11 @@ go 1.21.3 require ( github.com/Azure/azure-sdk-for-go v68.0.0+incompatible github.com/Azure/go-autorest/autorest/azure/auth v0.5.12 - github.com/aws/aws-sdk-go v1.50.0 + github.com/aws/aws-sdk-go-v2 v1.24.0 + github.com/aws/aws-sdk-go-v2/config v1.26.2 + github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.10 + github.com/aws/aws-sdk-go-v2/service/autoscaling v1.36.6 + github.com/aws/aws-sdk-go-v2/service/ec2 v1.142.0 github.com/nginxinc/nginx-plus-go-client v1.2.0 gopkg.in/yaml.v2 v2.4.0 ) @@ -20,6 +24,16 @@ require ( github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect github.com/Azure/go-autorest/logger v0.2.1 // indirect github.com/Azure/go-autorest/tracing v0.6.0 // indirect + github.com/aws/aws-sdk-go-v2/credentials v1.16.13 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.9 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.9 // indirect + github.com/aws/aws-sdk-go-v2/internal/ini v1.7.2 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.4 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.9 // indirect + github.com/aws/aws-sdk-go-v2/service/sso v1.18.5 // indirect + github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.5 // indirect + github.com/aws/aws-sdk-go-v2/service/sts v1.26.6 // indirect + github.com/aws/smithy-go v1.19.0 // indirect github.com/dimchansky/utfbom v1.1.1 // indirect github.com/golang-jwt/jwt/v4 v4.2.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect diff --git a/go.sum b/go.sum index 1dfe1b3e..3e607261 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,36 @@ github.com/Azure/go-autorest/logger v0.2.1 h1:IG7i4p/mDa2Ce4TRyAO8IHnVhAVF3RFU+Z github.com/Azure/go-autorest/logger v0.2.1/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZmbF5NWuPV8+WeEW8= github.com/Azure/go-autorest/tracing v0.6.0 h1:TYi4+3m5t6K48TGI9AUdb+IzbnSxvnvUMfuitfgcfuo= github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU= -github.com/aws/aws-sdk-go v1.50.0 h1:HBtrLeO+QyDKnc3t1+5DR1RxodOHCGr8ZcrHudpv7jI= -github.com/aws/aws-sdk-go v1.50.0/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= +github.com/aws/aws-sdk-go-v2 v1.24.0 h1:890+mqQ+hTpNuw0gGP6/4akolQkSToDJgHfQE7AwGuk= +github.com/aws/aws-sdk-go-v2 v1.24.0/go.mod h1:LNh45Br1YAkEKaAqvmE1m8FUx6a5b/V0oAKV7of29b4= +github.com/aws/aws-sdk-go-v2/config v1.26.2 h1:+RWLEIWQIGgrz2pBPAUoGgNGs1TOyF4Hml7hCnYj2jc= +github.com/aws/aws-sdk-go-v2/config v1.26.2/go.mod h1:l6xqvUxt0Oj7PI/SUXYLNyZ9T/yBPn3YTQcJLLOdtR8= +github.com/aws/aws-sdk-go-v2/credentials v1.16.13 h1:WLABQ4Cp4vXtXfOWOS3MEZKr6AAYUpMczLhgKtAjQ/8= +github.com/aws/aws-sdk-go-v2/credentials v1.16.13/go.mod h1:Qg6x82FXwW0sJHzYruxGiuApNo31UEtJvXVSZAXeWiw= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.10 h1:w98BT5w+ao1/r5sUuiH6JkVzjowOKeOJRHERyy1vh58= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.10/go.mod h1:K2WGI7vUvkIv1HoNbfBA1bvIZ+9kL3YVmWxeKuLQsiw= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.9 h1:v+HbZaCGmOwnTTVS86Fleq0vPzOd7tnJGbFhP0stNLs= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.9/go.mod h1:Xjqy+Nyj7VDLBtCMkQYOw1QYfAEZCVLrfI0ezve8wd4= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.9 h1:N94sVhRACtXyVcjXxrwK1SKFIJrA9pOJ5yu2eSHnmls= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.9/go.mod h1:hqamLz7g1/4EJP+GH5NBhcUMLjW+gKLQabgyz6/7WAU= +github.com/aws/aws-sdk-go-v2/internal/ini v1.7.2 h1:GrSw8s0Gs/5zZ0SX+gX4zQjRnRsMJDJ2sLur1gRBhEM= +github.com/aws/aws-sdk-go-v2/internal/ini v1.7.2/go.mod h1:6fQQgfuGmw8Al/3M2IgIllycxV7ZW7WCdVSqfBeUiCY= +github.com/aws/aws-sdk-go-v2/service/autoscaling v1.36.6 h1:xLETNIzlbzqb/ZFir6l1AQKjDJ96dQf/ekNysJHoxqo= +github.com/aws/aws-sdk-go-v2/service/autoscaling v1.36.6/go.mod h1:ldeYLrGhWz2aMgCEL7He3+YbJAG5xn1K/fFFKRkyzd0= +github.com/aws/aws-sdk-go-v2/service/ec2 v1.142.0 h1:VrFC1uEZjX4ghkm/et8ATVGb1mT75Iv8aPKPjUE+F8A= +github.com/aws/aws-sdk-go-v2/service/ec2 v1.142.0/go.mod h1:qjhtI9zjpUHRc6khtrIM9fb48+ii6+UikL3/b+MKYn0= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.4 h1:/b31bi3YVNlkzkBrm9LfpaKoaYZUxIAj4sHfOTmLfqw= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.4/go.mod h1:2aGXHFmbInwgP9ZfpmdIfOELL79zhdNYNmReK8qDfdQ= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.9 h1:Nf2sHxjMJR8CSImIVCONRi4g0Su3J+TSTbS7G0pUeMU= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.9/go.mod h1:idky4TER38YIjr2cADF1/ugFMKvZV7p//pVeV5LZbF0= +github.com/aws/aws-sdk-go-v2/service/sso v1.18.5 h1:ldSFWz9tEHAwHNmjx2Cvy1MjP5/L9kNoR0skc6wyOOM= +github.com/aws/aws-sdk-go-v2/service/sso v1.18.5/go.mod h1:CaFfXLYL376jgbP7VKC96uFcU8Rlavak0UlAwk1Dlhc= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.5 h1:2k9KmFawS63euAkY4/ixVNsYYwrwnd5fIvgEKkfZFNM= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.21.5/go.mod h1:W+nd4wWDVkSUIox9bacmkBP5NMFQeTJ/xqNabpzSR38= +github.com/aws/aws-sdk-go-v2/service/sts v1.26.6 h1:HJeiuZ2fldpd0WqngyMR6KW7ofkXNLyOaHwEIGm39Cs= +github.com/aws/aws-sdk-go-v2/service/sts v1.26.6/go.mod h1:XX5gh4CB7wAs4KhcF46G6C8a2i7eupU19dcAAE+EydU= +github.com/aws/smithy-go v1.19.0 h1:KWFKQV80DpP3vJrrA9sVAHQ5gc2z8i4EzrLhLlWXcBM= +github.com/aws/smithy-go v1.19.0/go.mod h1:NukqUGpCZIILqqiV0NIjeFh24kd/FAa4beRb6nbIUPE= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dimchansky/utfbom v1.1.1 h1:vV6w1AhK4VMnhBno/TPVCoK9U/LP0PkLCS9tbxHdi/U= @@ -31,6 +59,8 @@ github.com/dimchansky/utfbom v1.1.1/go.mod h1:SxdoEBH5qIqFocHMyGOXVAybYJdr71b1Q/ github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= github.com/golang-jwt/jwt/v4 v4.2.0 h1:besgBTC8w8HjP6NzQdxwKH9Z5oQMZ24ThTrHp3cZ8eU= github.com/golang-jwt/jwt/v4 v4.2.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= +github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= +github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=