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

gandi works

This commit is contained in:
Tom Limoncelli
2023-11-12 19:33:31 -05:00
parent fb164b410f
commit e112e37818
6 changed files with 34 additions and 31 deletions

View File

@ -1088,8 +1088,8 @@ func makeTests(t *testing.T) []*TestGroup {
tc("TXT with 1 backtick", txt("foobt", "blah`blah")), tc("TXT with 1 backtick", txt("foobt", "blah`blah")),
tc("TXT with 1 double-quotes", txt("foodq", `quo"te`)), tc("TXT with 1 double-quotes", txt("foodq", `quo"te`)),
tc("TXT with 2 double-quotes", txt("foodqs", `q"uo"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(), //clear(),
tc("TXT interior ws", txt("foosp", "with spaces")), tc("TXT interior ws", txt("foosp", "with spaces")),
tc("TXT trailing ws", txt("foows1", "with space at end ")), tc("TXT trailing ws", txt("foows1", "with space at end ")),
@ -1099,7 +1099,7 @@ func makeTests(t *testing.T) []*TestGroup {
//clear(), //clear(),
// TODO(tlim): Re-add this when we fix the RFC1035 escaped-quotes issue. // TODO(tlim): Re-add this when we fix the RFC1035 escaped-quotes issue.
//tc("Create TXT with frequently escaped characters", txt("fooex", `!^.*$@#%^&()([][{}{<></:;-_=+\`)), tc("Create TXT with frequently escaped characters", txt("fooex", `!^.*$@#%^&()([][{}{<></:;-_=+\`)),
clear(), clear(),
), ),

View File

@ -4,7 +4,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"log" "log"
"os"
"sort" "sort"
"strings" "strings"
@ -324,7 +323,7 @@ func (rc *RecordConfig) ToDiffable(extraMaps ...map[string]string) string {
content = fmt.Sprintf("%s %v %d %d %d %d ttl=%d", rc.target, rc.SoaMbox, rc.SoaRefresh, rc.SoaRetry, rc.SoaExpire, rc.SoaMinttl, rc.TTL) content = fmt.Sprintf("%s %v %d %d %d %d ttl=%d", rc.target, rc.SoaMbox, rc.SoaRefresh, rc.SoaRetry, rc.SoaExpire, rc.SoaMinttl, rc.TTL)
// SoaSerial is not used in comparison // SoaSerial is not used in comparison
case "TXT": case "TXT":
fmt.Fprintf(os.Stdout, "DEBUG: XXXXXXXXXXXXXXXX\n") //fmt.Fprintf(os.Stdout, "DEBUG: XXXXXXXXXXXXXXXX\n")
t := rc.GetTargetField() t := rc.GetTargetField()
te := txtutil.EncodeQuoted(t) te := txtutil.EncodeQuoted(t)
content = fmt.Sprintf("%v ttl=%d", te, rc.TTL) content = fmt.Sprintf("%v ttl=%d", te, rc.TTL)
@ -360,9 +359,9 @@ func (rc *RecordConfig) ToDiffable(extraMaps ...map[string]string) string {
// This replaces ToDiff() // This replaces ToDiff()
func (rc *RecordConfig) ToComparableNoTTL() string { func (rc *RecordConfig) ToComparableNoTTL() string {
if rc.Type == "TXT" { if rc.Type == "TXT" {
fmt.Fprintf(os.Stdout, "DEBUG: ToComNoTTL raw txts=%s q=%q\n", rc.target, rc.target) //fmt.Fprintf(os.Stdout, "DEBUG: ToComNoTTL raw txts=%s q=%q\n", rc.target, rc.target)
r := txtutil.EncodeQuoted(rc.target) r := txtutil.EncodeQuoted(rc.target)
fmt.Fprintf(os.Stdout, "DEBUG: ToComNoTTL cmp txts=%s q=%q\n", r, r) //fmt.Fprintf(os.Stdout, "DEBUG: ToComNoTTL cmp txts=%s q=%q\n", r, r)
return r return r
} }
return rc.GetTargetCombined() return rc.GetTargetCombined()

View File

@ -45,7 +45,10 @@ func (rc *RecordConfig) GetTargetCombined() string {
} }
} }
if rc.Type == "SOA" { switch rc.Type {
case "TXT":
return rc.target
case "SOA":
return fmt.Sprintf("%s %v %d %d %d %d %d", rc.target, rc.SoaMbox, rc.SoaSerial, rc.SoaRefresh, rc.SoaRetry, rc.SoaExpire, rc.SoaMinttl) return fmt.Sprintf("%s %v %d %d %d %d %d", rc.target, rc.SoaMbox, rc.SoaSerial, rc.SoaRefresh, rc.SoaRetry, rc.SoaExpire, rc.SoaMinttl)
} }

View File

@ -7,7 +7,6 @@ import (
"github.com/StackExchange/dnscontrol/v4/models" "github.com/StackExchange/dnscontrol/v4/models"
"github.com/StackExchange/dnscontrol/v4/pkg/prettyzone" "github.com/StackExchange/dnscontrol/v4/pkg/prettyzone"
"github.com/StackExchange/dnscontrol/v4/pkg/printer"
) )
/* /*
@ -104,9 +103,9 @@ func NewCompareConfig(origin string, existing, desired models.Records, compFn Co
labelMap: map[string]bool{}, labelMap: map[string]bool{},
keyMap: map[models.RecordKey]bool{}, keyMap: map[models.RecordKey]bool{},
} }
printer.Printf("DEBUG: EXISTING:\n") //printer.Printf("DEBUG: EXISTING:\n")
cc.addRecords(existing, true) // Must be called first so that CNAME manipulations happen in the correct order. cc.addRecords(existing, true) // Must be called first so that CNAME manipulations happen in the correct order.
printer.Printf("DEBUG: DESIRED:\n") //printer.Printf("DEBUG: DESIRED:\n")
cc.addRecords(desired, false) cc.addRecords(desired, false)
cc.verifyCNAMEAssertions() cc.verifyCNAMEAssertions()
sort.Slice(cc.ldata, func(i, j int) bool { sort.Slice(cc.ldata, func(i, j int) bool {

View File

@ -33,13 +33,17 @@ func nativeToRecords(n livedns.DomainRecord, origin string) (rcs []*models.Recor
case "TXT": case "TXT":
//err = rc.SetTargetTXTfromRFC1035Quoted(value) //err = rc.SetTargetTXTfromRFC1035Quoted(value)
t := value t := value
printer.Printf("DEBUG gandi txt inbounds=%s q=%q\n", t, t) //printer.Printf("DEBUG gandi txt inbounds=%s q=%q\n", t, t)
td, err := txtutil.ParseQuoted(t) td, err := txtutil.ParseQuoted(t)
if err != nil { if err != nil {
return nil, err return nil, err
} }
printer.Printf("DEBUG gandi txt decodeds=%s q=%q\n", td, td) //td := t
_ = rc.SetTargetTXT(td) //printer.Printf("DEBUG gandi txt decodeds=%s q=%q\n", td, td)
err = rc.SetTargetTXT(td)
if err != nil {
return nil, err
}
default: default:
err = rc.PopulateFromString(rtype, value, origin) err = rc.PopulateFromString(rtype, value, origin)
} }
@ -68,25 +72,27 @@ func recordsToNative(rcs []*models.RecordConfig, origin string) []livedns.Domain
} }
key := r.Key() key := r.Key()
var val string
if r.Type == "TXT" {
t := r.GetTargetTXTJoined()
//printer.Printf("DEBUG: txt outbounds=%s q=%q\n", t, t)
val = txtutil.EncodeQuoted(t)
//printer.Printf("DEBUG: txt encodeds=%s q=%q\n", val, val)
} else {
val = r.GetTargetCombined()
}
if zr, ok := keys[key]; !ok { if zr, ok := keys[key]; !ok {
var vals []string
// Allocate a new ZoneRecord: // Allocate a new ZoneRecord:
zr := livedns.DomainRecord{ zr := livedns.DomainRecord{
RrsetType: r.Type, RrsetType: r.Type,
RrsetTTL: int(r.TTL), RrsetTTL: int(r.TTL),
RrsetName: label, RrsetName: label,
//RrsetValues: []string{r.GetTargetCombined()}, RrsetValues: []string{val},
} }
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 keys[key] = &zr
} else { } else {
zr.RrsetValues = append(zr.RrsetValues, r.GetTargetCombined()) zr.RrsetValues = append(zr.RrsetValues, val)
if r.TTL != uint32(zr.RrsetTTL) { if r.TTL != uint32(zr.RrsetTTL) {
printer.Warnf("All TTLs for a rrset (%v) must be the same. Using smaller of %v and %v.\n", key, r.TTL, zr.RrsetTTL) printer.Warnf("All TTLs for a rrset (%v) must be the same. Using smaller of %v and %v.\n", key, r.TTL, zr.RrsetTTL)
@ -94,7 +100,6 @@ func recordsToNative(rcs []*models.RecordConfig, origin string) []livedns.Domain
zr.RrsetTTL = int(r.TTL) zr.RrsetTTL = int(r.TTL)
} }
} }
} }
} }

View File

@ -175,9 +175,6 @@ func PrepDesiredRecords(dc *models.DomainConfig) {
printer.Warnf("Gandi does not support ttls > 30 days. Setting %s from %d to 2592000\n", rec.GetLabelFQDN(), rec.TTL) printer.Warnf("Gandi does not support ttls > 30 days. Setting %s from %d to 2592000\n", rec.GetLabelFQDN(), rec.TTL)
rec.TTL = 2592000 rec.TTL = 2592000
} }
//if rec.Type == "TXT" {
// rec.SetTarget("\"" + rec.GetTargetField() + "\"") // FIXME(tlim): Should do proper quoting.
//}
if rec.Type == "NS" && rec.GetLabel() == "@" { if rec.Type == "NS" && rec.GetLabel() == "@" {
if !strings.HasSuffix(rec.GetTargetField(), ".gandi.net.") { if !strings.HasSuffix(rec.GetTargetField(), ".gandi.net.") {
printer.Warnf("Gandi does not support changing apex NS records. Ignoring %s\n", rec.GetTargetField()) printer.Warnf("Gandi does not support changing apex NS records. Ignoring %s\n", rec.GetTargetField())