Implement libdns ZoneLister interface for provider
This commit is contained in:
parent
4be2894734
commit
76c18636cd
@ -25,6 +25,15 @@ func main() {
|
||||
|
||||
provider := vultr.Provider{APIToken: token}
|
||||
|
||||
zones, err := provider.ListZones(context.TODO())
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: %s\n", err.Error())
|
||||
}
|
||||
|
||||
for _, zone := range zones {
|
||||
fmt.Printf("%s\n", zone.Name)
|
||||
}
|
||||
|
||||
records, err := provider.GetRecords(context.TODO(), zone)
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: %s\n", err.Error())
|
||||
|
||||
32
client.go
32
client.go
@ -121,3 +121,35 @@ func (p *Provider) updateDNSRecord(ctx context.Context, domain string, record li
|
||||
|
||||
return record, nil
|
||||
}
|
||||
|
||||
func (p *Provider) getDNSZones(ctx context.Context) ([]libdns.Zone, error) {
|
||||
p.client.mutex.Lock()
|
||||
defer p.client.mutex.Unlock()
|
||||
|
||||
p.getClient()
|
||||
|
||||
listOptions := &govultr.ListOptions{}
|
||||
|
||||
var zones []libdns.Zone
|
||||
for {
|
||||
dns_zones, meta, _, err := p.client.vultr.Domain.List(ctx, listOptions)
|
||||
if err != nil {
|
||||
return zones, err
|
||||
}
|
||||
|
||||
for _, entry := range dns_zones {
|
||||
zone := libdns.Zone{
|
||||
Name: entry.Domain,
|
||||
}
|
||||
zones = append(zones, zone)
|
||||
}
|
||||
|
||||
if meta.Links.Next == "" {
|
||||
break
|
||||
}
|
||||
|
||||
listOptions.Cursor = meta.Links.Next
|
||||
}
|
||||
|
||||
return zones, nil
|
||||
}
|
||||
|
||||
11
provider.go
11
provider.go
@ -83,10 +83,21 @@ func (p *Provider) SetRecords(ctx context.Context, zone string, records []libdns
|
||||
return setRecords, nil
|
||||
}
|
||||
|
||||
func (p *Provider) ListZones(ctx context.Context) ([]libdns.Zone, error) {
|
||||
zones, err := p.getDNSZones(ctx)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return zones, nil
|
||||
}
|
||||
|
||||
// Interface guards
|
||||
var (
|
||||
_ libdns.RecordGetter = (*Provider)(nil)
|
||||
_ libdns.RecordAppender = (*Provider)(nil)
|
||||
_ libdns.RecordSetter = (*Provider)(nil)
|
||||
_ libdns.RecordDeleter = (*Provider)(nil)
|
||||
_ libdns.ZoneLister = (*Provider)(nil)
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user