Skip to content

Commit fc47c35

Browse files
authored
chore: migrate to aws-sdk-go-v2 (lightsail, route53) (#1973)
1 parent ed14dda commit fc47c35

File tree

14 files changed

+319
-215
lines changed

14 files changed

+319
-215
lines changed

docs/content/dns/zz_gen_lightsail.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ Alternatively, you can also set the `Resource` to `*` (wildcard), which allow to
9595
## More information
9696

9797

98-
- [Go client](https://github.com/aws/aws-sdk-go/)
98+
- [Go client](https://github.com/aws/aws-sdk-go-v2)
9999

100100
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
101101
<!-- providers/dns/lightsail/lightsail.toml -->

docs/content/dns/zz_gen_route53.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ Replace `Z11111112222222333333` with your hosted zone ID and `example.com` with
178178
## More information
179179

180180
- [API documentation](https://docs.aws.amazon.com/Route53/latest/APIReference/API_Operations_Amazon_Route_53.html)
181-
- [Go client](https://github.com/aws/aws-sdk-go/aws)
181+
- [Go client](https://github.com/aws/aws-sdk-go-v2)
182182

183183
<!-- THIS DOCUMENTATION IS AUTO-GENERATED. PLEASE DO NOT EDIT. -->
184184
<!-- providers/dns/route53/route53.toml -->

go.mod

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/go-acme/lego/v4
33
go 1.19
44

55
// github.com/exoscale/egoscale v1.19.0 => It is an error, please don't use it.
6+
67
require (
78
cloud.google.com/go/compute/metadata v0.2.3
89
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible
@@ -17,7 +18,12 @@ require (
1718
github.com/OpenDNS/vegadns2client v0.0.0-20180418235048-a3fa4a771d87
1819
github.com/akamai/AkamaiOPEN-edgegrid-golang v1.2.2
1920
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1755
20-
github.com/aws/aws-sdk-go v1.39.0
21+
github.com/aws/aws-sdk-go-v2 v1.19.0
22+
github.com/aws/aws-sdk-go-v2/config v1.18.28
23+
github.com/aws/aws-sdk-go-v2/credentials v1.13.27
24+
github.com/aws/aws-sdk-go-v2/service/lightsail v1.27.2
25+
github.com/aws/aws-sdk-go-v2/service/route53 v1.28.4
26+
github.com/aws/aws-sdk-go-v2/service/sts v1.19.3
2127
github.com/cenkalti/backoff/v4 v4.2.1
2228
github.com/civo/civogo v0.3.11
2329
github.com/cloudflare/cloudflare-go v0.70.0
@@ -89,6 +95,14 @@ require (
8995
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
9096
github.com/AzureAD/microsoft-authentication-library-for-go v1.0.0 // indirect
9197
github.com/andres-erbsen/clock v0.0.0-20160526145045-9e14626cd129 // indirect
98+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.5 // indirect
99+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.35 // indirect
100+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.29 // indirect
101+
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.36 // indirect
102+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.29 // indirect
103+
github.com/aws/aws-sdk-go-v2/service/sso v1.12.13 // indirect
104+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.13 // indirect
105+
github.com/aws/smithy-go v1.13.5 // indirect
92106
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
93107
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
94108
github.com/davecgh/go-spew v1.1.1 // indirect

go.sum

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,34 @@ github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kd
7474
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
7575
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
7676
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
77-
github.com/aws/aws-sdk-go v1.39.0 h1:74BBwkEmiqBbi2CGflEh34l0YNtIibTjZsibGarkNjo=
78-
github.com/aws/aws-sdk-go v1.39.0/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
77+
github.com/aws/aws-sdk-go-v2 v1.19.0 h1:klAT+y3pGFBU/qVf1uzwttpBbiuozJYWzNLHioyDJ+k=
78+
github.com/aws/aws-sdk-go-v2 v1.19.0/go.mod h1:uzbQtefpm44goOPmdKyAlXSNcwlRgF3ePWVW6EtJvvw=
79+
github.com/aws/aws-sdk-go-v2/config v1.18.28 h1:TINEaKyh1Td64tqFvn09iYpKiWjmHYrG1fa91q2gnqw=
80+
github.com/aws/aws-sdk-go-v2/config v1.18.28/go.mod h1:nIL+4/8JdAuNHEjn/gPEXqtnS02Q3NXB/9Z7o5xE4+A=
81+
github.com/aws/aws-sdk-go-v2/credentials v1.13.27 h1:dz0yr/yR1jweAnsCx+BmjerUILVPQ6FS5AwF/OyG1kA=
82+
github.com/aws/aws-sdk-go-v2/credentials v1.13.27/go.mod h1:syOqAek45ZXZp29HlnRS/BNgMIW6uiRmeuQsz4Qh2UE=
83+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.5 h1:kP3Me6Fy3vdi+9uHd7YLr6ewPxRL+PU6y15urfTaamU=
84+
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.5/go.mod h1:Gj7tm95r+QsDoN2Fhuz/3npQvcZbkEf5mL70n3Xfluc=
85+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.35 h1:hMUCiE3Zi5AHrRNGf5j985u0WyqI6r2NULhUfo0N/No=
86+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.35/go.mod h1:ipR5PvpSPqIqL5Mi82BxLnfMkHVbmco8kUwO2xrCi0M=
87+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.29 h1:yOpYx+FTBdpk/g+sBU6Cb1H0U/TLEcYYp66mYqsPpcc=
88+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.29/go.mod h1:M/eUABlDbw2uVrdAn+UsI6M727qp2fxkp8K0ejcBDUY=
89+
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.36 h1:8r5m1BoAWkn0TDC34lUculryf7nUF25EgIMdjvGCkgo=
90+
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.36/go.mod h1:Rmw2M1hMVTwiUhjwMoIBFWFJMhvJbct06sSidxInkhY=
91+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.29 h1:IiDolu/eLmuB18DRZibj77n1hHQT7z12jnGO7Ze3pLc=
92+
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.29/go.mod h1:fDbkK4o7fpPXWn8YAPmTieAMuB9mk/VgvW64uaUqxd4=
93+
github.com/aws/aws-sdk-go-v2/service/lightsail v1.27.2 h1:PwNeYoonBzmTdCztKiiutws3U24KrnDBuabzRfIlZY4=
94+
github.com/aws/aws-sdk-go-v2/service/lightsail v1.27.2/go.mod h1:gQhLZrTEath4zik5ixIe6axvgY5jJrgSBDJ360Fxnco=
95+
github.com/aws/aws-sdk-go-v2/service/route53 v1.28.4 h1:p4mTxJfCAyiTT4Wp6p/mOPa6j5MqCSRGot8qZwFs+Z0=
96+
github.com/aws/aws-sdk-go-v2/service/route53 v1.28.4/go.mod h1:VBLWpaHvhQNeu7N9rMEf00SWeOONb/HvaDUxe/7b44k=
97+
github.com/aws/aws-sdk-go-v2/service/sso v1.12.13 h1:sWDv7cMITPcZ21QdreULwxOOAmE05JjEsT6fCDtDA9k=
98+
github.com/aws/aws-sdk-go-v2/service/sso v1.12.13/go.mod h1:DfX0sWuT46KpcqbMhJ9QWtxAIP1VozkDWf8VAkByjYY=
99+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.13 h1:BFubHS/xN5bjl818QaroN6mQdjneYQ+AOx44KNXlyH4=
100+
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.13/go.mod h1:BzqsVVFduubEmzrVtUFQQIQdFqvUItF8XUq2EnS8Wog=
101+
github.com/aws/aws-sdk-go-v2/service/sts v1.19.3 h1:e5mnydVdCVWxP+5rPAGi2PYxC7u2OZgH1ypC114H04U=
102+
github.com/aws/aws-sdk-go-v2/service/sts v1.19.3/go.mod h1:yVGZA1CPkmUhBdA039jXNJJG7/6t+G+EBWmFq23xqnY=
103+
github.com/aws/smithy-go v1.13.5 h1:hgz0X/DX0dGqTYpGALqXJoRKRj5oQ7150i5FdTePzO8=
104+
github.com/aws/smithy-go v1.13.5/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA=
79105
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
80106
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
81107
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
@@ -220,6 +246,7 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
220246
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
221247
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
222248
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
249+
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
223250
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
224251
github.com/google/go-github/v32 v32.1.0/go.mod h1:rIEpZD9CTDQwDK9GDrtMTycQNA4JU3qBsCizh3q2WCI=
225252
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=

platform/tester/env.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ func (e *EnvTest) WithLiveTestRequirements(keys ...string) *EnvTest {
5151
panic(fmt.Sprintf("Unauthorized action, the env var %s is not managed or it's not the key of the domain.", key))
5252
}
5353

54+
if e.domainKey == key {
55+
countValuedVars++
56+
continue
57+
}
58+
5459
if _, ok := e.values[key]; ok {
5560
countValuedVars++
5661
}

platform/tester/env_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,22 @@ func TestEnvTest(t *testing.T) {
148148
assert.Equal(t, "", envTest.GetDomain())
149149
},
150150
},
151+
{
152+
desc: "WithLiveTestRequirements with domain as requirement",
153+
envVars: map[string]string{
154+
envVar01: "A",
155+
envVar02: "B",
156+
},
157+
envTestSetup: func() *tester.EnvTest {
158+
return tester.NewEnvTest(envVar01, envVar02).WithDomain(envVarDomain).WithLiveTestRequirements(envVar02, envVarDomain)
159+
},
160+
expected: func(t *testing.T, envTest *tester.EnvTest) {
161+
assert.True(t, envTest.IsLiveTest())
162+
assert.Equal(t, "A", envTest.GetValue(envVar01))
163+
assert.Equal(t, "B", envTest.GetValue(envVar02))
164+
assert.Equal(t, "", envTest.GetDomain())
165+
},
166+
},
151167
{
152168
desc: "WithLiveTestRequirements non required var missing",
153169
envVars: map[string]string{

providers/dns/lightsail/lightsail.go

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
package lightsail
33

44
import (
5+
"context"
56
"errors"
67
"fmt"
78
"math/rand"
89
"strconv"
910
"time"
1011

11-
"github.com/aws/aws-sdk-go/aws"
12-
"github.com/aws/aws-sdk-go/aws/client"
13-
"github.com/aws/aws-sdk-go/aws/request"
14-
"github.com/aws/aws-sdk-go/aws/session"
15-
"github.com/aws/aws-sdk-go/service/lightsail"
12+
"github.com/aws/aws-sdk-go-v2/aws"
13+
"github.com/aws/aws-sdk-go-v2/aws/retry"
14+
awsconfig "github.com/aws/aws-sdk-go-v2/config"
15+
"github.com/aws/aws-sdk-go-v2/service/lightsail"
16+
awstypes "github.com/aws/aws-sdk-go-v2/service/lightsail/types"
1617
"github.com/go-acme/lego/v4/challenge/dns01"
1718
"github.com/go-acme/lego/v4/platform/config/env"
1819
)
@@ -32,27 +33,6 @@ const (
3233
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
3334
)
3435

35-
// customRetryer implements the client.Retryer interface by composing the DefaultRetryer.
36-
// It controls the logic for retrying recoverable request errors (e.g. when rate limits are exceeded).
37-
type customRetryer struct {
38-
client.DefaultRetryer
39-
}
40-
41-
// RetryRules overwrites the DefaultRetryer's method.
42-
// It uses a basic exponential backoff algorithm that returns an initial
43-
// delay of ~400ms with an upper limit of ~30 seconds which should prevent
44-
// causing a high number of consecutive throttling errors.
45-
// For reference: Route 53 enforces an account-wide(!) 5req/s query limit.
46-
func (c customRetryer) RetryRules(r *request.Request) time.Duration {
47-
retryCount := r.RetryCount
48-
if retryCount > 7 {
49-
retryCount = 7
50-
}
51-
52-
delay := (1 << uint(retryCount)) * (rand.Intn(50) + 200)
53-
return time.Duration(delay) * time.Millisecond
54-
}
55-
5636
// Config is used to configure the creation of the DNSProvider.
5737
type Config struct {
5838
DNSZone string
@@ -71,7 +51,7 @@ func NewDefaultConfig() *Config {
7151

7252
// DNSProvider implements the challenge.Provider interface.
7353
type DNSProvider struct {
74-
client *lightsail.Lightsail
54+
client *lightsail.Client
7555
config *Config
7656
}
7757

@@ -102,35 +82,55 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
10282
return nil, errors.New("lightsail: the configuration of the DNS provider is nil")
10383
}
10484

105-
retryer := customRetryer{}
106-
retryer.NumMaxRetries = maxRetries
107-
108-
conf := aws.NewConfig().WithRegion(config.Region)
109-
sess, err := session.NewSession(request.WithRetryer(conf, retryer))
85+
ctx := context.Background()
86+
87+
cfg, err := awsconfig.LoadDefaultConfig(ctx,
88+
awsconfig.WithRegion(config.Region),
89+
awsconfig.WithRetryer(func() aws.Retryer {
90+
return retry.NewStandard(func(options *retry.StandardOptions) {
91+
options.MaxAttempts = maxRetries
92+
93+
// It uses a basic exponential backoff algorithm that returns an initial
94+
// delay of ~400ms with an upper limit of ~30 seconds which should prevent
95+
// causing a high number of consecutive throttling errors.
96+
// For reference: Route 53 enforces an account-wide(!) 5req/s query limit.
97+
options.Backoff = retry.BackoffDelayerFunc(func(attempt int, err error) (time.Duration, error) {
98+
retryCount := attempt
99+
if retryCount > 7 {
100+
retryCount = 7
101+
}
102+
103+
delay := (1 << uint(retryCount)) * (rand.Intn(50) + 200)
104+
return time.Duration(delay) * time.Millisecond, nil
105+
})
106+
})
107+
}),
108+
)
110109
if err != nil {
111110
return nil, err
112111
}
113112

114113
return &DNSProvider{
115114
config: config,
116-
client: lightsail.New(sess),
115+
client: lightsail.NewFromConfig(cfg),
117116
}, nil
118117
}
119118

120119
// Present creates a TXT record using the specified parameters.
121-
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
120+
func (d *DNSProvider) Present(domain, _, keyAuth string) error {
121+
ctx := context.Background()
122122
info := dns01.GetChallengeInfo(domain, keyAuth)
123123

124124
params := &lightsail.CreateDomainEntryInput{
125125
DomainName: aws.String(d.config.DNSZone),
126-
DomainEntry: &lightsail.DomainEntry{
126+
DomainEntry: &awstypes.DomainEntry{
127127
Name: aws.String(info.EffectiveFQDN),
128128
Target: aws.String(strconv.Quote(info.Value)),
129129
Type: aws.String("TXT"),
130130
},
131131
}
132132

133-
_, err := d.client.CreateDomainEntry(params)
133+
_, err := d.client.CreateDomainEntry(ctx, params)
134134
if err != nil {
135135
return fmt.Errorf("lightsail: %w", err)
136136
}
@@ -139,19 +139,20 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
139139
}
140140

141141
// CleanUp removes the TXT record matching the specified parameters.
142-
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
142+
func (d *DNSProvider) CleanUp(domain, _, keyAuth string) error {
143+
ctx := context.Background()
143144
info := dns01.GetChallengeInfo(domain, keyAuth)
144145

145146
params := &lightsail.DeleteDomainEntryInput{
146147
DomainName: aws.String(d.config.DNSZone),
147-
DomainEntry: &lightsail.DomainEntry{
148+
DomainEntry: &awstypes.DomainEntry{
148149
Name: aws.String(info.EffectiveFQDN),
149150
Type: aws.String("TXT"),
150151
Target: aws.String(strconv.Quote(info.Value)),
151152
},
152153
}
153154

154-
_, err := d.client.DeleteDomainEntry(params)
155+
_, err := d.client.DeleteDomainEntry(ctx, params)
155156
if err != nil {
156157
return fmt.Errorf("lightsail: %w", err)
157158
}

providers/dns/lightsail/lightsail.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ Alternatively, you can also set the `Resource` to `*` (wildcard), which allow to
5656
LIGHTSAIL_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation"
5757

5858
[Links]
59-
GoClient = "https://github.com/aws/aws-sdk-go/"
59+
GoClient = "https://github.com/aws/aws-sdk-go-v2"

providers/dns/lightsail/lightsail_integration_test.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package lightsail
22

33
import (
4+
"context"
45
"testing"
56

6-
"github.com/aws/aws-sdk-go/aws"
7-
"github.com/aws/aws-sdk-go/aws/session"
8-
"github.com/aws/aws-sdk-go/service/lightsail"
7+
"github.com/aws/aws-sdk-go-v2/aws"
8+
awsconfig "github.com/aws/aws-sdk-go-v2/config"
9+
"github.com/aws/aws-sdk-go-v2/service/lightsail"
910
"github.com/stretchr/testify/require"
1011
)
1112

@@ -24,13 +25,15 @@ func TestLiveTTL(t *testing.T) {
2425
err = provider.Present(domain, "foo", "bar")
2526
require.NoError(t, err)
2627

27-
// we need a separate Lightsail client here as the one in the DNS provider is
28-
// unexported.
28+
// we need a separate Lightsail client here as the one in the DNS provider is unexported.
2929
fqdn := "_acme-challenge." + domain
30-
sess, err := session.NewSession()
30+
31+
ctx := context.Background()
32+
33+
cfg, err := awsconfig.LoadDefaultConfig(ctx)
3134
require.NoError(t, err)
3235

33-
svc := lightsail.New(sess)
36+
svc := lightsail.NewFromConfig(cfg)
3437
require.NoError(t, err)
3538

3639
defer func() {
@@ -44,15 +47,24 @@ func TestLiveTTL(t *testing.T) {
4447
DomainName: aws.String(domain),
4548
}
4649

47-
resp, err := svc.GetDomain(params)
50+
resp, err := svc.GetDomain(ctx, params)
4851
require.NoError(t, err)
4952

5053
entries := resp.Domain.DomainEntries
5154
for _, entry := range entries {
52-
if aws.StringValue(entry.Type) == "TXT" && aws.StringValue(entry.Name) == fqdn {
55+
if deref(entry.Type) == "TXT" && deref(entry.Name) == fqdn {
5356
return
5457
}
5558
}
5659

5760
t.Fatalf("Could not find a TXT record for _acme-challenge.%s", domain)
5861
}
62+
63+
func deref[T string | int | int32 | int64 | bool](v *T) T {
64+
if v == nil {
65+
var zero T
66+
return zero
67+
}
68+
69+
return *v
70+
}

0 commit comments

Comments
 (0)