mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-02-24 23:53:01 +08:00
HEXONET: Support long TXT records and fix whitespace bug (#1283)
* HEXONET: Support for long TXT records * HEXONET: Revert and update comments in auditrecords.go * Update auditrecords.go * HEXONET: Sync TXT support with reality * Fix the fixed unit tests Co-authored-by: Burak Tamturk <buraktamturk@gmail.com>
This commit is contained in:
parent
eef8c25a95
commit
7f071b4ce8
3 changed files with 21 additions and 37 deletions
|
@ -9,25 +9,10 @@ import (
|
||||||
// supportable by this provider.
|
// supportable by this provider.
|
||||||
func AuditRecords(records []*models.RecordConfig) error {
|
func AuditRecords(records []*models.RecordConfig) error {
|
||||||
|
|
||||||
// if err := recordaudit.TxtNoLongStrings(records); err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// Not needed as of 2021-03-26
|
|
||||||
|
|
||||||
if err := recordaudit.TxtNoMultipleStrings(records); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// Still needed as of 2021-03-07
|
|
||||||
|
|
||||||
if err := recordaudit.TxtNotEmpty(records); err != nil {
|
if err := recordaudit.TxtNotEmpty(records); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Still needed as of 2021-03-01
|
// Still needed as of 2021-10-01
|
||||||
|
|
||||||
if err := recordaudit.TxtNoTrailingSpace(records); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// Still needed as of 2021-03-01
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
|
|
||||||
"github.com/StackExchange/dnscontrol/v3/models"
|
"github.com/StackExchange/dnscontrol/v3/models"
|
||||||
"github.com/StackExchange/dnscontrol/v3/pkg/diff"
|
"github.com/StackExchange/dnscontrol/v3/pkg/diff"
|
||||||
|
"github.com/StackExchange/dnscontrol/v3/pkg/txtutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HXRecord covers an individual DNS resource record.
|
// HXRecord covers an individual DNS resource record.
|
||||||
|
@ -69,6 +70,7 @@ func (n *HXClient) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Corr
|
||||||
|
|
||||||
// Normalize
|
// Normalize
|
||||||
models.PostProcessRecords(actual)
|
models.PostProcessRecords(actual)
|
||||||
|
txtutil.SplitSingleLongTxt(dc.Records)
|
||||||
|
|
||||||
differ := diff.New(dc)
|
differ := diff.New(dc)
|
||||||
_, create, del, mod, err := differ.IncrementalDiff(actual)
|
_, create, del, mod, err := differ.IncrementalDiff(actual)
|
||||||
|
@ -276,15 +278,12 @@ func (n *HXClient) deleteRecordString(record *HXRecord, domain string) string {
|
||||||
|
|
||||||
// encodeTxt encodes TxtStrings for sending in the CREATE/MODIFY API:
|
// encodeTxt encodes TxtStrings for sending in the CREATE/MODIFY API:
|
||||||
func encodeTxt(txts []string) string {
|
func encodeTxt(txts []string) string {
|
||||||
ans := txts[0]
|
var r []string
|
||||||
|
for _, txt := range txts {
|
||||||
if len(txts) > 1 {
|
n := `"` + strings.Replace(txt, `"`, `\"`, -1) + `"`
|
||||||
ans = ""
|
r = append(r, n)
|
||||||
for _, t := range txts {
|
|
||||||
ans += `"` + strings.Replace(t, `"`, `\"`, -1) + `"`
|
|
||||||
}
|
}
|
||||||
}
|
return strings.Join(r, " ")
|
||||||
return ans
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// finds a string surrounded by quotes that might contain an escaped quote character.
|
// finds a string surrounded by quotes that might contain an escaped quote character.
|
||||||
|
|
|
@ -9,16 +9,16 @@ var txtData = []struct {
|
||||||
decoded []string
|
decoded []string
|
||||||
encoded string
|
encoded string
|
||||||
}{
|
}{
|
||||||
{[]string{`simple`}, `simple`},
|
{[]string{`simple`}, `"simple"`},
|
||||||
{[]string{`changed`}, `changed`},
|
{[]string{`changed`}, `"changed"`},
|
||||||
{[]string{`with spaces`}, `with spaces`},
|
{[]string{`with spaces`}, `"with spaces"`},
|
||||||
{[]string{`with whitespace`}, `with whitespace`},
|
{[]string{`with whitespace`}, `"with whitespace"`},
|
||||||
{[]string{"one", "two"}, `"one""two"`},
|
{[]string{"one", "two"}, `"one" "two"`},
|
||||||
{[]string{"eh", "bee", "cee"}, `"eh""bee""cee"`},
|
{[]string{"eh", "bee", "cee"}, `"eh" "bee" "cee"`},
|
||||||
{[]string{"o\"ne", "tw\"o"}, `"o\"ne""tw\"o"`},
|
{[]string{"o\"ne", "tw\"o"}, `"o\"ne" "tw\"o"`},
|
||||||
{[]string{"dimple"}, `dimple`},
|
{[]string{"dimple"}, `"dimple"`},
|
||||||
{[]string{"fun", "two"}, `"fun""two"`},
|
{[]string{"fun", "two"}, `"fun" "two"`},
|
||||||
{[]string{"eh", "bzz", "cee"}, `"eh""bzz""cee"`},
|
{[]string{"eh", "bzz", "cee"}, `"eh" "bzz" "cee"`},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEncodeTxt(t *testing.T) {
|
func TestEncodeTxt(t *testing.T) {
|
||||||
|
@ -26,7 +26,7 @@ func TestEncodeTxt(t *testing.T) {
|
||||||
for i, test := range txtData {
|
for i, test := range txtData {
|
||||||
enc := encodeTxt(test.decoded)
|
enc := encodeTxt(test.decoded)
|
||||||
if enc != test.encoded {
|
if enc != test.encoded {
|
||||||
t.Errorf("%v: txt\n data: []string{%v}\nexpected: %s\n got: %s",
|
t.Errorf("%v: txt\n data: []string{%v}\nexpected: %q\n got: %q",
|
||||||
i, "`"+strings.Join(test.decoded, "`, `")+"`", test.encoded, enc)
|
i, "`"+strings.Join(test.decoded, "`, `")+"`", test.encoded, enc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,11 +39,11 @@ func TestDecodeTxt(t *testing.T) {
|
||||||
got := decodeTxt(data)
|
got := decodeTxt(data)
|
||||||
wanted := test.decoded
|
wanted := test.decoded
|
||||||
if len(got) != len(wanted) {
|
if len(got) != len(wanted) {
|
||||||
t.Errorf("%v: txt\n decode: %v\nexpected: `%v`\n got: `%v`\n", i, data, strings.Join(wanted, "`, `"), strings.Join(got, "`, `"))
|
t.Errorf("%v: txt\n decode: %v\nexpected: %q\n got: %q\n", i, data, strings.Join(wanted, "`, `"), strings.Join(got, "`, `"))
|
||||||
} else {
|
} else {
|
||||||
for j := range got {
|
for j := range got {
|
||||||
if got[j] != wanted[j] {
|
if got[j] != wanted[j] {
|
||||||
t.Errorf("%v: txt\n decode: %v\nexpected: `%v`\n got: `%v`\n", i, data, strings.Join(wanted, "`, `"), strings.Join(got, "`, `"))
|
t.Errorf("%v: txt\n decode: %v\nexpected: %q\n got: %q\n", i, data, strings.Join(wanted, "`, `"), strings.Join(got, "`, `"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue