-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprovider.go
69 lines (60 loc) · 1.79 KB
/
provider.go
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
package tencentcloud
import (
"context"
"github.com/libdns/libdns"
)
// Provider is a libdns provider for Tencent Cloud DNS
type Provider struct {
// SecretId is the secret ID for Tencent Cloud DNS
SecretId string
// SecretKey is the secret key for Tencent Cloud DNS
SecretKey string
}
// GetRecords gets the records for a zone
func (p *Provider) GetRecords(ctx context.Context, zone string) ([]libdns.Record, error) {
return p.describeRecordList(ctx, zone)
}
// AppendRecords appends records to a zone
func (p *Provider) AppendRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error) {
for k, record := range records {
if id, err := p.createRecord(ctx, zone, record); err != nil {
return records, err
} else {
records[k].ID = id
}
}
return records, nil
}
// SetRecords sets the records for a zone
func (p *Provider) SetRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error) {
for i, record := range records {
if record.ID == "" {
newRecord, err := p.AppendRecords(ctx, zone, []libdns.Record{record})
if err != nil {
return nil, err
}
records[i].ID = newRecord[0].ID
} else {
if err := p.modifyRecord(ctx, zone, record); err != nil {
return nil, err
}
}
}
return records, nil
}
// DeleteRecords deletes the records for a zone
func (p *Provider) DeleteRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error) {
for _, record := range records {
if err := p.deleteRecord(ctx, zone, record); err != nil {
return nil, err
}
}
return records, nil
}
// Interface guards
var (
_ libdns.RecordGetter = (*Provider)(nil)
_ libdns.RecordAppender = (*Provider)(nil)
_ libdns.RecordSetter = (*Provider)(nil)
_ libdns.RecordDeleter = (*Provider)(nil)
)