From 41864a3bce65faa32ac62b269ffa0b04b5e083e9 Mon Sep 17 00:00:00 2001 From: Ernesto Ruy Sanchez Date: Fri, 9 Jan 2015 12:42:24 -0800 Subject: [PATCH 1/2] Added support to create private hosted zones on Route53 Issue #197 --- route53/route53.go | 67 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 9 deletions(-) diff --git a/route53/route53.go b/route53/route53.go index 92d623f6..14c71021 100644 --- a/route53/route53.go +++ b/route53/route53.go @@ -35,26 +35,57 @@ func NewWithClient(auth aws.Auth, region aws.Region, httpClient *http.Client) *R return &Route53{auth, region, httpClient} } -type CreateHostedZoneRequest struct { +type CreatePublicHostedZoneRequest struct { Name string `xml:"Name"` CallerReference string `xml:"CallerReference"` Comment string `xml:"HostedZoneConfig>Comment"` } -type CreateHostedZoneResponse struct { - HostedZone HostedZone `xml:"HostedZone"` - ChangeInfo ChangeInfo `xml:"ChangeInfo"` - DelegationSet DelegationSet `xml:"DelegationSet"` +type CreatePublicHostedZoneResponse struct { + PublicHostedZone PublicHostedZone `xml:"HostedZone"` + ChangeInfo ChangeInfo `xml:"ChangeInfo"` + DelegationSet DelegationSet `xml:"DelegationSet"` +} + +type CreatePrivateHostedZoneRequest struct { + Name string `xml:"Name"` + VPCId string `xml:"VPC>VPCId"` + VPCRegion string `xml:"VPC>VPCRegion"` + CallerReference string `xml:"CallerReference"` + Comment string `xml:"HostedZoneConfig>Comment"` +} + +type CreatePrivateHostedZoneResponse struct { + PrivateHostedZone PrivateHostedZone `xml:"HostedZone"` + VPC VPC `xml:"VPC"` + ChangeInfo ChangeInfo `xml:"ChangeInfo"` +} + +type PublicHostedZone struct { + ID string `xml:"Id"` + Name string `xml:"Name"` + CallerReference string `xml:"CallerReference"` + Comment string `xml:"Config>Comment"` + PrivateZone string `xml:"Config>PrivateZone"` + ResourceCount int `xml:"ResourceRecordSetCount"` } -type HostedZone struct { +type PrivateHostedZone struct { ID string `xml:"Id"` Name string `xml:"Name"` CallerReference string `xml:"CallerReference"` + VPCId string `xml:"VPC>VPCId"` + VPCRegion string `xml:"VPC>VPCRegion"` Comment string `xml:"Config>Comment"` + PrivateZone string `xml:"Config>PrivateZone"` ResourceCount int `xml:"ResourceRecordSetCount"` } +type VPC struct { + VPCId string `xml:"VPC>VPCId"` + VPCRegion string `xml:"VPC>VPCRegion"` +} + type ChangeInfo struct { ID string `xml:"Id"` Status string `xml:"Status"` @@ -158,13 +189,31 @@ func multimap(p map[string]string) url.Values { return q } -// CreateHostedZone is used to create a new hosted zone -func (r *Route53) CreateHostedZone(req *CreateHostedZoneRequest) (*CreateHostedZoneResponse, error) { +// CreateHostedZone is kept for backwards compatibility +func (r *Route53) CreateHostedZone(req *CreatePublicHostedZoneRequest) (*CreatePublicHostedZoneResponse, error) { + return CreatePublicHostedZone(req) +} + +// CreatePublicHostedZone is used to create a new hosted zone +func (r *Route53) CreatePublicHostedZone(req *CreatePublicHostedZoneRequest) (*CreatePublicHostedZoneResponse, error) { + // Generate a unique caller reference if none provided + if req.CallerReference == "" { + req.CallerReference = time.Now().Format(time.RFC3339Nano) + } + out := &CreatePublicHostedZoneResponse{} + if err := r.query("POST", fmt.Sprintf("/%s/hostedzone", APIVersion), req, out); err != nil { + return nil, err + } + return out, nil +} + +// CreatePrivateHostedZone is used to create a new hosted zone +func (r *Route53) CreatePrivateHostedZone(req *CreatePrivateHostedZoneRequest) (*CreatePrivateHostedZoneResponse, error) { // Generate a unique caller reference if none provided if req.CallerReference == "" { req.CallerReference = time.Now().Format(time.RFC3339Nano) } - out := &CreateHostedZoneResponse{} + out := &CreatePublicHostedZoneResponse{} if err := r.query("POST", fmt.Sprintf("/%s/hostedzone", APIVersion), req, out); err != nil { return nil, err } From 9038248d0c15962c4dcec1f231488e7ed9ed6885 Mon Sep 17 00:00:00 2001 From: Ernesto Ruy Sanchez Date: Fri, 9 Jan 2015 12:53:15 -0800 Subject: [PATCH 2/2] Added HosedZone back for backwards compatibility --- route53/route53.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/route53/route53.go b/route53/route53.go index 14c71021..6fc013e7 100644 --- a/route53/route53.go +++ b/route53/route53.go @@ -61,6 +61,17 @@ type CreatePrivateHostedZoneResponse struct { ChangeInfo ChangeInfo `xml:"ChangeInfo"` } +// kept for backwards compatibility +type HostedZone struct { + ID string `xml:"Id"` + Name string `xml:"Name"` + CallerReference string `xml:"CallerReference"` + Comment string `xml:"Config>Comment"` + PrivateZone string `xml:"Config>PrivateZone"` + ResourceCount int `xml:"ResourceRecordSetCount"` +} + + type PublicHostedZone struct { ID string `xml:"Id"` Name string `xml:"Name"`