This repository was archived by the owner on Oct 22, 2025. It is now read-only.
forked from libdns/route53
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprovider.go
More file actions
177 lines (140 loc) · 5.08 KB
/
provider.go
File metadata and controls
177 lines (140 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package route53
import (
"context"
"time"
r53 "github.com/aws/aws-sdk-go-v2/service/route53"
"github.com/libdns/libdns"
)
// Provider implements the libdns interfaces for Route53.
//
// By default, the provider loads the AWS configuration from the environment.
// To override these values, set the fields in the Provider struct.
type Provider struct {
client *r53.Client
// Region is the AWS Region to use. If not set, it will use AWS_REGION
// environment variable.
Region string `json:"region,omitempty"`
// AWSProfile is the AWS Profile to use. If not set, it will use
// AWS_PROFILE environment variable.
//
// Deprecated: Use Profile instead
AWSProfile string `json:"aws_profile,omitempty"`
// AWSProfile is the AWS Profile to use. If not set, it will use
// AWS_PROFILE environment variable.
Profile string `json:"profile,omitempty"`
// AccessKeyId is the AWS Access Key ID to use. If not set, it will use
// AWS_ACCESS_KEY_ID
AccessKeyId string `json:"access_key_id,omitempty"`
// SecretAccessKey is the AWS Secret Access Key to use. If not set, it will use
// AWS_SECRET_ACCESS_KEY environment variable.
SecretAccessKey string `json:"secret_access_key,omitempty"`
// Token is the AWS Session Token to use. If not set, it will use
// AWS_SESSION_TOKEN environment variable.
//
// Deprecated: Use SessionToken instead.
Token string `json:"token,omitempty"`
// SessionToken is the AWS Session Token to use. If not set, it will use
// AWS_SESSION_TOKEN environment variable.
SessionToken string `json:"session_token,omitempty"`
// MaxRetries is the maximum number of retries to make when a request
// fails. If not set, it will use 5 retries.
MaxRetries int `json:"max_retries,omitempty"`
// MaxWaitDur is the maximum amount of time to wait for a record to be
// propagated. If not set, it will use 1 minutes.
MaxWaitDur time.Duration `json:"max_wait_dur,omitempty"`
// WaitForPropagation if set to true, it will wait for the record to be
// propagated before returning.
WaitForPropagation bool `json:"wait_for_propagation,omitempty"`
// WaitForDeletePropagation enables not to wait for propogation when cleaning challenge records
// 0 (default) will use WaitForPropagation's value (for backwards compatibility)
// 1 will always wait, 2 will never wait
WaitForDeletePropagation waitForDeletePropagationOption `json:"wait_for_delete_propogation,omitempty"`
}
type waitForDeletePropagationOption int
const (
AlwaysWaitForDeletePropagation waitForDeletePropagationOption = 1
NeverWaitForDeletePropagation waitForDeletePropagationOption = 2
)
func (p *Provider) shouldWaitForDeletePropagation() bool {
switch p.WaitForDeletePropagation {
case AlwaysWaitForDeletePropagation:
return true
case NeverWaitForDeletePropagation:
return false
default:
return p.WaitForPropagation
}
}
// GetRecords lists all the records in the zone.
func (p *Provider) GetRecords(ctx context.Context, zone string) ([]libdns.Record, error) {
p.init(ctx)
zoneID, err := p.getZoneID(ctx, zone)
if err != nil {
return nil, err
}
records, err := p.getRecords(ctx, zoneID, zone)
if err != nil {
return nil, err
}
return records, nil
}
// AppendRecords adds records to the zone. It returns the records that were added.
func (p *Provider) AppendRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error) {
p.init(ctx)
zoneID, err := p.getZoneID(ctx, zone)
if err != nil {
return nil, err
}
var createdRecords []libdns.Record
for _, record := range records {
newRecord, err := p.createRecord(ctx, zoneID, record, zone)
if err != nil {
return nil, err
}
createdRecords = append(createdRecords, newRecord)
}
return createdRecords, nil
}
// DeleteRecords deletes the records from the zone. If a record does not have an ID,
// it will be looked up. It returns the records that were deleted.
func (p *Provider) DeleteRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error) {
p.init(ctx)
zoneID, err := p.getZoneID(ctx, zone)
if err != nil {
return nil, err
}
var deletedRecords []libdns.Record
for _, record := range records {
deletedRecord, err := p.deleteRecord(ctx, zoneID, record, zone)
if err != nil {
return nil, err
}
deletedRecords = append(deletedRecords, deletedRecord)
}
return deletedRecords, nil
}
// SetRecords sets the records in the zone, either by updating existing records
// or creating new ones. It returns the updated records.
func (p *Provider) SetRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error) {
p.init(ctx)
zoneID, err := p.getZoneID(ctx, zone)
if err != nil {
return nil, err
}
var updatedRecords []libdns.Record
for _, record := range records {
updatedRecord, err := p.updateRecord(ctx, zoneID, record, zone)
if err != nil {
return nil, err
}
updatedRecords = append(updatedRecords, updatedRecord)
}
return updatedRecords, nil
}
// Interface guards
var (
_ libdns.RecordGetter = (*Provider)(nil)
_ libdns.RecordAppender = (*Provider)(nil)
_ libdns.RecordSetter = (*Provider)(nil)
_ libdns.RecordDeleter = (*Provider)(nil)
)