Skip to content

Commit

Permalink
Merge pull request #267 from wfaulk/master
Browse files Browse the repository at this point in the history
add support for importing/exporting NAPTR records
  • Loading branch information
barnybug authored Feb 10, 2019
2 parents 3fcc537 + 534e697 commit 5ac4382
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
37 changes: 37 additions & 0 deletions bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"io"
"net"
"os"
"regexp"
"strconv"
"strings"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -77,6 +79,16 @@ func ConvertBindToRR(record dns.RR) *route53.ResourceRecord {
return &route53.ResourceRecord{
Value: aws.String(value),
}
case *dns.NAPTR:
var value string
if record.Replacement == "." {
value = fmt.Sprintf("%d %d \"%s\" \"%s\" \"%s\" .", record.Order, record.Preference, record.Flags, record.Service, record.Regexp)
} else {
value = fmt.Sprintf("%d %d \"%s\" \"%s\" \"\" \"%s\"", record.Order, record.Preference, record.Flags, record.Service, record.Replacement)
}
return &route53.ResourceRecord{
Value: aws.String(value),
}
case *dns.NS:
return &route53.ResourceRecord{
Value: aws.String(record.Ns),
Expand Down Expand Up @@ -200,6 +212,8 @@ func absolute(name string) string {
return name
}

var reNaptr = regexp.MustCompile(`^([[:digit:]]+) ([[:digit:]]+) "([^"]*)" "([^"]*)" "([^"]*)" "?([^"]+)"?$`)

// ConvertRRSetToBind will convert a ResourceRecordSet to an array of RR entries
func ConvertRRSetToBind(rrset *route53.ResourceRecordSet) []dns.RR {
ret := []dns.RR{}
Expand Down Expand Up @@ -294,6 +308,29 @@ func ConvertRRSetToBind(rrset *route53.ResourceRecordSet) []dns.RR {
}
ret = append(ret, dnsrr)
}
case "NAPTR":
for _, rr := range rrset.ResourceRecords {
// parse value
naptr := reNaptr.FindStringSubmatch(*rr.Value)
order, _ := strconv.Atoi(naptr[1])
preference, _ := strconv.Atoi(naptr[2])

dnsrr := &dns.NAPTR{
Hdr: dns.RR_Header{
Name: name,
Rrtype: dns.TypeNAPTR,
Class: dns.ClassINET,
Ttl: uint32(*rrset.TTL),
},
Order: uint16(order),
Preference: uint16(preference),
Flags: naptr[3],
Service: naptr[4],
Regexp: naptr[5],
Replacement: naptr[6],
}
ret = append(ret, dnsrr)
}
case "NS":
for _, rr := range rrset.ResourceRecords {
dnsrr := &dns.NS{
Expand Down
28 changes: 28 additions & 0 deletions bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,34 @@ var testConvertRRSetToBindTable = []struct {
},
},
},
{
Input: route53.ResourceRecordSet{
Type: aws.String("NAPTR"),
Name: aws.String("example.com."),
ResourceRecords: []*route53.ResourceRecord{
&route53.ResourceRecord{
Value: aws.String(`100 10 "u" "sip+E2U" "!^.*$!sip:information@foo.se!i" .`),
},
},
TTL: aws.Int64(86400),
},
Output: []dns.RR{
&dns.NAPTR{
Hdr: dns.RR_Header{
Name: "example.com.",
Rrtype: dns.TypeNAPTR,
Class: dns.ClassINET,
Ttl: uint32(86400),
},
Order: 100,
Preference: 10,
Flags: "u",
Service: "sip+E2U",
Regexp: "!^.*$!sip:information@foo.se!i",
Replacement: ".",
},
},
},
{
Input: route53.ResourceRecordSet{
Type: aws.String("A"),
Expand Down
2 changes: 2 additions & 0 deletions tests/basic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ test 86400 IN TXT "multivalued" " txt \"quoted\" record"
www 86400 IN A 10.0.0.1
web 86400 IN CNAME www
google 86400 IN CNAME www.google.com.
rfc3403-1 86400 IN NAPTR 100 10 "u" "sip+E2U" "!^.*$!sip:information@foo.se!i" .
rfc3403-2 86400 IN NAPTR 100 50 "a" "z3950+N2L+N2C" "" cidserver.example.com.

0 comments on commit 5ac4382

Please sign in to comment.