From 4f935be6081aca4547b08ff880c6285c2e961278 Mon Sep 17 00:00:00 2001 From: Tom Limoncelli Date: Sun, 12 Nov 2023 18:10:13 -0500 Subject: [PATCH] Add debug printfs --- commands/getZones.go | 3 +++ integrationTest/integration_test.go | 2 +- models/record.go | 6 ++++-- pkg/diff2/compareconfig.go | 4 ++++ providers/gandiv5/convert.go | 27 ++++++++++++++++++++++----- 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/commands/getZones.go b/commands/getZones.go index bf028c9bf..821674675 100644 --- a/commands/getZones.go +++ b/commands/getZones.go @@ -9,6 +9,7 @@ import ( "github.com/StackExchange/dnscontrol/v4/models" "github.com/StackExchange/dnscontrol/v4/pkg/credsfile" "github.com/StackExchange/dnscontrol/v4/pkg/prettyzone" + "github.com/StackExchange/dnscontrol/v4/pkg/printer" "github.com/StackExchange/dnscontrol/v4/providers" "github.com/urfave/cli/v2" ) @@ -351,7 +352,9 @@ func formatDsl(zonename string, rec *models.RecordConfig, defaultTTL uint32) str case "TLSA": target = fmt.Sprintf(`%d, %d, %d, "%s"`, rec.TlsaUsage, rec.TlsaSelector, rec.TlsaMatchingType, rec.GetTargetField()) case "TXT": + printer.Printf("DEBUG: gz raw s=%s q=%q\n", rec.GetTargetTXTJoined(), rec.GetTargetTXTJoined()) target = jsonQuoted(rec.GetTargetTXTJoined()) + printer.Printf("DEBUG: gz qtd s=%s q=%q\n", target, target) // TODO(tlim): If this is an SPF record, generate a SPF_BUILDER(). case "NS": // NS records at the apex should be NAMESERVER() records. diff --git a/integrationTest/integration_test.go b/integrationTest/integration_test.go index f915bfb7b..6940bd6f7 100644 --- a/integrationTest/integration_test.go +++ b/integrationTest/integration_test.go @@ -1088,7 +1088,7 @@ func makeTests(t *testing.T) []*TestGroup { tc("TXT with 1 backtick", txt("foobt", "blah`blah")), tc("TXT with 1 double-quotes", txt("foodq", `quo"te`)), tc("TXT with 2 double-quotes", txt("foodqs", `q"uo"te`)), - //tc("TXT with 1 backslash", txt("fooosbs", `back\slash`)), + tc("TXT with 1 backslash", txt("fooosbs", `back\slash`)), clear(), tc("TXT interior ws", txt("foosp", "with spaces")), diff --git a/models/record.go b/models/record.go index a69d69a64..71da6c2fa 100644 --- a/models/record.go +++ b/models/record.go @@ -360,8 +360,10 @@ func (rc *RecordConfig) ToDiffable(extraMaps ...map[string]string) string { // This replaces ToDiff() func (rc *RecordConfig) ToComparableNoTTL() string { if rc.Type == "TXT" { - fmt.Fprintf(os.Stdout, "DEBUG: ToComNoTTL txts=%s q=%q\n", rc.target, rc.target) - return txtutil.EncodeQuoted(rc.target) + fmt.Fprintf(os.Stdout, "DEBUG: ToComNoTTL raw txts=%s q=%q\n", rc.target, rc.target) + r := txtutil.EncodeQuoted(rc.target) + fmt.Fprintf(os.Stdout, "DEBUG: ToComNoTTL cmp txts=%s q=%q\n", r, r) + return r } return rc.GetTargetCombined() } diff --git a/pkg/diff2/compareconfig.go b/pkg/diff2/compareconfig.go index 0b75d32a2..b238c26b0 100644 --- a/pkg/diff2/compareconfig.go +++ b/pkg/diff2/compareconfig.go @@ -7,6 +7,7 @@ import ( "github.com/StackExchange/dnscontrol/v4/models" "github.com/StackExchange/dnscontrol/v4/pkg/prettyzone" + "github.com/StackExchange/dnscontrol/v4/pkg/printer" ) /* @@ -103,7 +104,9 @@ func NewCompareConfig(origin string, existing, desired models.Records, compFn Co labelMap: map[string]bool{}, keyMap: map[models.RecordKey]bool{}, } + printer.Printf("DEBUG: EXISTING:\n") cc.addRecords(existing, true) // Must be called first so that CNAME manipulations happen in the correct order. + printer.Printf("DEBUG: DESIRED:\n") cc.addRecords(desired, false) cc.verifyCNAMEAssertions() sort.Slice(cc.ldata, func(i, j int) bool { @@ -215,6 +218,7 @@ func mkCompareBlobs(rc *models.RecordConfig, f func(*models.RecordConfig) string } } + // We do this to save memory. This assures the first return value uses the same memory as the second. lenWithoutTTL := len(comp) compFull := comp + fmt.Sprintf(" ttl=%d", rc.TTL) diff --git a/providers/gandiv5/convert.go b/providers/gandiv5/convert.go index 229ac0c3f..0daa0c34d 100644 --- a/providers/gandiv5/convert.go +++ b/providers/gandiv5/convert.go @@ -7,6 +7,7 @@ import ( "github.com/StackExchange/dnscontrol/v4/models" "github.com/StackExchange/dnscontrol/v4/pkg/printer" + "github.com/StackExchange/dnscontrol/v4/pkg/txtutil" "github.com/go-gandi/go-gandi/livedns" ) @@ -30,7 +31,15 @@ func nativeToRecords(n livedns.DomainRecord, origin string) (rcs []*models.Recor rc.Type = "ALIAS" err = rc.SetTarget(value) case "TXT": - err = rc.SetTargetTXTfromRFC1035Quoted(value) + //err = rc.SetTargetTXTfromRFC1035Quoted(value) + t := value + printer.Printf("DEBUG gandi txt inbounds=%s q=%q\n", t, t) + td, err := txtutil.ParseQuoted(t) + if err != nil { + return nil, err + } + printer.Printf("DEBUG gandi txt decodeds=%s q=%q\n", td, td) + _ = rc.SetTargetTXT(td) default: err = rc.PopulateFromString(rtype, value, origin) } @@ -60,13 +69,21 @@ func recordsToNative(rcs []*models.RecordConfig, origin string) []livedns.Domain key := r.Key() if zr, ok := keys[key]; !ok { + var vals []string // Allocate a new ZoneRecord: zr := livedns.DomainRecord{ - RrsetType: r.Type, - RrsetTTL: int(r.TTL), - RrsetName: label, - RrsetValues: []string{r.GetTargetCombined()}, + RrsetType: r.Type, + RrsetTTL: int(r.TTL), + RrsetName: label, + //RrsetValues: []string{r.GetTargetCombined()}, } + if r.Type == "TXT" { + vals = r.GetTargetTXTChunked255() + printer.Printf("DEBUG: gandi TXT outbounds=%s q=%q\n", vals, vals) + } else { + vals = []string{r.GetTargetCombined()} + } + zr.RrsetValues = vals keys[key] = &zr } else { zr.RrsetValues = append(zr.RrsetValues, r.GetTargetCombined())