Skip to content

Commit

Permalink
nifcloud: Get zone info from dns01.FindZoneByFqdn (#1383)
Browse files Browse the repository at this point in the history
  • Loading branch information
kakakikikeke-fork authored Apr 8, 2021
1 parent ae7daa7 commit 2334340
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions providers/dns/nifcloud/nifcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) {
func (d *DNSProvider) Present(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)

err := d.changeRecord("CREATE", fqdn, value, domain, d.config.TTL)
err := d.changeRecord("CREATE", fqdn, value, d.config.TTL)
if err != nil {
return fmt.Errorf("nifcloud: %w", err)
}
Expand All @@ -110,7 +110,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
fqdn, value := dns01.GetRecord(domain, keyAuth)

err := d.changeRecord("DELETE", fqdn, value, domain, d.config.TTL)
err := d.changeRecord("DELETE", fqdn, value, d.config.TTL)
if err != nil {
return fmt.Errorf("nifcloud: %w", err)
}
Expand All @@ -123,7 +123,7 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
return d.config.PropagationTimeout, d.config.PollingInterval
}

func (d *DNSProvider) changeRecord(action, fqdn, value, domain string, ttl int) error {
func (d *DNSProvider) changeRecord(action, fqdn, value string, ttl int) error {
name := dns01.UnFqdn(fqdn)

reqParams := internal.ChangeResourceRecordSetsRequest{
Expand Down Expand Up @@ -152,17 +152,22 @@ func (d *DNSProvider) changeRecord(action, fqdn, value, domain string, ttl int)
},
}

resp, err := d.client.ChangeResourceRecordSets(domain, reqParams)
authZone, err := dns01.FindZoneByFqdn(fqdn)
if err != nil {
return fmt.Errorf("failed to change NIFCLOUD record set: %w", err)
return fmt.Errorf("failed to find zone: %w", err)
}

resp, err := d.client.ChangeResourceRecordSets(dns01.UnFqdn(authZone), reqParams)
if err != nil {
return fmt.Errorf("failed to change record set: %w", err)
}

statusID := resp.ChangeInfo.ID

return wait.For("nifcloud", 120*time.Second, 4*time.Second, func() (bool, error) {
resp, err := d.client.GetChange(statusID)
if err != nil {
return false, fmt.Errorf("failed to query NIFCLOUD DNS change status: %w", err)
return false, fmt.Errorf("failed to query change status: %w", err)
}
return resp.ChangeInfo.Status == "INSYNC", nil
})
Expand Down

0 comments on commit 2334340

Please sign in to comment.