From 572f2ce28cc61bb15722e7ebd05b03e58822e127 Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Wed, 18 Jan 2023 12:34:45 -0500 Subject: [PATCH] NETCUP: Adopt diff2 in compatibility mode (#1895) --- integrationTest/integration_test.go | 5 ++ providers/netcup/netcupProvider.go | 87 ++++++++++++++--------------- 2 files changed, 48 insertions(+), 44 deletions(-) diff --git a/integrationTest/integration_test.go b/integrationTest/integration_test.go index 11c23de18..6b6bdd829 100644 --- a/integrationTest/integration_test.go +++ b/integrationTest/integration_test.go @@ -693,6 +693,11 @@ func makeTests(t *testing.T) []*TestGroup { tc("Change it", a("@", "1.2.3.4")), tc("Add another", a("@", "1.2.3.4"), a("www", "1.2.3.4")), tc("Add another(same name)", a("@", "1.2.3.4"), a("www", "1.2.3.4"), a("www", "5.6.7.8")), + ), + + testgroup("Protocol-TTL", + not("NETCUP"), // NETCUP does not support TTLs. + tc("Start", a("@", "1.2.3.4"), a("www", "1.2.3.4"), a("www", "5.6.7.8")), tc("Change a ttl", ttl(a("@", "1.2.3.4"), 1000), a("www", "1.2.3.4"), a("www", "5.6.7.8")), tc("Change single target from set", ttl(a("@", "1.2.3.4"), 1000), a("www", "2.2.2.2"), a("www", "5.6.7.8")), tc("Change all ttls", ttl(a("@", "1.2.3.4"), 500), ttl(a("www", "2.2.2.2"), 400), ttl(a("www", "5.6.7.8"), 400)), diff --git a/providers/netcup/netcupProvider.go b/providers/netcup/netcupProvider.go index 6de9921bf..961e09af8 100644 --- a/providers/netcup/netcupProvider.go +++ b/providers/netcup/netcupProvider.go @@ -102,53 +102,52 @@ func (api *netcupProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*mod // txtutil.SplitSingleLongTxt(dc.Records) // Autosplit long TXT records var corrections []*models.Correction - if !diff2.EnableDiff2 || true { // Remove "|| true" when diff2 version arrives - + var create, del, modify diff.Changeset + if !diff2.EnableDiff2 { differ := diff.New(dc) - _, create, del, modify, err := differ.IncrementalDiff(existingRecords) - if err != nil { - return nil, err - } - - // Deletes first so changing type works etc. - for _, m := range del { - req := m.Existing.Original.(*record) - corr := &models.Correction{ - Msg: fmt.Sprintf("%s, Netcup ID: %s", m.String(), req.ID), - F: func() error { - return api.deleteRecord(domain, req) - }, - } - corrections = append(corrections, corr) - } - - for _, m := range create { - req := fromRecordConfig(m.Desired) - corr := &models.Correction{ - Msg: m.String(), - F: func() error { - return api.createRecord(domain, req) - }, - } - corrections = append(corrections, corr) - } - for _, m := range modify { - id := m.Existing.Original.(*record).ID - req := fromRecordConfig(m.Desired) - req.ID = id - corr := &models.Correction{ - Msg: fmt.Sprintf("%s, Netcup ID: %s: ", m.String(), id), - F: func() error { - return api.modifyRecord(domain, req) - }, - } - corrections = append(corrections, corr) - } - - return corrections, nil + _, create, del, modify, err = differ.IncrementalDiff(existingRecords) + } else { + differ := diff.NewCompat(dc) + _, create, del, modify, err = differ.IncrementalDiff(existingRecords) + } + if err != nil { + return nil, err } - // Insert Future diff2 version here. + // Deletes first so changing type works etc. + for _, m := range del { + req := m.Existing.Original.(*record) + corr := &models.Correction{ + Msg: fmt.Sprintf("%s, Netcup ID: %s", m.String(), req.ID), + F: func() error { + return api.deleteRecord(domain, req) + }, + } + corrections = append(corrections, corr) + } + + for _, m := range create { + req := fromRecordConfig(m.Desired) + corr := &models.Correction{ + Msg: m.String(), + F: func() error { + return api.createRecord(domain, req) + }, + } + corrections = append(corrections, corr) + } + for _, m := range modify { + id := m.Existing.Original.(*record).ID + req := fromRecordConfig(m.Desired) + req.ID = id + corr := &models.Correction{ + Msg: fmt.Sprintf("%s, Netcup ID: %s: ", m.String(), id), + F: func() error { + return api.modifyRecord(domain, req) + }, + } + corrections = append(corrections, corr) + } return corrections, nil }