Skip to content

Commit

Permalink
Merge pull request #22 from duedil-ltd/fix/tab-separator
Browse files Browse the repository at this point in the history
Fix tab separator
  • Loading branch information
tarnfeld committed Aug 5, 2014
2 parents 164f8ec + 39f43ce commit a641bc5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,23 @@ If you're not familiar with the DNS specification, to behave *correctly* as an a
#### SOA
```shell
curl -L http://127.0.0.1:4001/v2/keys/net/discodns/.SOA -XPUT -d value="ns1.discodns.net.\tadmin.discodns.net.\t3600\t600\t86400\t10"
curl -L http://127.0.0.1:4001/v2/keys/net/discodns/.SOA -XPUT -d value=$'ns1.discodns.net.\tadmin.discodns.net.\t3600\t600\t86400\t10'
{"action":"set","node":{"key":"/net/discodns/.SOA","value":"...","modifiedIndex":11,"createdIndex":11}}
```
Let's break out the value and see what we've got.
```
ns1.discodns.net \t << - This is the root, master nameserver for this delegated domain
admin.discodns.net \t << - This is the "admin" email address, note the first segment is actually the user (`admin@discodns.net`)
3600 \t << - Time in seconds for any secondary DNS servers to cache the zone (used with `AXFR`)
600 \t << - Interval in seconds for any secondary DNS servers to re-try in the event of a failed zone update
86400 \t << - Expiry time in seconds for any secondary DNS server to drop the zone data (too old)
10 << - Minimum TTL that applies to all DNS entries in the zone
ns1.discodns.net << - This is the root, master nameserver for this delegated domain
admin.discodns.net << - This is the "admin" email address, note the first segment is actually the user (`admin@discodns.net`)
3600 << - Time in seconds for any secondary DNS servers to cache the zone (used with `AXFR`)
600 << - Interval in seconds for any secondary DNS servers to re-try in the event of a failed zone update
86400 << - Expiry time in seconds for any secondary DNS server to drop the zone data (too old)
10 << - Minimum TTL that applies to all DNS entries in the zone
```
These are all tab-separated in the PUT request body. (The `$''` is just a convenience to neatly escape tabs in bash; you could use regular bash strings, with `\u0009` or `%09` for the tab chars, too)
**Note:** If you're familiar with SOA records, you'll probably notice a value missing from above. The "Serial Number" (should be in the 3rd position) is actually filled in automatically by discodns, because it uses the current index of the etcd cluster to describe the current version of the zone. (TODO).
#### NS
Expand Down
4 changes: 2 additions & 2 deletions resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ var converters = map[uint16]func (node *etcd.Node, header dns.RR_Header) (rr dns
},

