forked from StackExchange/dnscontrol
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for TXT records with multiple strings (BIND, ROUTE53) (St…
…ackExchange#293) * BIND: Support TXT records with multiple strings (StackExchange#289) * ROUTE53: Add support for TXT records with multiple strings (StackExchange#292)
- Loading branch information
Tom Limoncelli
authored
Jan 5, 2018
1 parent
5dec688
commit db1858a
Showing
32 changed files
with
485 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
$TTL 300 | ||
@ IN SOA DEFAULT_NOT_SET. DEFAULT_NOT_SET. 2017091830 3600 600 604800 1440 | ||
@ IN SOA DEFAULT_NOT_SET. DEFAULT_NOT_SET. 2018010281 3600 600 604800 1440 | ||
IN NS ns1.otherdomain.tld. | ||
IN NS ns2.otherdomain.tld. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package models | ||
|
||
import "strings" | ||
|
||
// SetTxt sets the value of a TXT record to s. | ||
func (rc *RecordConfig) SetTxt(s string) { | ||
rc.Target = s | ||
rc.TxtStrings = []string{s} | ||
} | ||
|
||
// SetTxts sets the value of a TXT record to the list of strings s. | ||
func (rc *RecordConfig) SetTxts(s []string) { | ||
rc.Target = s[0] | ||
rc.TxtStrings = s | ||
} | ||
|
||
// SetTxtParse sets the value of TXT record if the list of strings is combined into one string. | ||
// `foo` -> []string{"foo"} | ||
// `"foo"` -> []string{"foo"} | ||
// `"foo" "bar"` -> []string{"foo" "bar"} | ||
func (rc *RecordConfig) SetTxtParse(s string) { | ||
rc.SetTxts(ParseQuotedTxt(s)) | ||
} | ||
|
||
// IsQuoted returns true if the string starts and ends with a double quote. | ||
func IsQuoted(s string) bool { | ||
if s == "" { | ||
return false | ||
} | ||
if len(s) < 2 { | ||
return false | ||
} | ||
if s[0] == '"' && s[len(s)-1] == s[0] { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
// StripQuotes returns the string with the starting and ending quotes removed. | ||
func StripQuotes(s string) string { | ||
if IsQuoted(s) { | ||
return s[1 : len(s)-1] | ||
} | ||
return s | ||
} | ||
|
||
// ParseQuotedTxt returns the individual strings of a combined quoted string. | ||
// `foo` -> []string{"foo"} | ||
// `"foo"` -> []string{"foo"} | ||
// `"foo" "bar"` -> []string{"foo" "bar"} | ||
// NOTE: it is assumed there is exactly one space between the quotes. | ||
func ParseQuotedTxt(s string) []string { | ||
if !IsQuoted(s) { | ||
return []string{s} | ||
} | ||
return strings.Split(StripQuotes(s), `" "`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package models | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestIsQuoted(t *testing.T) { | ||
tests := []struct { | ||
d1 string | ||
e1 bool | ||
}{ | ||
{``, false}, | ||
{`foo`, false}, | ||
{`""`, true}, | ||
{`"a"`, true}, | ||
{`"bb"`, true}, | ||
{`"ccc"`, true}, | ||
{`"aaa" "bbb"`, true}, | ||
} | ||
for i, test := range tests { | ||
r := IsQuoted(test.d1) | ||
if r != test.e1 { | ||
t.Errorf("%v: expected (%v) got (%v)", i, test.e1, r) | ||
} | ||
} | ||
} | ||
|
||
func TestStripQuotes(t *testing.T) { | ||
tests := []struct { | ||
d1 string | ||
e1 string | ||
}{ | ||
{``, ``}, | ||
{`a`, `a`}, | ||
{`bb`, `bb`}, | ||
{`ccc`, `ccc`}, | ||
{`dddd`, `dddd`}, | ||
{`"A"`, `A`}, | ||
{`"BB"`, `BB`}, | ||
{`"CCC"`, `CCC`}, | ||
{`"DDDD"`, `DDDD`}, | ||
{`"EEEEE"`, `EEEEE`}, | ||
{`"aaa" "bbb"`, `aaa" "bbb`}, | ||
} | ||
for i, test := range tests { | ||
r := StripQuotes(test.d1) | ||
if r != test.e1 { | ||
t.Errorf("%v: expected (%v) got (%v)", i, test.e1, r) | ||
} | ||
} | ||
} | ||
|
||
func TestSetTxtParse(t *testing.T) { | ||
tests := []struct { | ||
d1 string | ||
e1 string | ||
e2 []string | ||
}{ | ||
{``, ``, []string{``}}, | ||
{`foo`, `foo`, []string{`foo`}}, | ||
{`"foo"`, `foo`, []string{`foo`}}, | ||
{`"aaa" "bbb"`, `aaa`, []string{`aaa`, `bbb`}}, | ||
} | ||
for i, test := range tests { | ||
x := &RecordConfig{Type: "TXT"} | ||
x.SetTxtParse(test.d1) | ||
if x.Target != test.e1 { | ||
t.Errorf("%v: expected Target=(%v) got (%v)", i, test.e1, x.Target) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
D("foo.com","none" | ||
, TXT("@","simple") | ||
, TXT("@",["one"]) | ||
, TXT("@",["bonie", "clyde"]) | ||
, TXT("@",["straw", "wood", "brick"]) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"registrars": [], | ||
"dns_providers": [], | ||
"domains": [ | ||
{ | ||
"name": "foo.com", | ||
"registrar": "none", | ||
"dnsProviders": {}, | ||
"records": [ | ||
{ | ||
"type": "TXT", | ||
"name": "@", | ||
"target": "simple", | ||
"txtstrings": [ "simple" ] | ||
}, | ||
{ | ||
"type": "TXT", | ||
"name": "@", | ||
"target": "one", | ||
"txtstrings": [ "one" ] | ||
}, | ||
{ | ||
"type": "TXT", | ||
"name": "@", | ||
"target": "bonie", | ||
"txtstrings": [ "bonie", "clyde" ] | ||
}, | ||
{ | ||
"type": "TXT", | ||
"name": "@", | ||
"target": "straw", | ||
"txtstrings": [ "straw", "wood", "brick" ] | ||
} | ||
] | ||
} | ||
] | ||
} |
Oops, something went wrong.