diff --git a/commands/previewPush.go b/commands/previewPush.go index 6eee2cac8..b00700c0d 100644 --- a/commands/previewPush.go +++ b/commands/previewPush.go @@ -2,17 +2,19 @@ package commands import ( "fmt" - "golang.org/x/net/idna" "log" "os" "strings" + "golang.org/x/net/idna" + "github.com/StackExchange/dnscontrol/v3/models" "github.com/StackExchange/dnscontrol/v3/pkg/credsfile" "github.com/StackExchange/dnscontrol/v3/pkg/nameservers" "github.com/StackExchange/dnscontrol/v3/pkg/normalize" "github.com/StackExchange/dnscontrol/v3/pkg/notifications" "github.com/StackExchange/dnscontrol/v3/pkg/printer" + "github.com/StackExchange/dnscontrol/v3/pkg/zonerecs" "github.com/StackExchange/dnscontrol/v3/providers" "github.com/urfave/cli/v2" "golang.org/x/exp/slices" @@ -188,7 +190,7 @@ DomainLoop: /// This is where we should audit? - corrections, err := provider.Driver.GetDomainCorrections(dc) + corrections, err := zonerecs.CorrectZoneRecords(provider.Driver, dc) out.EndProvider(len(corrections), err) if err != nil { anyErrors = true diff --git a/integrationTest/integration_test.go b/integrationTest/integration_test.go index 694d05284..1a6fa6574 100644 --- a/integrationTest/integration_test.go +++ b/integrationTest/integration_test.go @@ -15,6 +15,7 @@ import ( "github.com/StackExchange/dnscontrol/v3/pkg/diff2" "github.com/StackExchange/dnscontrol/v3/pkg/nameservers" "github.com/StackExchange/dnscontrol/v3/pkg/normalize" + "github.com/StackExchange/dnscontrol/v3/pkg/zonerecs" "github.com/StackExchange/dnscontrol/v3/providers" _ "github.com/StackExchange/dnscontrol/v3/providers/_all" "github.com/StackExchange/dnscontrol/v3/providers/cloudflare" @@ -211,7 +212,7 @@ func makeChanges(t *testing.T, prv providers.DNSServiceProvider, dc *models.Doma } // get and run corrections for first time - corrections, err := prv.GetDomainCorrections(dom) + corrections, err := zonerecs.CorrectZoneRecords(prv, dom) if err != nil { t.Fatal(fmt.Errorf("runTests: %w", err)) } diff --git a/models/provider.go b/models/provider.go index 9a254231c..9eb9980d5 100644 --- a/models/provider.go +++ b/models/provider.go @@ -4,7 +4,8 @@ package models type DNSProvider interface { GetNameservers(domain string) ([]*Nameserver, error) GetZoneRecords(domain string) (Records, error) - GetDomainCorrections(dc *DomainConfig) ([]*Correction, error) + GetDomainCorrections(dc *DomainConfig) ([]*Correction, error) // Legacy + GetZoneRecordsCorrections(dc *DomainConfig, existing Records) ([]*Correction, error) } // Registrar is an interface for Registrar plug-ins. diff --git a/pkg/acme/acme.go b/pkg/acme/acme.go index c76b7adb9..7316658e2 100644 --- a/pkg/acme/acme.go +++ b/pkg/acme/acme.go @@ -15,6 +15,7 @@ import ( "github.com/StackExchange/dnscontrol/v3/models" "github.com/StackExchange/dnscontrol/v3/pkg/nameservers" "github.com/StackExchange/dnscontrol/v3/pkg/notifications" + "github.com/StackExchange/dnscontrol/v3/pkg/zonerecs" "github.com/go-acme/lego/certcrypto" "github.com/go-acme/lego/certificate" "github.com/go-acme/lego/challenge" @@ -275,7 +276,7 @@ func (c *certManager) getCorrections(d *models.DomainConfig) ([]*models.Correcti if err != nil { return nil, err } - corrections, err := p.Driver.GetDomainCorrections(dc) + corrections, err := zonerecs.CorrectZoneRecords(p.Driver, dc) if err != nil { return nil, err } diff --git a/providers/gcloud/gcloudProvider.go b/providers/gcloud/gcloudProvider.go index 891094d45..45d3aad42 100644 --- a/providers/gcloud/gcloudProvider.go +++ b/providers/gcloud/gcloudProvider.go @@ -205,6 +205,14 @@ func (g *gcloudProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*model models.PostProcessRecords(existingRecords) txtutil.SplitSingleLongTxt(dc.Records) // Autosplit long TXT records + return GetZoneRecordsCorrections(dc, existingRecords) +} + +func (g *gcloudProvider) GetZoneRecordsCorrections(dc *models.DomainConfig, existingRecords models.Records) ([]*models.Correction, error) { + + // oldRRs := + // zoneName := + // first collect keys that have changed var differ diff.Differ if !diff2.EnableDiff2 {