mirror of
https://github.com/vxcontrol/external-dns.git
synced 2026-07-19 18:23:33 -04:00
Switch to API v2
This commit is contained in:
@@ -11,12 +11,10 @@ import (
|
||||
"github.com/juju/ratelimit"
|
||||
"github.com/rancher/external-dns/providers"
|
||||
"github.com/rancher/external-dns/utils"
|
||||
api "github.com/weppos/go-dnsimple/dnsimple"
|
||||
)
|
||||
|
||||
type DNSimpleProvider struct {
|
||||
client *api.Client
|
||||
client2 *dnsimple.Client
|
||||
client *dnsimple.Client
|
||||
accountID string
|
||||
root string
|
||||
limiter *ratelimit.Bucket
|
||||
@@ -27,14 +25,10 @@ func init() {
|
||||
}
|
||||
|
||||
func (d *DNSimpleProvider) Init(rootDomainName string) error {
|
||||
var email, apiToken, oauthToken string
|
||||
var oauthToken string
|
||||
|
||||
if email = os.Getenv("DNSIMPLE_EMAIL"); len(email) == 0 {
|
||||
return fmt.Errorf("DNSIMPLE_EMAIL is not set")
|
||||
}
|
||||
|
||||
if apiToken = os.Getenv("DNSIMPLE_TOKEN"); len(apiToken) == 0 {
|
||||
return fmt.Errorf("DNSIMPLE_TOKEN is not set")
|
||||
if len(os.Getenv("DNSIMPLE_EMAIL")) > 0 {
|
||||
return fmt.Errorf("DNSimple API v2 requires an account identifier and the new OAuth token. Please upgrade your configuration.")
|
||||
}
|
||||
|
||||
if oauthToken = os.Getenv("DNSIMPLE_TOKEN"); len(oauthToken) == 0 {
|
||||
@@ -42,11 +36,10 @@ func (d *DNSimpleProvider) Init(rootDomainName string) error {
|
||||
}
|
||||
|
||||
d.root = utils.UnFqdn(rootDomainName)
|
||||
d.client = api.NewClient(apiToken, email)
|
||||
d.client2 = dnsimple.NewClient(dnsimple.NewOauthTokenCredentials(oauthToken))
|
||||
d.client = dnsimple.NewClient(dnsimple.NewOauthTokenCredentials(oauthToken))
|
||||
d.limiter = ratelimit.NewBucketWithRate(1.5, 5)
|
||||
|
||||
whoamiResponse, err := d.client2.Identity.Whoami()
|
||||
whoamiResponse, err := d.client.Identity.Whoami()
|
||||
if err != nil {
|
||||
return fmt.Errorf("DNSimple Authentication failed: %v", err)
|
||||
}
|
||||
@@ -55,7 +48,7 @@ func (d *DNSimpleProvider) Init(rootDomainName string) error {
|
||||
}
|
||||
d.accountID = strconv.Itoa(whoamiResponse.Data.Account.ID)
|
||||
|
||||
_, err = d.client2.Zones.GetZone(d.accountID, d.root)
|
||||
_, err = d.client.Zones.GetZone(d.accountID, d.root)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to get zone for '%s': %v", d.root)
|
||||
}
|
||||
@@ -70,7 +63,7 @@ func (*DNSimpleProvider) GetName() string {
|
||||
|
||||
func (d *DNSimpleProvider) HealthCheck() error {
|
||||
d.limiter.Wait(1)
|
||||
_, err := d.client2.Identity.Whoami()
|
||||
_, err := d.client.Identity.Whoami()
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -89,7 +82,7 @@ func (d *DNSimpleProvider) AddRecord(record utils.DnsRecord) error {
|
||||
Content: rec,
|
||||
}
|
||||
d.limiter.Wait(1)
|
||||
_, err := d.client2.Zones.CreateRecord(d.accountID, d.root, recordInput)
|
||||
_, err := d.client.Zones.CreateRecord(d.accountID, d.root, recordInput)
|
||||
if err != nil {
|
||||
return fmt.Errorf("DNSimple API call has failed: %v", err)
|
||||
}
|
||||
@@ -102,7 +95,7 @@ func (d *DNSimpleProvider) findRecords(record utils.DnsRecord) ([]dnsimple.ZoneR
|
||||
var zoneRecords []dnsimple.ZoneRecord
|
||||
|
||||
d.limiter.Wait(1)
|
||||
recordsResponse, err := d.client2.Zones.ListRecords(d.accountID, d.root, nil)
|
||||
recordsResponse, err := d.client.Zones.ListRecords(d.accountID, d.root, nil)
|
||||
if err != nil {
|
||||
return zoneRecords, fmt.Errorf("DNSimple API call has failed: %v", err)
|
||||
}
|
||||
@@ -134,7 +127,7 @@ func (d *DNSimpleProvider) RemoveRecord(record utils.DnsRecord) error {
|
||||
|
||||
for _, zoneRecord := range zoneRecords {
|
||||
d.limiter.Wait(1)
|
||||
_, err := d.client2.Zones.DeleteRecord(d.accountID, d.root, zoneRecord.ID)
|
||||
_, err := d.client.Zones.DeleteRecord(d.accountID, d.root, zoneRecord.ID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("DNSimple API call has failed: %v", err)
|
||||
}
|
||||
@@ -147,7 +140,7 @@ func (d *DNSimpleProvider) GetRecords() ([]utils.DnsRecord, error) {
|
||||
var records []utils.DnsRecord
|
||||
|
||||
d.limiter.Wait(1)
|
||||
recordsResponse, err := d.client2.Zones.ListRecords(d.accountID, d.root, nil)
|
||||
recordsResponse, err := d.client.Zones.ListRecords(d.accountID, d.root, nil)
|
||||
if err != nil {
|
||||
return records, fmt.Errorf("DNSimple API call has failed: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user