mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04:00
Add PTR record support for Route53 plugin (#1606)
This fix adds PTR record support for Route53 plugin This fix fixes 1595 Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
@@ -50,6 +50,8 @@ func (rr Route53) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
|
||||
answers = a(qname, output.ResourceRecordSets)
|
||||
case dns.TypeAAAA:
|
||||
answers = aaaa(qname, output.ResourceRecordSets)
|
||||
case dns.TypePTR:
|
||||
answers = ptr(qname, output.ResourceRecordSets)
|
||||
}
|
||||
|
||||
if len(answers) == 0 {
|
||||
@@ -93,5 +95,18 @@ func aaaa(zone string, rrss []*route53.ResourceRecordSet) []dns.RR {
|
||||
return answers
|
||||
}
|
||||
|
||||
func ptr(zone string, rrss []*route53.ResourceRecordSet) []dns.RR {
|
||||
answers := []dns.RR{}
|
||||
for _, rrs := range rrss {
|
||||
for _, rr := range rrs.ResourceRecords {
|
||||
r := new(dns.PTR)
|
||||
r.Hdr = dns.RR_Header{Name: zone, Rrtype: dns.TypePTR, Class: dns.ClassINET, Ttl: uint32(aws.Int64Value(rrs.TTL))}
|
||||
r.Ptr = aws.StringValue(rr.Value)
|
||||
answers = append(answers, r)
|
||||
}
|
||||
}
|
||||
return answers
|
||||
}
|
||||
|
||||
// Name implements the Handler interface.
|
||||
func (rr Route53) Name() string { return "route53" }
|
||||
|
||||
@@ -24,6 +24,8 @@ func (mockedRoute53) ListResourceRecordSets(input *route53.ListResourceRecordSet
|
||||
value = "10.2.3.4"
|
||||
case "AAAA":
|
||||
value = "2001:db8:85a3::8a2e:370:7334"
|
||||
case "PTR":
|
||||
value = "ptr.example.org"
|
||||
}
|
||||
return &route53.ListResourceRecordSetsOutput{
|
||||
ResourceRecordSets: []*route53.ResourceRecordSet{
|
||||
@@ -66,6 +68,13 @@ func TestRoute53(t *testing.T) {
|
||||
expectedReply: []string{"2001:db8:85a3::8a2e:370:7334"},
|
||||
expectedErr: nil,
|
||||
},
|
||||
{
|
||||
qname: "example.org",
|
||||
qtype: dns.TypePTR,
|
||||
expectedCode: dns.RcodeSuccess,
|
||||
expectedReply: []string{"ptr.example.org"},
|
||||
expectedErr: nil,
|
||||
},
|
||||
}
|
||||
|
||||
ctx := context.TODO()
|
||||
@@ -91,6 +100,8 @@ func TestRoute53(t *testing.T) {
|
||||
actual = rec.Msg.Answer[i].(*dns.A).A.String()
|
||||
case dns.TypeAAAA:
|
||||
actual = rec.Msg.Answer[i].(*dns.AAAA).AAAA.String()
|
||||
case dns.TypePTR:
|
||||
actual = rec.Msg.Answer[i].(*dns.PTR).Ptr
|
||||
}
|
||||
if actual != expected {
|
||||
t.Errorf("Test %d: Expected answer %s, but got %s", i, expected, actual)
|
||||
|
||||
Reference in New Issue
Block a user