diff --git a/aws/version.go b/aws/version.go index 11457ac..97a3f57 100755 --- a/aws/version.go +++ b/aws/version.go @@ -5,4 +5,4 @@ package aws const SDKName = "aws-sdk-go" // SDKVersion is the version of this SDK -const SDKVersion = "1.2.3" +const SDKVersion = "1.2.5" diff --git a/internal/protocol/rest/payload.go b/internal/protocol/rest/payload.go index e4e865e..c4ce64a 100755 --- a/internal/protocol/rest/payload.go +++ b/internal/protocol/rest/payload.go @@ -38,6 +38,9 @@ func PayloadType(i interface{}) string { } if field, ok := v.Type().FieldByName("SDKShapeTraits"); ok { if payloadName := field.Tag.Get("payload"); payloadName != "" { + if payloadName == "GetBucketCORSInput" { + return field.Tag.Get("type") + } if member, ok := v.Type().FieldByName(payloadName); ok { return member.Tag.Get("type") } diff --git a/internal/protocol/restxml/restxml.go b/internal/protocol/restxml/restxml.go index b0f1689..ecf912a 100755 --- a/internal/protocol/restxml/restxml.go +++ b/internal/protocol/restxml/restxml.go @@ -14,6 +14,7 @@ import ( "github.com/ks3sdklib/aws-sdk-go/internal/protocol/query" "github.com/ks3sdklib/aws-sdk-go/internal/protocol/rest" "github.com/ks3sdklib/aws-sdk-go/internal/protocol/xml/xmlutil" + "io/ioutil" ) // Build builds a request payload for the REST XML protocol. @@ -39,15 +40,38 @@ func Build(r *aws.Request) { func Unmarshal(r *aws.Request) { if t := rest.PayloadType(r.Data); t == "structure" || t == "" { defer r.HTTPResponse.Body.Close() - decoder := xml.NewDecoder(r.HTTPResponse.Body) - err := xmlutil.UnmarshalXML(r.Data, decoder, "") + data, err := ioutil.ReadAll(r.HTTPResponse.Body) + if err != nil { + r.Error = apierr.New("ReadBody", "failed to read response body", err) + return + } + decoder := xml.NewDecoder(bytes.NewReader(data)) + err = xmlutil.UnmarshalXML(r.Data, decoder, "") if err != nil { r.Error = apierr.New("Unmarshal", "failed to decode REST XML response", err) return } + return } } +type GetBucketCORSOutput struct { + CORSConfiguration *CORSConfiguration `xml:"CORSConfiguration"` + Metadata map[string]*string `xml:"-"` +} + +type CORSConfiguration struct { + Rules []*CORSRule `xml:"CORSRule"` +} + +type CORSRule struct { + AllowedHeader []string `xml:"AllowedHeader"` + AllowedMethod []string `xml:"AllowedMethod"` + AllowedOrigin []string `xml:"AllowedOrigin"` + ExposeHeader []string `xml:"ExposeHeader"` + MaxAgeSeconds int `xml:"MaxAgeSeconds"` +} + // UnmarshalMeta unmarshals response headers for the REST XML protocol. func UnmarshalMeta(r *aws.Request) { rest.Unmarshal(r) diff --git a/service/s3/cors.go b/service/s3/cors.go index d3d01d9..c95563d 100644 --- a/service/s3/cors.go +++ b/service/s3/cors.go @@ -31,6 +31,9 @@ func (c *S3) GetBucketCORSRequest(input *GetBucketCORSInput) (req *aws.Request, func (c *S3) GetBucketCORS(input *GetBucketCORSInput) (*GetBucketCORSOutput, error) { req, out := c.GetBucketCORSRequest(input) err := req.Send() + if req.Data != nil { + out = req.Data.(*GetBucketCORSOutput) + } return out, err } @@ -114,16 +117,6 @@ type metadataPutBucketCORSInput struct { AutoFillMD5 bool } -type PutBucketCORSOutput struct { - metadataPutBucketCORSOutput `json:"-" xml:"-"` - - Metadata map[string]*string `location:"headers" type:"map"` -} - -type metadataPutBucketCORSOutput struct { - SDKShapeTraits bool `type:"structure"` -} - type GetBucketCORSInput struct { Bucket *string `location:"uri" locationName:"Bucket" type:"string" required:"true"` @@ -137,19 +130,34 @@ type metadataInput struct { } type GetBucketCORSOutput struct { - CORSRules []*CORSRule `locationName:"CORSRule" type:"list" flattened:"true"` - metadataInput `json:"-" xml:"-"` - Metadata map[string]*string `location:"headers" type:"map"` + Metadata map[string]*string `location:"headers" type:"map"` + Rules []*GetCORSRule `locationName:"CORSRule" type:"list" flattened:"true" xml:"CORSRule"` +} +type GetCORSRule struct { + AllowedHeader []*string `locationName:"AllowedHeader" type:"list" flattened:"true" ` + AllowedMethod []*string `locationName:"AllowedMethod" type:"list" flattened:"true"` + AllowedOrigin []*string `locationName:"AllowedOrigin" type:"list" flattened:"true"` + ExposeHeader []*string `locationName:"ExposeHeader" type:"list" flattened:"true"` + MaxAgeSeconds *int64 `locationName:"MaxAgeSeconds" flattened:"true"` // Max cache ages in seconds } - type CORSConfiguration struct { - Rules []*CORSRule `locationName:"CORSRule" type:"list" flattened:"true"` // CORS rules + Rules []*CORSRule `locationName:"CORSRule" type:"list" flattened:"true" xml:"CORSRule"` +} + +type PutBucketCORSOutput struct { + metadataPutBucketCORSOutput `json:"-" xml:"-"` + + Metadata map[string]*string `location:"headers" type:"map"` +} + +type metadataPutBucketCORSOutput struct { + SDKShapeTraits bool `type:"structure"` } type CORSRule struct { - AllowedHeader []string `locationName:"AllowedHeader" type:"list" flattened:"true" ` + AllowedHeader []string `locationName:"AllowedHeader" type:"list" flattened:"true"` AllowedMethod []string `locationName:"AllowedMethod" type:"list" flattened:"true"` AllowedOrigin []string `locationName:"AllowedOrigin" type:"list" flattened:"true"` ExposeHeader []string `locationName:"ExposeHeader" type:"list" flattened:"true"` - MaxAgeSeconds int `locationName:"MaxAgeSeconds" flattened:"true"` // Max cache ages in seconds + MaxAgeSeconds int64 `locationName:"MaxAgeSeconds" flattened:"true"` // Max cache ages in seconds } diff --git a/test/bucketsample_test.go b/test/bucketsample_test.go index 60c3aa9..89542c8 100644 --- a/test/bucketsample_test.go +++ b/test/bucketsample_test.go @@ -104,7 +104,7 @@ func (s *Ks3utilCommandSuite) TestDeleteBucketLifeRules(c *C) { } //设置bucket cors -func (s *Ks3utilCommandSuite) TestSetBucketCors() { +func (s *Ks3utilCommandSuite) TestSetBucketCors(c *C) { // 配置CORS规则 corsConfiguration := &s3.CORSConfiguration{ @@ -138,6 +138,8 @@ func (s *Ks3utilCommandSuite) TestGetBucketCors(c *C) { }) fmt.Println("结果:\n", awsutil.StringValue(resp), err) } + +//删除bucket cors func (s *Ks3utilCommandSuite) TestDeleteBucketCors(c *C) { resp, err := client.DeleteBucketCORS(&s3.DeleteBucketCORSInput{ Bucket: aws.String(bucket),