Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for importing/exporting NAPTR records #267

Merged
merged 8 commits into from
Feb 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.