From 8c8d08b72f665a09637392ff44cdd6331a9a1dba Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Thu, 19 Jan 2023 13:04:09 -0500 Subject: [PATCH] HOSTINGDE: Adopt diff2 in compatibility mode (#1890) --- providers/hostingde/auditrecords.go | 11 ++- providers/hostingde/hostingdeProvider.go | 109 +++++++++++++---------- 2 files changed, 72 insertions(+), 48 deletions(-) diff --git a/providers/hostingde/auditrecords.go b/providers/hostingde/auditrecords.go index ca0adb5a1..1d5baba0c 100644 --- a/providers/hostingde/auditrecords.go +++ b/providers/hostingde/auditrecords.go @@ -1,10 +1,17 @@ package hostingde -import "github.com/StackExchange/dnscontrol/v3/models" +import ( + "github.com/StackExchange/dnscontrol/v3/models" + "github.com/StackExchange/dnscontrol/v3/pkg/rejectif" +) // AuditRecords returns a list of errors corresponding to the records // that aren't supported by this provider. If all records are // supported, an empty list is returned. func AuditRecords(records []*models.RecordConfig) []error { - return nil + a := rejectif.Auditor{} + + a.Add("SRV", rejectif.SrvHasNullTarget) // Last verified 2023-01-19 + + return a.Audit(records) } diff --git a/providers/hostingde/hostingdeProvider.go b/providers/hostingde/hostingdeProvider.go index 93af9c6e8..34ca62f21 100644 --- a/providers/hostingde/hostingdeProvider.go +++ b/providers/hostingde/hostingdeProvider.go @@ -128,54 +128,71 @@ func (hp *hostingdeProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*m return nil, err } - var corrections []*models.Correction - if !diff2.EnableDiff2 || true { // Remove "|| true" when diff2 version arrives - - differ := diff.New(dc) - _, create, del, mod, err := differ.IncrementalDiff(records) - if err != nil { - return nil, err - } - - // NOPURGE - if dc.KeepUnknown { - del = []diff.Correlation{} - } - - msg := []string{} - for _, c := range append(del, append(create, mod...)...) { - msg = append(msg, c.String()) - } - - if len(create) == 0 && len(del) == 0 && len(mod) == 0 { - return nil, nil - } - - corrections = []*models.Correction{ - { - Msg: fmt.Sprintf("\n%s", strings.Join(msg, "\n")), - F: func() error { - for i := 0; i < 10; i++ { - err := hp.updateRecords(dc.Name, create, del, mod) - if err == nil { - return nil - } - // Code:10205 indicates the zone is currently blocked due to a running zone update. - if !strings.Contains(err.Error(), "Code:10205") { - return err - } - - // Exponential back-off retry. - // Base of 1.8 seemed like a good trade-off, retrying for approximately 45 seconds. - time.Sleep(time.Duration(math.Pow(1.8, float64(i))) * 100 * time.Millisecond) - } - return fmt.Errorf("retry exhaustion: zone blocked for 10 attempts") - }, - }, - } + var create, del, mod diff.Changeset + if !diff2.EnableDiff2 { + differ = diff.New(dc) + } else { + differ = diff.NewCompat(dc) + } + _, create, del, mod, err = differ.IncrementalDiff(records) + if err != nil { + return nil, err } - // Insert Future diff2 version here. + // NOPURGE + if dc.KeepUnknown { + del = []diff.Correlation{} + } + + msg := []string{} + for _, c := range append(del, append(create, mod...)...) { + msg = append(msg, c.String()) + } + + if len(create) == 0 && len(del) == 0 && len(mod) == 0 { + return nil, nil + } + + corrections = []*models.Correction{ + { + Msg: fmt.Sprintf("\n%s", strings.Join(msg, "\n")), + F: func() error { + for i := 0; i < 10; i++ { + err := hp.updateRecords(dc.Name, create, del, mod) + if err == nil { + return nil + } + // Code:10205 indicates the zone is currently blocked due to a running zone update. + if !strings.Contains(err.Error(), "Code:10205") { + return err + } + + // Exponential back-off retry. + // Base of 1.8 seemed like a good trade-off, retrying for approximately 45 seconds. + time.Sleep(time.Duration(math.Pow(1.8, float64(i))) * 100 * time.Millisecond) + } + return fmt.Errorf("retry exhaustion: zone blocked for 10 attempts") + }, + }, + } + + msg := []string{} + for _, c := range append(del, append(create, mod...)...) { + msg = append(msg, c.String()) + } + + if len(create) == 0 && len(del) == 0 && len(mod) == 0 { + return nil, nil + } + + corrections := []*models.Correction{ + { + Msg: fmt.Sprintf("\n%s", strings.Join(msg, "\n")), + F: func() error { + return hp.updateRecords(dc.Name, create, del, mod) + }, + }, + } return corrections, nil }