1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

refactor corrections

This commit is contained in:
Tom Limoncelli
2023-03-03 16:23:46 -05:00
parent 91242d54dc
commit 4fa191df0c
5 changed files with 18 additions and 5 deletions

View File

@ -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

View File

@ -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))
}

View File

@ -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.

View File

@ -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
}

View File

@ -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 {