-
Notifications
You must be signed in to change notification settings - Fork 6
/
client-get.go
50 lines (45 loc) · 1.52 KB
/
client-get.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
package googleclouddns
import (
"context"
"github.com/libdns/libdns"
"google.golang.org/api/dns/v1"
)
// getCloudDNSRecords returns all the records for the specified zone. It breaks up a single Google Record
// with multiple Values into separate libdns.Records.
func (p *Provider) getCloudDNSRecords(ctx context.Context, zone string) ([]libdns.Record, error) {
if err := p.newService(ctx); err != nil {
return nil, err
}
gcdZone, err := p.getCloudDNSZone(zone)
if err != nil {
return nil, err
}
rrsReq := p.service.ResourceRecordSets.List(p.Project, gcdZone)
records := make([]libdns.Record, 0)
if err := rrsReq.Pages(ctx, func(page *dns.ResourceRecordSetsListResponse) error {
for _, googleRecord := range page.Rrsets {
records = append(records, convertToLibDNS(googleRecord, zone)...)
}
return nil
}); err != nil {
return nil, err
}
return records, nil
}
// getCloudDNSRecord returns the record for the specified zone, name, and type. It breaks up a single Cloud DNS Record
// with multiple Values into separate libdns.Records.
func (p *Provider) getCloudDNSRecord(ctx context.Context, zone, name, recordType string) (libdnsRecords, error) {
if err := p.newService(ctx); err != nil {
return nil, err
}
gcdZone, err := p.getCloudDNSZone(zone)
if err != nil {
return nil, err
}
fullName := libdns.AbsoluteName(name, zone)
rrs, err := p.service.ResourceRecordSets.Get(p.Project, gcdZone, fullName, recordType).Context(ctx).Do()
if err != nil {
return nil, err
}
return convertToLibDNS(rrs, zone), nil
}