From e4f50fe13c43fc4aed7635fd2f989e4edf01f662 Mon Sep 17 00:00:00 2001 From: sawanoboly Date: Wed, 15 Apr 2015 02:25:33 +0900 Subject: [PATCH 1/3] add ListHostedZonesByName to route53 --- route53/route53.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/route53/route53.go b/route53/route53.go index 92d623f6..9df76d7a 100644 --- a/route53/route53.go +++ b/route53/route53.go @@ -245,6 +245,38 @@ func (r *Route53) ListHostedZones(marker string, maxItems int) (*ListHostedZones return out, err } +type ListHostedZonesByNameResponse struct { + HostedZones []HostedZone `xml:"HostedZones>HostedZone"` + DNSName string `xml:"DNSName"` + IsTruncated bool `xml:"IsTruncated"` + NextDNSName string `xml:"NextDNSName"` + NextHostedZoneId string `xml:"NextHostedZoneId"` + MaxItems int `xml:"MaxItems"` +} + +func (r *Route53) ListHostedZonesByName(dnsName string, hostedZoneId string, maxItems int) (*ListHostedZonesByNameResponse, error) { + values := url.Values{} + + if dnsName != "" { + values.Add("dnsname", dnsName) + } + + if hostedZoneId != "" { + values.Add("Hostedzoneid", hostedZoneId) + } + + if maxItems != 0 { + values.Add("maxitems", strconv.Itoa(maxItems)) + } + + out := &ListHostedZonesByNameResponse{} + err := r.query("GET", fmt.Sprintf("/%s/hostedzonesbyname", APIVersion), values, out) + if err != nil { + return nil, err + } + return out, err +} + type GetChangeResponse struct { ChangeInfo ChangeInfo `xml:"ChangeInfo"` } From a910f06ad1dccc22538971e67690759f103b3915 Mon Sep 17 00:00:00 2001 From: sawanoboly Date: Wed, 15 Apr 2015 02:37:37 +0900 Subject: [PATCH 2/3] add test for route53.ListHostedZonesByName --- route53/responses_test.go | 30 ++++++++++++++++++++++++++++++ route53/route53_test.go | 19 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/route53/responses_test.go b/route53/responses_test.go index 0844b462..7c1c0b73 100644 --- a/route53/responses_test.go +++ b/route53/responses_test.go @@ -120,3 +120,33 @@ var ListHostedZonesExample = ` false 100 ` + +var ListHostedZonesByNameExample = ` + + + + /hostedzone/Z222222VVVVVVV + example2.com. + MyUniqueIdentifier2 + + This is my second hosted zone. + false + + 17 + + + /hostedzone/Z2682N5HXP0BZ4 + example3.com. + MyUniqueIdentifier3 + + This is my third hosted zone. + false + + 117 + + + example2.com + Z222222VVVVVVV + false + 2 +` diff --git a/route53/route53_test.go b/route53/route53_test.go index 092c8174..a2072a1d 100644 --- a/route53/route53_test.go +++ b/route53/route53_test.go @@ -176,6 +176,25 @@ func TestListHostedZones(t *testing.T) { } } +func TestListHostedZonesByName(t *testing.T) { + testServer := makeTestServer() + client := makeClient(testServer) + testServer.Response(200, nil, ListHostedZonesByNameExample) + + resp, err := client.ListHostedZonesByName("example2.com", "Z2682N5HXP0BZ4", 0) + if err != nil { + t.Fatalf("err: %v", err) + } + + if resp.HostedZones[0].Name != "example2.com." { + t.Fatalf("bad: %v", resp) + } + + if resp.HostedZones[1].Name != "example3.com." { + t.Fatalf("bad: %v", resp) + } +} + func decode(t *testing.T, r io.Reader, out interface{}) { var buf1 bytes.Buffer var buf2 bytes.Buffer From 649dda62a4be4cc3be8a62975e6cb88ef99d152a Mon Sep 17 00:00:00 2001 From: sawanoboly Date: Wed, 15 Apr 2015 02:47:43 +0900 Subject: [PATCH 3/3] use downcase to query keys --- route53/route53.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/route53/route53.go b/route53/route53.go index 9df76d7a..8ca68233 100644 --- a/route53/route53.go +++ b/route53/route53.go @@ -262,7 +262,7 @@ func (r *Route53) ListHostedZonesByName(dnsName string, hostedZoneId string, max } if hostedZoneId != "" { - values.Add("Hostedzoneid", hostedZoneId) + values.Add("hostedzoneid", hostedZoneId) } if maxItems != 0 {