Initial code commit
This commit is contained in:
34
internal/providers/namecheap/dns.go
Normal file
34
internal/providers/namecheap/dns.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package namecheap
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (c *Client) WaitForDNSPropagation(domain, subdomain, expectedIP string, timeout time.Duration) error {
|
||||
deadline := time.Now().Add(timeout)
|
||||
backoff := 5 * time.Second
|
||||
maxBackoff := 80 * time.Second
|
||||
|
||||
for {
|
||||
if time.Now().After(deadline) {
|
||||
return fmt.Errorf("timeout waiting for DNS propagation")
|
||||
}
|
||||
|
||||
records, err := c.ListDNSRecords(domain)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to check DNS records: %w", err)
|
||||
}
|
||||
|
||||
for _, record := range records {
|
||||
if record.Name == subdomain && record.Address == expectedIP {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
time.Sleep(backoff)
|
||||
if backoff < maxBackoff {
|
||||
backoff *= 2
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user