Skip to content

Commit 87bf057

Browse files
chore: Deprecate EndpointResolver v1, bump some deps (#365)
Helps with: argoproj/argo-cd#22140 Remove deprecated functionality, moving to per-service endpoint and region resolution. Also, bump some dependencies. Signed-off-by: Andrii Korotkov <andrii.korotkov@verkada.com> Co-authored-by: Pasha Kostohrys <pavel@codefresh.io>
1 parent 5996040 commit 87bf057

File tree

4 files changed

+57
-88
lines changed

4 files changed

+57
-88
lines changed

go.mod

+9-6
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ require (
88
github.com/PagerDuty/go-pagerduty v1.8.0
99
github.com/RocketChat/Rocket.Chat.Go.SDK v0.0.0-20240116134246-a8cbe886bab0
1010
github.com/aws/aws-sdk-go-v2 v1.36.3
11-
github.com/aws/aws-sdk-go-v2/config v1.29.8
12-
github.com/aws/aws-sdk-go-v2/credentials v1.17.61
13-
github.com/aws/aws-sdk-go-v2/service/sqs v1.37.4
11+
github.com/aws/aws-sdk-go-v2/config v1.29.9
12+
github.com/aws/aws-sdk-go-v2/credentials v1.17.62
13+
github.com/aws/aws-sdk-go-v2/service/sqs v1.38.1
1414
github.com/bradleyfalzon/ghinstallation/v2 v2.14.0
1515
github.com/chainguard-dev/git-urls v1.0.2
1616
github.com/expr-lang/expr v1.16.9
@@ -51,9 +51,9 @@ require (
5151
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3 // indirect
5252
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.3 // indirect
5353
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.15 // indirect
54-
github.com/aws/aws-sdk-go-v2/service/sso v1.25.0 // indirect
55-
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.29.0 // indirect
56-
github.com/aws/aws-sdk-go-v2/service/sts v1.33.16 // indirect
54+
github.com/aws/aws-sdk-go-v2/service/sso v1.25.1 // indirect
55+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.29.1 // indirect
56+
github.com/aws/aws-sdk-go-v2/service/sts v1.33.17 // indirect
5757
github.com/aws/smithy-go v1.22.2 // indirect
5858
github.com/beorn7/perks v1.0.1 // indirect
5959
github.com/cespare/xxhash/v2 v2.3.0 // indirect
@@ -120,3 +120,6 @@ require (
120120
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
121121
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
122122
)
123+
124+
// Avoid CVE-2022-28948
125+
replace gopkg.in/yaml.v3 => gopkg.in/yaml.v3 v3.0.1

go.sum

+12-13
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ github.com/RocketChat/Rocket.Chat.Go.SDK v0.0.0-20240116134246-a8cbe886bab0/go.m
2323
github.com/appscode/go v0.0.0-20191119085241-0887d8ec2ecc/go.mod h1:OawnOmAL4ZX3YaPdN+8HTNwBveT1jMsqP74moa9XUbE=
2424
github.com/aws/aws-sdk-go-v2 v1.36.3 h1:mJoei2CxPutQVxaATCzDUjcZEjVRdpsiiXi2o38yqWM=
2525
github.com/aws/aws-sdk-go-v2 v1.36.3/go.mod h1:LLXuLpgzEbD766Z5ECcRmi8AzSwfZItDtmABVkRLGzg=
26-
github.com/aws/aws-sdk-go-v2/config v1.29.8 h1:RpwAfYcV2lr/yRc4lWhUM9JRPQqKgKWmou3LV7UfWP4=
27-
github.com/aws/aws-sdk-go-v2/config v1.29.8/go.mod h1:t+G7Fq1OcO8cXTPPXzxQSnj/5Xzdc9jAAD3Xrn9/Mgo=
28-
github.com/aws/aws-sdk-go-v2/credentials v1.17.61 h1:Hd/uX6Wo2iUW1JWII+rmyCD7MMhOe7ALwQXN6sKDd1o=
29-
github.com/aws/aws-sdk-go-v2/credentials v1.17.61/go.mod h1:L7vaLkwHY1qgW0gG1zG0z/X0sQ5tpIY5iI13+j3qI80=
26+
github.com/aws/aws-sdk-go-v2/config v1.29.9 h1:Kg+fAYNaJeGXp1vmjtidss8O2uXIsXwaRqsQJKXVr+0=
27+
github.com/aws/aws-sdk-go-v2/config v1.29.9/go.mod h1:oU3jj2O53kgOU4TXq/yipt6ryiooYjlkqqVaZk7gY/U=
28+
github.com/aws/aws-sdk-go-v2/credentials v1.17.62 h1:fvtQY3zFzYJ9CfixuAQ96IxDrBajbBWGqjNTCa79ocU=
29+
github.com/aws/aws-sdk-go-v2/credentials v1.17.62/go.mod h1:ElETBxIQqcxej++Cs8GyPBbgMys5DgQPTwo7cUPDKt8=
3030
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.30 h1:x793wxmUWVDhshP8WW2mlnXuFrO4cOd3HLBroh1paFw=
3131
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.30/go.mod h1:Jpne2tDnYiFascUEs2AWHJL9Yp7A5ZVy3TNyxaAjD6M=
3232
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.34 h1:ZK5jHhnrioRkUNOc+hOgQKlUL5JeC3S6JgLxtQ+Rm0Q=
@@ -39,14 +39,14 @@ github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.3 h1:eAh2A4b
3939
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.3/go.mod h1:0yKJC/kb8sAnmlYa6Zs3QVYqaC8ug2AbnNChv5Ox3uA=
4040
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.15 h1:dM9/92u2F1JbDaGooxTq18wmmFzbJRfXfVfy96/1CXM=
4141
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.15/go.mod h1:SwFBy2vjtA0vZbjjaFtfN045boopadnoVPhu4Fv66vY=
42-
github.com/aws/aws-sdk-go-v2/service/sqs v1.37.4 h1:WpoMCoS4+qOkkuWQommvDRboKYzK91En6eXO/k5dXr0=
43-
github.com/aws/aws-sdk-go-v2/service/sqs v1.37.4/go.mod h1:171mrsbgz6DahPMnLJzQiH3bXXrdsWhpE9USZiM19Lk=
44-
github.com/aws/aws-sdk-go-v2/service/sso v1.25.0 h1:2U9sF8nKy7UgyEeLiZTRg6ShBS22z8UnYpV6aRFL0is=
45-
github.com/aws/aws-sdk-go-v2/service/sso v1.25.0/go.mod h1:qs4a9T5EMLl/Cajiw2TcbNt2UNo/Hqlyp+GiuG4CFDI=
46-
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.29.0 h1:wjAdc85cXdQR5uLx5FwWvGIHm4OPJhTyzUHU8craXtE=
47-
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.29.0/go.mod h1:MlYRNmYu/fGPoxBQVvBYr9nyr948aY/WLUvwBMBJubs=
48-
github.com/aws/aws-sdk-go-v2/service/sts v1.33.16 h1:BHEK2Q/7CMRMCb3nySi/w8UbIcPhKvYP5s1xf8/izn0=
49-
github.com/aws/aws-sdk-go-v2/service/sts v1.33.16/go.mod h1:cQnB8CUnxbMU82JvlqjKR2HBOm3fe9pWorWBza6MBJ4=
42+
github.com/aws/aws-sdk-go-v2/service/sqs v1.38.1 h1:ZtgZeMPJH8+/vNs9vJFFLI0QEzYbcN0p7x1/FFwyROc=
43+
github.com/aws/aws-sdk-go-v2/service/sqs v1.38.1/go.mod h1:Bar4MrRxeqdn6XIh8JGfiXuFRmyrrsZNTJotxEJmWW0=
44+
github.com/aws/aws-sdk-go-v2/service/sso v1.25.1 h1:8JdC7Gr9NROg1Rusk25IcZeTO59zLxsKgE0gkh5O6h0=
45+
github.com/aws/aws-sdk-go-v2/service/sso v1.25.1/go.mod h1:qs4a9T5EMLl/Cajiw2TcbNt2UNo/Hqlyp+GiuG4CFDI=
46+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.29.1 h1:KwuLovgQPcdjNMfFt9OhUd9a2OwcOKhxfvF4glTzLuA=
47+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.29.1/go.mod h1:MlYRNmYu/fGPoxBQVvBYr9nyr948aY/WLUvwBMBJubs=
48+
github.com/aws/aws-sdk-go-v2/service/sts v1.33.17 h1:PZV5W8yk4OtH1JAuhV2PXwwO9v5G5Aoj+eMCn4T+1Kc=
49+
github.com/aws/aws-sdk-go-v2/service/sts v1.33.17/go.mod h1:cQnB8CUnxbMU82JvlqjKR2HBOm3fe9pWorWBza6MBJ4=
5050
github.com/aws/smithy-go v1.22.2 h1:6D9hW43xKFrRx/tXXfAlIZc4JI+yQe6snnWcQyxSyLQ=
5151
github.com/aws/smithy-go v1.22.2/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
5252
github.com/beevik/ntp v0.2.0/go.mod h1:hIHWr+l3+/clUnF44zdK+CWW7fO8dR5cIylAQ76NRpg=
@@ -420,7 +420,6 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
420420
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
421421
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
422422
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
423-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
424423
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
425424
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
426425
k8s.io/api v0.32.2 h1:bZrMLEkgizC24G9eViHGOPbW+aRo9duEISRIJKfdJuw=

pkg/services/awssqs.go

+21-30
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ type awsSqsService struct {
4141
}
4242

4343
func (s awsSqsService) Send(notif Notification, dest Destination) error {
44-
options := s.setOptions()
45-
cfg, err := config.LoadDefaultConfig(context.TODO(), options...)
44+
cfgOptions := s.getConfigOptions()
45+
cfg, err := config.LoadDefaultConfig(context.TODO(), cfgOptions...)
4646
if err != nil {
4747
log.Fatalf("failed to load configuration, %v", err)
4848
}
4949

50-
client := sqs.NewFromConfig(cfg)
50+
clientOptions := s.getClientOptions()
51+
client := sqs.NewFromConfig(cfg, clientOptions...)
5152

5253
queueUrl, err := GetQueueURL(context.TODO(), client, s.getQueueInput(dest))
5354
if err != nil {
@@ -89,7 +90,7 @@ func (s awsSqsService) getQueueInput(dest Destination) *sqs.GetQueueUrlInput {
8990
return result
9091
}
9192

92-
func (s awsSqsService) setOptions() []func(*config.LoadOptions) error {
93+
func (s awsSqsService) getConfigOptions() []func(*config.LoadOptions) error {
9394
// Slice for AWS config options
9495
var options []func(*config.LoadOptions) error
9596

@@ -103,36 +104,26 @@ func (s awsSqsService) setOptions() []func(*config.LoadOptions) error {
103104
options = append(options, config.WithRegion(s.opts.Region))
104105
}
105106

106-
// Useful for testing with localstack
107-
if s.opts.EndpointUrl != "" {
108-
endpointRegion := os.Getenv("AWS_DEFAULT_REGION")
109-
if s.opts.Region != "" {
110-
endpointRegion = s.opts.Region
111-
}
112-
//nolint:staticcheck // SA1019 Migration needed
113-
customResolver := aws.EndpointResolverWithOptionsFunc(s.getCustomResolver(endpointRegion))
114-
//nolint:staticcheck // SA1019 Migration needed
115-
options = append(options, config.WithEndpointResolverWithOptions(customResolver))
116-
}
117107
return options
118108
}
119109

120-
//nolint:staticcheck // SA1019 Migration needed
121-
func (s awsSqsService) getCustomResolver(endpointRegion string) func(service, region string, options ...interface{}) (aws.Endpoint, error) {
122-
//nolint:staticcheck // SA1019 Migration needed
123-
return func(service, region string, options ...interface{}) (aws.Endpoint, error) {
124-
if service == sqs.ServiceID {
125-
//nolint:staticcheck // SA1019 Migration needed
126-
return aws.Endpoint{
127-
PartitionID: "aws",
128-
URL: s.opts.EndpointUrl,
129-
SigningRegion: endpointRegion,
130-
}, nil
131-
}
132-
// returning EndpointNotFoundError will allow the service to fallback to it's default resolution
133-
//nolint:staticcheck // SA1019 Migration needed
134-
return aws.Endpoint{}, &aws.EndpointNotFoundError{}
110+
func (s awsSqsService) getClientOptions() []func(*sqs.Options) {
111+
clientOptions := []func(o *sqs.Options){}
112+
if s.opts.EndpointUrl != "" {
113+
clientOptions = append(clientOptions, func(o *sqs.Options) {
114+
o.BaseEndpoint = aws.String(s.opts.EndpointUrl)
115+
})
116+
}
117+
endpointRegion := os.Getenv("AWS_DEFAULT_REGION")
118+
if s.opts.Region != "" {
119+
endpointRegion = s.opts.Region
120+
}
121+
if endpointRegion != "" {
122+
clientOptions = append(clientOptions, func(o *sqs.Options) {
123+
o.Region = endpointRegion
124+
})
135125
}
126+
return clientOptions
136127
}
137128

138129
func (n *AwsSqsNotification) GetTemplater(name string, f texttemplate.FuncMap) (Templater, error) {

pkg/services/awssqs_test.go

+15-39
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func TestSendFail_AwsSqs(t *testing.T) {
9898
}
9999
}
100100

101-
func TestSetOptions_AwsSqs(t *testing.T) {
101+
func TestGetConfigOptions_AwsSqs(t *testing.T) {
102102
s := NewTypedAwsSqsService(AwsSqsOptions{
103103
Region: "us-east-1",
104104
AwsAccess: AwsAccess{
@@ -109,7 +109,7 @@ func TestSetOptions_AwsSqs(t *testing.T) {
109109
})
110110

111111
options := &config.LoadOptions{}
112-
optionsF := SetOptions(s)
112+
optionsF := GetConfigOptions(s)
113113

114114
for _, f := range optionsF {
115115
assert.NoError(t, f(options))
@@ -120,13 +120,9 @@ func TestSetOptions_AwsSqs(t *testing.T) {
120120
creds, _ := options.Credentials.Retrieve(context.TODO())
121121
assert.Equal(t, s.opts.AwsAccess.Key, creds.AccessKeyID)
122122
assert.Equal(t, s.opts.AwsAccess.Secret, creds.SecretAccessKey)
123-
// Verify custom resolver is used
124-
//nolint:staticcheck // SA1019 Migration needed
125-
var resolverType aws.EndpointResolverWithOptionsFunc
126-
assert.IsType(t, resolverType, options.EndpointResolverWithOptions)
127123
}
128124

129-
func TestSetOptionsFromEnv_AwsSqs(t *testing.T) {
125+
func TestGetConfigOptionsFromEnv_AwsSqs(t *testing.T) {
130126
// Applying override via parameters instead of the ENV Variables
131127
finalKey, finalSecret, finalRegion := "key", "secret", "us-east-1"
132128

@@ -136,7 +132,7 @@ func TestSetOptionsFromEnv_AwsSqs(t *testing.T) {
136132

137133
s := NewTypedAwsSqsService(AwsSqsOptions{})
138134

139-
options := SetOptions(s)
135+
options := GetConfigOptions(s)
140136
cfg, err := config.LoadDefaultConfig(context.TODO(), options...)
141137
assert.NoError(t, err)
142138

@@ -147,7 +143,7 @@ func TestSetOptionsFromEnv_AwsSqs(t *testing.T) {
147143
assert.Equal(t, finalRegion, cfg.Region)
148144
}
149145

150-
func TestSetOptionsOverrideCredentials_AwsSqs(t *testing.T) {
146+
func TestGetConfigOptionsOverrideCredentials_AwsSqs(t *testing.T) {
151147
os.Setenv("AWS_ACCESS_KEY_ID", "env_key")
152148
os.Setenv("AWS_SECRET_ACCESS_KEY", "env_secret")
153149
os.Setenv("AWS_DEFAULT_REGION", "us-east-2")
@@ -163,7 +159,7 @@ func TestSetOptionsOverrideCredentials_AwsSqs(t *testing.T) {
163159
},
164160
})
165161

166-
options := SetOptions(s)
162+
options := GetConfigOptions(s)
167163
cfg, err := config.LoadDefaultConfig(context.TODO(), options...)
168164
assert.NoError(t, err)
169165

@@ -174,7 +170,7 @@ func TestSetOptionsOverrideCredentials_AwsSqs(t *testing.T) {
174170
assert.Equal(t, finalRegion, cfg.Region)
175171
}
176172

177-
func TestSetOptionsCustomEndpointUrl_AwsSqs(t *testing.T) {
173+
func TestGetConfigOptionsCustomEndpointUrl_AwsSqs(t *testing.T) {
178174
// Will be overridden
179175
os.Setenv("AWS_DEFAULT_REGION", "us-east-2")
180176

@@ -189,7 +185,7 @@ func TestSetOptionsCustomEndpointUrl_AwsSqs(t *testing.T) {
189185
EndpointUrl: finalEndpoint,
190186
})
191187

192-
options := SetOptions(s)
188+
options := GetConfigOptions(s)
193189
cfg, err := config.LoadDefaultConfig(context.TODO(), options...)
194190
assert.NoError(t, err)
195191

@@ -199,27 +195,10 @@ func TestSetOptionsCustomEndpointUrl_AwsSqs(t *testing.T) {
199195
assert.Equal(t, finalSecret, creds.SecretAccessKey)
200196
assert.Equal(t, finalRegion, cfg.Region)
201197
}
202-
func TestSetOptionsCustomResolverFunc(t *testing.T) {
203198

204-
finalKey, finalSecret, finalRegion, finalEndpoint := "key", "secret", "us-east-1", "localhost"
205-
206-
s := NewTypedAwsSqsService(AwsSqsOptions{
207-
Region: finalRegion,
208-
AwsAccess: AwsAccess{
209-
Key: finalKey,
210-
Secret: finalSecret,
211-
},
212-
EndpointUrl: finalEndpoint,
213-
})
214-
215-
customResolver := s.getCustomResolver(finalRegion)
216-
endpoint, err := customResolver(sqs.ServiceID, finalRegion)
217-
assert.NoError(t, err)
218-
assert.Equal(t, finalEndpoint, endpoint.URL)
219-
220-
}
221-
222-
func TestSetOptionsCustomResolverFuncReturnErr(t *testing.T) {
199+
func TestGetClientOptionsCustomEndpointUrl_AwsSqs(t *testing.T) {
200+
// Will be overridden
201+
os.Setenv("AWS_DEFAULT_REGION", "us-east-2")
223202

224203
finalKey, finalSecret, finalRegion, finalEndpoint := "key", "secret", "us-east-1", "localhost"
225204

@@ -232,16 +211,13 @@ func TestSetOptionsCustomResolverFuncReturnErr(t *testing.T) {
232211
EndpointUrl: finalEndpoint,
233212
})
234213

235-
customResolver := s.getCustomResolver(finalRegion)
236-
_, err := customResolver("NotSQS", finalRegion)
237-
assert.Error(t, err)
238-
//assert that err is of type aws.EndpointNotFoundError
239-
assert.IsType(t, &aws.EndpointNotFoundError{}, err)
240-
214+
options := GetClientOptions(s)
215+
assert.Equal(t, 2, len(options))
241216
}
242217

243218
// Helpers
244-
var SetOptions = (*awsSqsService).setOptions
219+
var GetConfigOptions = (*awsSqsService).getConfigOptions
220+
var GetClientOptions = (*awsSqsService).getClientOptions
245221
var SendMessageInput = (*awsSqsService).sendMessageInput
246222

247223
var NewTypedAwsSqsService = func(opts AwsSqsOptions) *awsSqsService {

0 commit comments

Comments
 (0)