dns.TypeSRV: func (node *etcd.Node, header dns.RR_Header) (rr dns.RR, err error) {
parts := strings.SplitN(node.Value, "\\t", 4)
parts := strings.SplitN(node.Value, "\t", 4)

if len(parts) != 4 {
err = &NodeConversionError{
Expand Down Expand Up @@ -404,7 +404,7 @@ var converters = map[uint16]func (node *etcd.Node, header dns.RR_Header) (rr dns
},

dns.TypeSOA: func (node *etcd.Node, header dns.RR_Header) (rr dns.RR, err error) {
parts := strings.SplitN(node.Value, "\\t", 6)
parts := strings.SplitN(node.Value, "\t", 6)

if len(parts) < 6 {
err = &NodeConversionError{
Expand Down
30 changes: 15 additions & 15 deletions resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestNameToKeyConverter(t *testing.T) {

func TestAuthorityRoot(t *testing.T) {
resolver.etcdPrefix = "TestAuthorityRoot/"
client.Set("TestAuthorityRoot/net/disco/.SOA", "ns1.disco.net.\\tadmin.disco.net.\\t3600\\t600\\t86400\\t10", 0)
client.Set("TestAuthorityRoot/net/disco/.SOA", "ns1.disco.net.\tadmin.disco.net.\t3600\t600\t86400\t10", 0)

query := new(dns.Msg)
query.SetQuestion("disco.net.", dns.TypeA)
Expand Down Expand Up @@ -167,7 +167,7 @@ func TestAuthorityRoot(t *testing.T) {

func TestAuthorityDomain(t *testing.T) {
resolver.etcdPrefix = "TestAuthorityDomain/"
client.Set("TestAuthorityDomain/net/disco/.SOA", "ns1.disco.net.\\tadmin.disco.net.\\t3600\\t600\\t86400\\t10", 0)
client.Set("TestAuthorityDomain/net/disco/.SOA", "ns1.disco.net.\tadmin.disco.net.\t3600\t600\t86400\t10", 0)

query := new(dns.Msg)
query.SetQuestion("bar.disco.net.", dns.TypeA)
Expand Down Expand Up @@ -226,8 +226,8 @@ func TestAuthorityDomain(t *testing.T) {

func TestAuthoritySubdomain(t *testing.T) {
resolver.etcdPrefix = "TestAuthoritySubdomain/"
client.Set("TestAuthoritySubdomain/net/disco/.SOA", "ns1.disco.net.\\tadmin.disco.net.\\t3600\\t600\\t86400\\t10", 0)
client.Set("TestAuthoritySubdomain/net/disco/bar/.SOA", "ns1.bar.disco.net.\\tbar.disco.net.\\t3600\\t600\\t86400\\t10", 0)
client.Set("TestAuthoritySubdomain/net/disco/.SOA", "ns1.disco.net.\tadmin.disco.net.\t3600\t600\t86400\t10", 0)
client.Set("TestAuthoritySubdomain/net/disco/bar/.SOA", "ns1.bar.disco.net.\tbar.disco.net.\t3600\t600\t86400\t10", 0)

query := new(dns.Msg)
query.SetQuestion("foo.bar.disco.net.", dns.TypeA)
Expand Down Expand Up @@ -291,7 +291,7 @@ func TestAuthoritySubdomain(t *testing.T) {
func TestAnswerQuestionA(t *testing.T) {
resolver.etcdPrefix = "TestAnswerQuestionA/"
client.Set("TestAnswerQuestionA/net/disco/bar/.A", "1.2.3.4", 0)
client.Set("TestAnswerQuestionA/net/disco/.SOA", "ns1.disco.net.\\tadmin.disco.net.\\t3600\\t600\\t86400\\t10", 0)
client.Set("TestAnswerQuestionA/net/disco/.SOA", "ns1.disco.net.\tadmin.disco.net.\t3600\t600\t86400\t10", 0)

query := new(dns.Msg)
query.SetQuestion("bar.disco.net.", dns.TypeA)
Expand Down Expand Up @@ -331,7 +331,7 @@ func TestAnswerQuestionA(t *testing.T) {
func TestAnswerQuestionAAAA(t *testing.T) {
resolver.etcdPrefix = "TestAnswerQuestionAAAA/"
client.Set("TestAnswerQuestionAAAA/net/disco/bar/.AAAA", "::1", 0)
client.Set("TestAnswerQuestionAAAA/net/disco/.SOA", "ns1.disco.net.\\tadmin.disco.net.\\t3600\\t600\\t86400\\t10", 0)
client.Set("TestAnswerQuestionAAAA/net/disco/.SOA", "ns1.disco.net.\tadmin.disco.net.\t3600\t600\t86400\t10", 0)

query := new(dns.Msg)
query.SetQuestion("bar.disco.net.", dns.TypeAAAA)
Expand Down Expand Up @@ -563,7 +563,7 @@ func TestLookupAnswerForNS(t *testing.T) {

func TestLookupAnswerForSOA(t *testing.T) {
resolver.etcdPrefix = "TestLookupAnswerForSOA/"
client.Set("TestLookupAnswerForSOA/net/disco/.SOA", "ns1.disco.net.\\tadmin.disco.net.\\t3600\\t600\\t86400\\t10", 0)
client.Set("TestLookupAnswerForSOA/net/disco/.SOA", "ns1.disco.net.\tadmin.disco.net.\t3600\t600\t86400\t10", 0)

records, _ := resolver.LookupAnswersForType("disco.net.", dns.TypeSOA)

Expand Down Expand Up @@ -677,7 +677,7 @@ func TestLookupAnswerForSRV(t *testing.T) {

resolver.etcdPrefix = "TestLookupAnswerForSRV/"
client.Set("TestLookupAnswerForSRV/net/disco/_tcp/_http/.SRV",
"100\\t100\\t80\\tsome-webserver.disco.net",
"100\t100\t80\tsome-webserver.disco.net",
0)

records, _ := resolver.LookupAnswersForType("_http._tcp.disco.net.", dns.TypeSRV)
Expand Down Expand Up @@ -712,13 +712,13 @@ func TestLookupAnswerForSRVInvalidValues(t *testing.T) {

var bad_vals_map = map[string]string {
"wrong-delimiter": "10 10 80 foo.disco.net",
"not-enough-fields": "0\\t0",
"neg-int-priority": "-10\\t10\\t80\\tfoo.disco.net",
"neg-int-weight": "10\\t-10\\t80\\tfoo.disco.net",
"neg-int-port": "10\\t10\\t-80\\tfoo.disco.net",
"large-int-priority": "65536\\t10\\t80\\tfoo.disco.net",
"large-int-weight": "10\\t65536\\t80\\tfoo.disco.net",
"large-int-port": "10\\t10\\t65536\\tfoo.disco.net"}
"not-enough-fields": "0\t0",
"neg-int-priority": "-10\t10\t80\tfoo.disco.net",
"neg-int-weight": "10\t-10\t80\tfoo.disco.net",
"neg-int-port": "10\t10\t-80\tfoo.disco.net",
"large-int-priority": "65536\t10\t80\tfoo.disco.net",
"large-int-weight": "10\t65536\t80\tfoo.disco.net",
"large-int-port": "10\t10\t65536\tfoo.disco.net"}

for name, value := range bad_vals_map {

Expand Down

0 comments on commit a641bc5

Please sign in to comment.