From 5822de269c12e73ccae7761ac8f1bae6ddbe6cbc Mon Sep 17 00:00:00 2001 From: Jonathan Remy Date: Fri, 1 Aug 2025 15:40:34 +0200 Subject: [PATCH] feat(domain): add WaitForDNSRecordNotExist waiter --- api/domain/v2beta1/domain_utils.go | 49 ++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/api/domain/v2beta1/domain_utils.go b/api/domain/v2beta1/domain_utils.go index 868739def..72fa6fbed 100644 --- a/api/domain/v2beta1/domain_utils.go +++ b/api/domain/v2beta1/domain_utils.go @@ -137,6 +137,55 @@ func (s *API) WaitForDNSRecordExist( return dns.(*Record), nil } +// WaitForDNSRecordNotExistRequest is used by WaitForDNSRecordNotExist method. +type WaitForDNSRecordNotExistRequest struct { + DNSZone string + RecordName string + RecordType RecordType + Timeout *time.Duration + RetryInterval *time.Duration +} + +func (s *API) WaitForDNSRecordNotExist( + req *WaitForDNSRecordNotExistRequest, + opts ...scw.RequestOption, +) error { + timeout := defaultTimeout + if req.Timeout != nil { + timeout = *req.Timeout + } + retryInterval := defaultRetryInterval + if req.RetryInterval != nil { + retryInterval = *req.RetryInterval + } + + _, err := async.WaitSync(&async.WaitSyncConfig{ + Get: func() (any, bool, error) { + DNSRecords, err := s.ListDNSZoneRecords(&ListDNSZoneRecordsRequest{ + Name: req.RecordName, + Type: req.RecordType, + DNSZone: req.DNSZone, + }, opts...) + if err != nil { + return nil, false, err + } + + if DNSRecords.TotalCount == 0 { + return nil, true, nil + } + + return nil, false, nil + }, + Timeout: timeout, + IntervalStrategy: async.LinearIntervalStrategy(retryInterval), + }) + if err != nil { + return errors.Wrap(err, "waiting for DNS record to not exist failed") + } + + return nil +} + // WaitForOrderDomainRequest is used by WaitForOrderDomain method. type WaitForOrderDomainRequest struct { Domain string