Update Go AWS SDK to the latest version

This commit is contained in:
Andrey Smirnov
2019-07-13 00:03:55 +03:00
committed by Andrey Smirnov
parent d08be990ef
commit 94a72b23ff
2183 changed files with 885887 additions and 228114 deletions
+1178 -796
View File
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -33,7 +33,7 @@ func sanitizeURL(r *request.Request) {
// Update Path so that it reflects the cleaned RawPath
updated, err := url.Parse(r.HTTPRequest.URL.RawPath)
if err != nil {
r.Error = awserr.New("SerializationError", "failed to clean Route53 URL", err)
r.Error = awserr.New(request.ErrCodeSerialization, "failed to clean Route53 URL", err)
return
}
+3
View File
@@ -3,6 +3,9 @@
// Package route53 provides the client and types for making API
// requests to Amazon Route 53.
//
// Amazon Route 53 is a highly available and scalable Domain Name System (DNS)
// web service.
//
// See https://docs.aws.amazon.com/goto/WebAPI/route53-2013-04-01 for more information on this service.
//
// See route53 package documentation for more information.
+25 -23
View File
@@ -23,7 +23,7 @@ const (
// the same name as an existing hosted zone or that's the parent or child
// of an existing hosted zone, and you specified a delegation set that shares
// one or more name servers with the existing hosted zone. For more information,
// see CreateReusableDelegationSet.
// see CreateReusableDelegationSet (https://docs.aws.amazon.com/Route53/latest/APIReference/API_CreateReusableDelegationSet.html).
//
// * Private hosted zone: You specified an Amazon VPC that you're already
// using for another hosted zone, and the domain that you specified for one
@@ -66,8 +66,8 @@ const (
// You can create a hosted zone that has the same name as an existing hosted
// zone (example.com is common), but there is a limit to the number of hosted
// zones that have the same name. If you get this error, Amazon Route 53 has
// reached that limit. If you own the domain name and Amazon Route 53 generates
// this error, contact Customer Support.
// reached that limit. If you own the domain name and Route 53 generates this
// error, contact Customer Support.
ErrCodeDelegationSetNotAvailable = "DelegationSetNotAvailable"
// ErrCodeDelegationSetNotReusable for service response error code
@@ -212,8 +212,9 @@ const (
// reached the limit on reusable delegation sets that it can create or because
// you've reached the limit on the number of Amazon VPCs that you can associate
// with a private hosted zone. To get the current limit on the number of reusable
// delegation sets, see GetAccountLimit. To get the current limit on the number
// of Amazon VPCs that you can associate with a private hosted zone, see GetHostedZoneLimit.
// delegation sets, see GetAccountLimit (https://docs.aws.amazon.com/Route53/latest/APIReference/API_GetAccountLimit.html).
// To get the current limit on the number of Amazon VPCs that you can associate
// with a private hosted zone, see GetHostedZoneLimit (https://docs.aws.amazon.com/Route53/latest/APIReference/API_GetHostedZoneLimit.html).
// To request a higher limit, create a case (http://aws.amazon.com/route53-request)
// with the AWS Support Center.
ErrCodeLimitsExceeded = "LimitsExceeded"
@@ -239,14 +240,13 @@ const (
// ErrCodeNoSuchGeoLocation for service response error code
// "NoSuchGeoLocation".
//
// Amazon Route 53 doesn't support the specified geolocation.
// Amazon Route 53 doesn't support the specified geographic location.
ErrCodeNoSuchGeoLocation = "NoSuchGeoLocation"
// ErrCodeNoSuchHealthCheck for service response error code
// "NoSuchHealthCheck".
//
// No health check exists with the ID that you specified in the DeleteHealthCheck
// request.
// No health check exists with the specified ID.
ErrCodeNoSuchHealthCheck = "NoSuchHealthCheck"
// ErrCodeNoSuchHostedZone for service response error code
@@ -285,8 +285,8 @@ const (
//
// If Amazon Route 53 can't process a request before the next request arrives,
// it will reject subsequent requests for the same hosted zone and return an
// HTTP 400 error (Bad request). If Amazon Route 53 returns this error repeatedly
// for the same request, we recommend that you wait, in intervals of increasing
// HTTP 400 error (Bad request). If Route 53 returns this error repeatedly for
// the same request, we recommend that you wait, in intervals of increasing
// duration, before you try the request again.
ErrCodePriorRequestNotComplete = "PriorRequestNotComplete"
@@ -316,10 +316,11 @@ const (
// This health check can't be created because the current account has reached
// the limit on the number of active health checks.
//
// For information about default limits, see Limits (http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/DNSLimitations.html)
// For information about default limits, see Limits (https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/DNSLimitations.html)
// in the Amazon Route 53 Developer Guide.
//
// For information about how to get the current limit for an account, see GetAccountLimit.
// For information about how to get the current limit for an account, see GetAccountLimit
// (https://docs.aws.amazon.com/Route53/latest/APIReference/API_GetAccountLimit.html).
// To request a higher limit, create a case (http://aws.amazon.com/route53-request)
// with the AWS Support Center.
//
@@ -336,14 +337,14 @@ const (
// the limit on the number of hosted zones that can be associated with a reusable
// delegation set.
//
// For information about default limits, see Limits (http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/DNSLimitations.html)
// For information about default limits, see Limits (https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/DNSLimitations.html)
// in the Amazon Route 53 Developer Guide.
//
// To get the current limit on hosted zones that can be created by an account,
// see GetAccountLimit.
// see GetAccountLimit (https://docs.aws.amazon.com/Route53/latest/APIReference/API_GetAccountLimit.html).
//
// To get the current limit on hosted zones that can be associated with a reusable
// delegation set, see GetReusableDelegationSetLimit.
// delegation set, see GetReusableDelegationSetLimit (https://docs.aws.amazon.com/Route53/latest/APIReference/API_GetReusableDelegationSetLimit.html).
//
// To request a higher limit, create a case (http://aws.amazon.com/route53-request)
// with the AWS Support Center.
@@ -355,10 +356,10 @@ const (
// This traffic policy can't be created because the current account has reached
// the limit on the number of traffic policies.
//
// For information about default limits, see Limits (http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/DNSLimitations.html)
// For information about default limits, see Limits (https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/DNSLimitations.html)
// in the Amazon Route 53 Developer Guide.
//
// To get the current limit for an account, see GetAccountLimit.
// To get the current limit for an account, see GetAccountLimit (https://docs.aws.amazon.com/Route53/latest/APIReference/API_GetAccountLimit.html).
//
// To request a higher limit, create a case (http://aws.amazon.com/route53-request)
// with the AWS Support Center.
@@ -370,10 +371,11 @@ const (
// This traffic policy instance can't be created because the current account
// has reached the limit on the number of traffic policy instances.
//
// For information about default limits, see Limits (http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/DNSLimitations.html)
// For information about default limits, see Limits (https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/DNSLimitations.html)
// in the Amazon Route 53 Developer Guide.
//
// For information about how to get the current limit for an account, see GetAccountLimit.
// For information about how to get the current limit for an account, see GetAccountLimit
// (https://docs.aws.amazon.com/Route53/latest/APIReference/API_GetAccountLimit.html).
//
// To request a higher limit, create a case (http://aws.amazon.com/route53-request)
// with the AWS Support Center.
@@ -386,10 +388,10 @@ const (
// of 1000 on the number of versions that you can create for the current traffic
// policy.
//
// To create more traffic policy versions, you can use GetTrafficPolicy to get
// the traffic policy document for a specified traffic policy version, and then
// use CreateTrafficPolicy to create a new traffic policy using the traffic
// policy document.
// To create more traffic policy versions, you can use GetTrafficPolicy (https://docs.aws.amazon.com/Route53/latest/APIReference/API_GetTrafficPolicy.html)
// to get the traffic policy document for a specified traffic policy version,
// and then use CreateTrafficPolicy (https://docs.aws.amazon.com/Route53/latest/APIReference/API_CreateTrafficPolicy.html)
// to create a new traffic policy using the traffic policy document.
ErrCodeTooManyTrafficPolicyVersionsForCurrentPolicy = "TooManyTrafficPolicyVersionsForCurrentPolicy"
// ErrCodeTooManyVPCAssociationAuthorizations for service response error code
+58
View File
@@ -0,0 +1,58 @@
// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
// +build go1.10,integration
package route53_test
import (
"context"
"testing"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/awstesting/integration"
"github.com/aws/aws-sdk-go/service/route53"
)
var _ aws.Config
var _ awserr.Error
var _ request.Request
func TestInteg_00_ListHostedZones(t *testing.T) {
ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
defer cancelFn()
sess := integration.SessionWithDefaultRegion("us-east-1")
svc := route53.New(sess)
params := &route53.ListHostedZonesInput{}
_, err := svc.ListHostedZonesWithContext(ctx, params)
if err != nil {
t.Errorf("expect no error, got %v", err)
}
}
func TestInteg_01_GetHostedZone(t *testing.T) {
ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
defer cancelFn()
sess := integration.SessionWithDefaultRegion("us-east-1")
svc := route53.New(sess)
params := &route53.GetHostedZoneInput{
Id: aws.String("fake-zone"),
}
_, err := svc.GetHostedZoneWithContext(ctx, params)
if err == nil {
t.Fatalf("expect request to fail")
}
aerr, ok := err.(awserr.RequestFailure)
if !ok {
t.Fatalf("expect awserr, was %T", err)
}
if len(aerr.Code()) == 0 {
t.Errorf("expect non-empty error code")
}
if v := aerr.Code(); v == request.ErrCodeSerialization {
t.Errorf("expect API error code got serialization failure")
}
}
+4 -2
View File
@@ -29,8 +29,9 @@ var initRequest func(*request.Request)
// Service information constants
const (
ServiceName = "route53" // Service endpoint prefix API calls made to.
EndpointsID = ServiceName // Service ID for Regions and Endpoints metadata.
ServiceName = "route53" // Name of service.
EndpointsID = ServiceName // ID to lookup a service endpoint with.
ServiceID = "Route 53" // ServiceID is a unique identifer of a specific service.
)
// New creates a new instance of the Route53 client with a session.
@@ -55,6 +56,7 @@ func newClient(cfg aws.Config, handlers request.Handlers, endpoint, signingRegio
cfg,
metadata.ClientInfo{
ServiceName: ServiceName,
ServiceID: ServiceID,
SigningName: signingName,
SigningRegion: signingRegion,
Endpoint: endpoint,
+76 -47
View File
@@ -1,77 +1,106 @@
package route53
import (
"bytes"
"encoding/xml"
"io/ioutil"
"fmt"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/private/protocol/restxml"
"github.com/aws/aws-sdk-go/private/protocol/xml/xmlutil"
)
type baseXMLErrorResponse struct {
XMLName xml.Name
}
const errorRespTag = "ErrorResponse"
const invalidChangeTag = "InvalidChangeBatch"
type standardXMLErrorResponse struct {
XMLName xml.Name `xml:"ErrorResponse"`
Code string `xml:"Error>Code"`
Message string `xml:"Error>Message"`
RequestID string `xml:"RequestId"`
Code string `xml:"Error>Code"`
Message string `xml:"Error>Message"`
RequestID string `xml:"RequestId"`
}
func (e standardXMLErrorResponse) FillCommon(c *xmlErrorResponse) {
c.Code = e.Code
c.Message = e.Message
c.RequestID = e.RequestID
}
type invalidChangeBatchXMLErrorResponse struct {
XMLName xml.Name `xml:"InvalidChangeBatch"`
Messages []string `xml:"Messages>Message"`
Messages []string `xml:"Messages>Message"`
RequestID string `xml:"RequestId"`
}
func (e invalidChangeBatchXMLErrorResponse) FillCommon(c *xmlErrorResponse) {
c.Code = invalidChangeTag
c.Message = "ChangeBatch errors occurred"
c.Messages = e.Messages
c.RequestID = e.RequestID
}
type xmlErrorResponse struct {
Code string
Message string
Messages []string
RequestID string
}
func (e *xmlErrorResponse) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
type commonFiller interface {
FillCommon(*xmlErrorResponse)
}
var errResp commonFiller
switch start.Name.Local {
case errorRespTag:
errResp = &standardXMLErrorResponse{}
case invalidChangeTag:
errResp = &invalidChangeBatchXMLErrorResponse{}
default:
return fmt.Errorf("unknown error message, %v", start.Name.Local)
}
if err := d.DecodeElement(errResp, &start); err != nil {
return err
}
errResp.FillCommon(e)
return nil
}
func unmarshalChangeResourceRecordSetsError(r *request.Request) {
defer r.HTTPResponse.Body.Close()
responseBody, err := ioutil.ReadAll(r.HTTPResponse.Body)
var errResp xmlErrorResponse
err := xmlutil.UnmarshalXMLError(&errResp, r.HTTPResponse.Body)
if err != nil {
r.Error = awserr.New("SerializationError", "failed to read Route53 XML error response", err)
r.Error = awserr.NewRequestFailure(
awserr.New(request.ErrCodeSerialization,
"failed to unmarshal error message", err),
r.HTTPResponse.StatusCode,
r.RequestID,
)
return
}
baseError := &baseXMLErrorResponse{}
if err := xml.Unmarshal(responseBody, baseError); err != nil {
r.Error = awserr.New("SerializationError", "failed to decode Route53 XML error response", err)
return
var baseErr awserr.Error
if len(errResp.Messages) != 0 {
var errs []error
for _, msg := range errResp.Messages {
errs = append(errs, awserr.New(invalidChangeTag, msg, nil))
}
baseErr = awserr.NewBatchError(errResp.Code, errResp.Message, errs)
} else {
baseErr = awserr.New(errResp.Code, errResp.Message, nil)
}
switch baseError.XMLName.Local {
case "InvalidChangeBatch":
unmarshalInvalidChangeBatchError(r, responseBody)
default:
r.HTTPResponse.Body = ioutil.NopCloser(bytes.NewReader(responseBody))
restxml.UnmarshalError(r)
reqID := errResp.RequestID
if len(reqID) == 0 {
reqID = r.RequestID
}
}
func unmarshalInvalidChangeBatchError(r *request.Request, requestBody []byte) {
resp := &invalidChangeBatchXMLErrorResponse{}
err := xml.Unmarshal(requestBody, resp)
if err != nil {
r.Error = awserr.New("SerializationError", "failed to decode query XML error response", err)
return
}
const errorCode = "InvalidChangeBatch"
errors := []error{}
for _, msg := range resp.Messages {
errors = append(errors, awserr.New(errorCode, msg, nil))
}
r.Error = awserr.NewRequestFailure(
awserr.NewBatchError(errorCode, "ChangeBatch errors occurred", errors),
baseErr,
r.HTTPResponse.StatusCode,
r.RequestID,
reqID,
)
}
+85 -102
View File
@@ -1,130 +1,113 @@
package route53_test
// +build go1.8
package route53
import (
"bytes"
"io/ioutil"
"net/http"
"strings"
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/awstesting/unit"
"github.com/aws/aws-sdk-go/service/route53"
)
func makeClientWithResponse(response string) *route53.Route53 {
r := route53.New(unit.Session)
r.Handlers.Send.Clear()
r.Handlers.Send.PushBack(func(r *request.Request) {
body := ioutil.NopCloser(bytes.NewReader([]byte(response)))
r.HTTPResponse = &http.Response{
ContentLength: int64(len(response)),
StatusCode: 400,
Status: "Bad Request",
Body: body,
}
})
return r
}
func TestUnmarshalStandardError(t *testing.T) {
const errorResponse = `<?xml version="1.0" encoding="UTF-8"?>
<ErrorResponse xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
<Error>
<Code>InvalidDomainName</Code>
<Message>The domain name is invalid</Message>
</Error>
<RequestId>12345</RequestId>
</ErrorResponse>
`
r := makeClientWithResponse(errorResponse)
_, err := r.CreateHostedZone(&route53.CreateHostedZoneInput{
CallerReference: aws.String("test"),
Name: aws.String("test_zone"),
})
if err == nil {
t.Error("expected error, but received none")
}
if e, a := "InvalidDomainName", err.(awserr.Error).Code(); e != a {
t.Errorf("expected %s, but received %s", e, a)
}
if e, a := "The domain name is invalid", err.(awserr.Error).Message(); e != a {
t.Errorf("expected %s, but received %s", e, a)
}
}
func TestUnmarshalInvalidChangeBatch(t *testing.T) {
const errorMessage = `
Tried to create resource record set duplicate.example.com. type A,
but it already exists
`
const errorResponse = `<?xml version="1.0" encoding="UTF-8"?>
type batchError struct {
Code, Message string
}
cases := map[string]struct {
Request *request.Request
Code, Message, RequestID string
StatusCode int
BatchErrors []batchError
}{
"standard error": {
Request: &request.Request{
HTTPResponse: &http.Response{
StatusCode: 400,
Header: http.Header{},
Body: ioutil.NopCloser(strings.NewReader(
`<?xml version="1.0" encoding="UTF-8"?>
<ErrorResponse xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
<Error>
<Code>InvalidDomainName</Code>
<Message>The domain name is invalid</Message>
</Error>
<RequestId>12345</RequestId>
</ErrorResponse>`)),
},
},
Code: "InvalidDomainName", Message: "The domain name is invalid",
StatusCode: 400, RequestID: "12345",
},
"batched error": {
Request: &request.Request{
HTTPResponse: &http.Response{
StatusCode: 400,
Header: http.Header{},
Body: ioutil.NopCloser(strings.NewReader(
`<?xml version="1.0" encoding="UTF-8"?>
<InvalidChangeBatch xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
<Messages>
<Message>` + errorMessage + `</Message>
<Message>` + errorMessage + `</Message>
</Messages>
</InvalidChangeBatch>
`
r := makeClientWithResponse(errorResponse)
req := &route53.ChangeResourceRecordSetsInput{
HostedZoneId: aws.String("zoneId"),
ChangeBatch: &route53.ChangeBatch{
Changes: []*route53.Change{
{
Action: aws.String("CREATE"),
ResourceRecordSet: &route53.ResourceRecordSet{
Name: aws.String("domain"),
Type: aws.String("CNAME"),
TTL: aws.Int64(120),
ResourceRecords: []*route53.ResourceRecord{
{
Value: aws.String("cname"),
},
},
},
<RequestId>12345</RequestId>
</InvalidChangeBatch>`)),
},
},
Code: "InvalidChangeBatch", Message: "ChangeBatch errors occurred",
StatusCode: 400, RequestID: "12345",
BatchErrors: []batchError{
{Code: "InvalidChangeBatch", Message: errorMessage},
},
},
}
_, err := r.ChangeResourceRecordSets(req)
if err == nil {
t.Error("expected error, but received none")
}
for name, c := range cases {
t.Run(name, func(t *testing.T) {
unmarshalChangeResourceRecordSetsError(c.Request)
err := c.Request.Error
if err == nil {
t.Error("expected error, but received none")
}
if reqErr, ok := err.(awserr.RequestFailure); ok {
if reqErr == nil {
t.Error("expected error, but received none")
}
reqErr := err.(awserr.RequestFailure)
if e, a := c.StatusCode, reqErr.StatusCode(); e != a {
t.Errorf("expected %d status, got %d", e, a)
}
if e, a := c.Code, reqErr.Code(); e != a {
t.Errorf("expected %v code, got %v", e, a)
}
if e, a := c.Message, reqErr.Message(); e != a {
t.Errorf("expected %q message, got %q", e, a)
}
if e, a := c.RequestID, reqErr.RequestID(); e != a {
t.Errorf("expected %v request ID, got %v", e, a)
}
if e, a := 400, reqErr.StatusCode(); e != a {
t.Errorf("expected %d, but received %d", e, a)
}
} else {
t.Fatal("returned error is not a RequestFailure")
}
batchErr := err.(awserr.BatchedErrors)
batchedErrs := batchErr.OrigErrs()
if batchErr, ok := err.(awserr.BatchedErrors); ok {
errs := batchErr.OrigErrs()
if e, a := 1, len(errs); e != a {
t.Errorf("expected %d, but received %d", e, a)
}
if e, a := "InvalidChangeBatch", errs[0].(awserr.Error).Code(); e != a {
t.Errorf("expected %s, but received %s", e, a)
}
if e, a := errorMessage, errs[0].(awserr.Error).Message(); e != a {
t.Errorf("expected %s, but received %s", e, a)
}
} else {
t.Fatal("returned error is not a BatchedErrors")
if e, a := len(c.BatchErrors), len(batchedErrs); e != a {
t.Fatalf("expect %v batch errors, got %v", e, a)
}
for i, ee := range c.BatchErrors {
bErr := batchedErrs[i].(awserr.Error)
if e, a := ee.Code, bErr.Code(); e != a {
t.Errorf("expect %v code, got %v", e, a)
}
if e, a := ee.Message, bErr.Message(); e != a {
t.Errorf("expect %v message, got %v", e, a)
}
}
})
}
}