fixing a few mistakes in list conversion

This commit is contained in:
Craig Peterson 2016-09-27 12:28:09 -06:00
parent c747498b87
commit 3fb4f3b54c
3 changed files with 21 additions and 12 deletions

View file

@ -5,10 +5,10 @@ import (
"net" "net"
"strings" "strings"
"github.com/miekg/dns"
"github.com/miekg/dns/dnsutil"
"github.com/StackExchange/dnscontrol/models" "github.com/StackExchange/dnscontrol/models"
"github.com/StackExchange/dnscontrol/transform" "github.com/StackExchange/dnscontrol/transform"
"github.com/miekg/dns"
"github.com/miekg/dns/dnsutil"
) )
// Returns false if label does not validate. // Returns false if label does not validate.
@ -138,19 +138,27 @@ func import_transform(src_domain, dst_domain *models.DomainConfig, transforms []
// 4. For As, change the target as described the transforms. // 4. For As, change the target as described the transforms.
for _, rec := range src_domain.Records { for _, rec := range src_domain.Records {
var newrec models.RecordConfig newRec := func() *models.RecordConfig {
newrec = *rec rec2, _ := rec.Copy()
newrec.Name = newrec.NameFQDN rec2.Name = rec2.NameFQDN
newrec.NameFQDN = dnsutil.AddOrigin(newrec.Name, dst_domain.Name) rec2.NameFQDN = dnsutil.AddOrigin(rec2.Name, dst_domain.Name)
return rec2
}
switch rec.Type { switch rec.Type {
case "A": case "A":
tr, err := transform.TransformIP(net.ParseIP(newrec.Target), transforms) trs, err := transform.TransformIPToList(net.ParseIP(rec.Target), transforms)
if err != nil { if err != nil {
return fmt.Errorf("import_transform: TransformIP(%v, %v) returned err=%s", newrec.Target, transforms, err) return fmt.Errorf("import_transform: TransformIP(%v, %v) returned err=%s", rec.Target, transforms, err)
}
for _, tr := range trs {
r := newRec()
r.Target = tr.String()
dst_domain.Records = append(dst_domain.Records, r)
} }
newrec.Target = tr.String()
case "CNAME": case "CNAME":
newrec.Target = transform_cname(newrec.Target, src_domain.Name, dst_domain.Name) r := newRec()
r.Target = transform_cname(r.Target, src_domain.Name, dst_domain.Name)
dst_domain.Records = append(dst_domain.Records, r)
case "MX", "NS", "TXT": case "MX", "NS", "TXT":
// Not imported. // Not imported.
continue continue
@ -158,7 +166,6 @@ func import_transform(src_domain, dst_domain *models.DomainConfig, transforms []
return fmt.Errorf("import_transform: Unimplemented record type %v (%v)", return fmt.Errorf("import_transform: Unimplemented record type %v (%v)",
rec.Type, rec.Name) rec.Type, rec.Name)
} }
dst_domain.Records = append(dst_domain.Records, &newrec)
} }
return nil return nil
} }

View file

@ -111,7 +111,7 @@ func TransformIPToList(address net.IP, transforms []IpConversion) ([]net.IP, err
return nil, err return nil, err
} }
if (thisIP >= min) && (thisIP <= max) { if (thisIP >= min) && (thisIP <= max) {
if conv.NewIPs != nil { if len(conv.NewIPs) > 0 {
return conv.NewIPs, nil return conv.NewIPs, nil
} }
list := []net.IP{} list := []net.IP{}

View file

@ -126,6 +126,7 @@ func Test_TransformIP(t *testing.T) {
High: net.ParseIP("55.255.0.0"), High: net.ParseIP("55.255.0.0"),
NewBases: []net.IP{net.ParseIP("66.0.0.0"), net.ParseIP("77.0.0.0")}, NewBases: []net.IP{net.ParseIP("66.0.0.0"), net.ParseIP("77.0.0.0")},
}} }}
//NO TRANSFORMS ON 99.x.x.x PLZ
var tests = []struct { var tests = []struct {
experiment string experiment string
@ -150,6 +151,7 @@ func Test_TransformIP(t *testing.T) {
{"44.44.44.24", "100.100.100.44"}, {"44.44.44.24", "100.100.100.44"},
{"44.44.44.44", "44.44.44.44"}, {"44.44.44.44", "44.44.44.44"},
{"55.0.42.42", "66.0.42.42,77.0.42.42"}, {"55.0.42.42", "66.0.42.42,77.0.42.42"},
{"99.0.0.42", "99.0.0.42"},
} }
for _, test := range tests { for _, test := range tests {