Compare commits
No commits in common. "master" and "v2.0.2" have entirely different histories.
28
client.go
28
client.go
@ -2,7 +2,6 @@ package vultr
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
@ -28,6 +27,9 @@ func (p *Provider) getClient() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) getDNSEntries(ctx context.Context, domain string) ([]libdns.Record, error) {
|
func (p *Provider) getDNSEntries(ctx context.Context, domain string) ([]libdns.Record, error) {
|
||||||
|
p.client.mutex.Lock()
|
||||||
|
defer p.client.mutex.Unlock()
|
||||||
|
|
||||||
p.getClient()
|
p.getClient()
|
||||||
|
|
||||||
listOptions := &govultr.ListOptions{}
|
listOptions := &govultr.ListOptions{}
|
||||||
@ -80,17 +82,7 @@ func (p *Provider) removeDNSRecord(ctx context.Context, domain string, record li
|
|||||||
|
|
||||||
recordId, err := getRecordId(record)
|
recordId, err := getRecordId(record)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// try to get the ID from API if we don't have it
|
return record, err
|
||||||
records, err := p.getDNSEntries(ctx, domain)
|
|
||||||
if err != nil {
|
|
||||||
return record, fmt.Errorf("could not get record ID from API")
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, rec := range records {
|
|
||||||
if rec.RR().Name == record.RR().Name {
|
|
||||||
recordId = rec.(VultrRecord).ID
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = p.client.vultr.DomainRecord.Delete(ctx, domain, recordId)
|
err = p.client.vultr.DomainRecord.Delete(ctx, domain, recordId)
|
||||||
@ -109,17 +101,7 @@ func (p *Provider) updateDNSRecord(ctx context.Context, domain string, record li
|
|||||||
|
|
||||||
recordId, err := getRecordId(record)
|
recordId, err := getRecordId(record)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// try to get the ID from API if we don't have it
|
return record, err
|
||||||
records, err := p.getDNSEntries(ctx, domain)
|
|
||||||
if err != nil {
|
|
||||||
return record, fmt.Errorf("could not get record ID from API")
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, rec := range records {
|
|
||||||
if rec.RR().Data == record.RR().Data {
|
|
||||||
recordId = rec.(VultrRecord).ID
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
domainRecordReq := toDomainRecordReq(record)
|
domainRecordReq := toDomainRecordReq(record)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user