Skip to content

Commit

Permalink
Add support for "multivalue answer" routing
Browse files Browse the repository at this point in the history
  • Loading branch information
lalinsky committed Sep 15, 2017
1 parent d8f8b00 commit 060269b
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 0 deletions.
11 changes: 11 additions & 0 deletions awsrr.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,20 @@ func (f *WeightedRoute) Parse(kvs KeyValues) {
f.Weight = int64(kvs.GetInt("weight"))
}

type MultiValueAnswerRoute struct {
}

func (f *MultiValueAnswerRoute) String() string {
return KeyValues{"routing", "MULTIVALUE"}.String()
}

func (f *MultiValueAnswerRoute) Parse(kvs KeyValues) {
}

var RoutingTypes = map[string]func() AWSRoute{
"FAILOVER": func() AWSRoute { return &FailoverRoute{} },
"GEOLOCATION": func() AWSRoute { return &GeoLocationRoute{} },
"LATENCY": func() AWSRoute { return &LatencyRoute{} },
"WEIGHTED": func() AWSRoute { return &WeightedRoute{} },
"MULTIVALUE": func() AWSRoute { return &MultiValueAnswerRoute{} },
}
4 changes: 4 additions & 0 deletions bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ func ConvertBindToRRSet(records []dns.RR) *route53.ResourceRecordSet {
rrset.Region = aws.String(route.Region)
case *WeightedRoute:
rrset.Weight = aws.Int64(route.Weight)
case *MultiValueAnswerRoute:
rrset.MultiValueAnswer = aws.Bool(true)
}
if awsrr.HealthCheckId != nil {
rrset.HealthCheckId = awsrr.HealthCheckId
Expand Down Expand Up @@ -423,6 +425,8 @@ func ConvertRRSetToBind(rrset *route53.ResourceRecordSet) []dns.RR {
route = &LatencyRoute{*rrset.Region}
} else if rrset.GeoLocation != nil {
route = &GeoLocationRoute{rrset.GeoLocation.CountryCode, rrset.GeoLocation.ContinentCode, rrset.GeoLocation.SubdivisionCode}
} else if rrset.MultiValueAnswer != nil && *rrset.MultiValueAnswer {
route = &MultiValueAnswerRoute{}
}
if route != nil {
for i, rr := range ret {
Expand Down
7 changes: 7 additions & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ type createArgs struct {
countryCode string
continentCode string
subdivisionCode string
multivalue bool
}

func (args createArgs) validate() bool {
Expand Down Expand Up @@ -461,6 +462,9 @@ func (args createArgs) validate() bool {
if args.continentCode != "" {
extcount += 1
}
if args.multivalue {
extcount += 1
}
if args.subdivisionCode != "" && args.countryCode == "" {
fmt.Println("country-code must be specified if subdivision-code is specified")
return false
Expand Down Expand Up @@ -512,6 +516,9 @@ func (args createArgs) applyRRSetParams(rrset *route53.ResourceRecordSet) {
SubdivisionCode: aws.String(args.subdivisionCode),
}
}
if args.multivalue {
rrset.MultiValueAnswer = aws.Bool(true)
}
}

func equalStringPtrs(a, b *string) bool {
Expand Down
6 changes: 6 additions & 0 deletions internal/features/import.feature
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ Feature: import
When I run "cli53 import --file tests/weighted.txt $domain"
Then the domain "$domain" export matches file "tests/weighted.txt"

@multivalue
Scenario: I can import a zone with multivalue answer extensions
Given I have a domain "$domain"
When I run "cli53 import --file tests/multivalue.txt $domain"
Then the domain "$domain" export matches file "tests/multivalue.txt"

Scenario: I can import a zone with alias extensions
Given I have a domain "$domain"
When I run "cli53 import --file tests/alias.txt $domain"
Expand Down
6 changes: 6 additions & 0 deletions internal/features/rrcreate.feature
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ Feature: rrcreate
When I run "cli53 rrcreate -i Zero --weight 0 $domain 'weighted 300 IN A 127.0.0.1'"
Then the domain "$domain" has record "weighted.$domain. 300 IN A 127.0.0.1 ; AWS routing="WEIGHTED" weight=0 identifier="Zero""

@multivalue
Scenario: I can create a multivalue answer record
Given I have a domain "$domain"
When I run "cli53 rrcreate -i One --multivalue $domain 'multivalue 300 IN A 127.0.0.1'"
Then the domain "$domain" has record "multivalue.$domain. 300 IN A 127.0.0.1 ; AWS routing="MULTIVALUE" identifier="One""

Scenario: I can create an alias
Given I have a domain "$domain"
When I run "cli53 rrcreate $domain 'www A 127.0.0.1'"
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ func Main(args []string) int {
Name: "subdivision-code",
Usage: "subdivision code for geolocation routing",
},
cli.BoolFlag{
Name: "multivalue",
Usage: "use multivalue answer routing",
},
),
Action: func(c *cli.Context) (err error) {
r53, err = getService(c)
Expand Down Expand Up @@ -348,6 +352,7 @@ func Main(args []string) int {
countryCode: c.String("country-code"),
continentCode: c.String("continent-code"),
subdivisionCode: c.String("subdivision-code"),
multivalue: c.Bool("multivalue"),
}
if args.validate() {
createRecords(args)
Expand Down
2 changes: 2 additions & 0 deletions tests/multivalue.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
multivalue 300 IN A 127.0.0.1 ; AWS routing="MULTIVALUE" identifier="One"
multivalue 300 IN A 127.0.0.2 ; AWS routing="MULTIVALUE" identifier="Two"

0 comments on commit 060269b

Please sign in to comment.