From 552ffa213ef9b27e59db9bc2715d5c9e5c8efe5a Mon Sep 17 00:00:00 2001 From: skotambkar Date: Wed, 11 Dec 2019 13:26:21 -0800 Subject: [PATCH] adds suggested changes --- .../internal/awsrestjson/marshal.go | 22 +++++++------ service/s3/internal/awsrestxml/marshal.go | 32 ++++++++++--------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/service/apigateway/internal/awsrestjson/marshal.go b/service/apigateway/internal/awsrestjson/marshal.go index 50e4a114c66..143ce5f79db 100644 --- a/service/apigateway/internal/awsrestjson/marshal.go +++ b/service/apigateway/internal/awsrestjson/marshal.go @@ -1,12 +1,12 @@ package awsrestjson import ( - "log" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/private/protocol/jsonrpc" - "github.com/aws/aws-sdk-go-v2/private/protocol/rest" - v2 "github.com/aws/aws-sdk-go-v2/private/protocol/rest/v2" + restlegacy "github.com/aws/aws-sdk-go-v2/private/protocol/rest" + restV2 "github.com/aws/aws-sdk-go-v2/private/protocol/rest/v2" "github.com/aws/aws-sdk-go-v2/service/apigateway/types" ) @@ -19,40 +19,44 @@ type ProtoGetAPIKeyMarshaler struct { // This method calls appropriate marshal shape functions as per the input shape and protocol used by the service. func (m ProtoGetAPIKeyMarshaler) MarshalOperation(r *aws.Request) { var err error - encoder := v2.NewEncoder(r.HTTPRequest) + encoder := restV2.NewEncoder(r.HTTPRequest) // adds content-type header encoder.AddHeader("Content-Type").String("application/json") err = MarshalGetAPIKeyInputShapeAWSREST(m.Input, encoder) if err != nil { r.Error = err + return } + encoder.Encode() + // Todo Instead of passing aws.Request directly to MarshalGetAPIKeyInputShapeAWSJSON; + // we should pass the payload as an argument err = MarshalGetAPIKeyInputShapeAWSJSON(m.Input, r) if err != nil { r.Error = err + return } } // MarshalGetAPIKeyInputShapeAWSREST is a stand alone function used to marshal the HTTP bindings a input shape. // This method uses the rest encoder utility -func MarshalGetAPIKeyInputShapeAWSREST(input *types.GetApiKeyInput, encoder *v2.Encoder) error { +func MarshalGetAPIKeyInputShapeAWSREST(input *types.GetApiKeyInput, encoder *restV2.Encoder) error { // encode using rest encoder utility if err := encoder.SetURI("api_Key").String(*input.ApiKey); err != nil { - log.Fatalf("Failed to marshal API KEY to URI using REST encoder:\n \t %v", err.Error()) + return fmt.Errorf("failed to marshal API KEY to URI using REST encoder:\n \t %v", err.Error()) } encoder.AddQuery("includeValue").Boolean(*input.IncludeValue) - encoder.Encode() return nil } // MarshalGetAPIKeyInputShapeAWSJSON is a stand alone function used to marshal the json body func MarshalGetAPIKeyInputShapeAWSJSON(v *types.GetApiKeyInput, r *aws.Request) error { // delegate to reflection based marshaling - if t := rest.PayloadType(r.Params); t == "structure" || t == "" { + if t := restlegacy.PayloadType(r.Params); t == "structure" || t == "" { jsonrpc.Build(r) } - return nil + return r.Error } // GetNamedBuildHandler returns a Named Build Handler for an operation marshal function diff --git a/service/s3/internal/awsrestxml/marshal.go b/service/s3/internal/awsrestxml/marshal.go index e93694c251e..78cdf72b2df 100644 --- a/service/s3/internal/awsrestxml/marshal.go +++ b/service/s3/internal/awsrestxml/marshal.go @@ -1,11 +1,11 @@ package awsrestxml import ( - "log" + "fmt" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/private/protocol" - v2 "github.com/aws/aws-sdk-go-v2/private/protocol/rest/v2" + restV2 "github.com/aws/aws-sdk-go-v2/private/protocol/rest/v2" "github.com/aws/aws-sdk-go-v2/service/s3/types" ) @@ -18,22 +18,26 @@ type ProtoPutObjectMarshaler struct { // This method calls appropriate marshal shape functions as per the input shape and protocol used by the service. func (m ProtoPutObjectMarshaler) MarshalOperation(r *aws.Request) { var err error - encoder := v2.NewEncoder(r.HTTPRequest) + encoder := restV2.NewEncoder(r.HTTPRequest) err = MarshalPutObjectInputShapeAWSREST(m.Input, encoder) if err != nil { r.Error = err + return } + encoder.Encode() - // since body payloadtype here is blob - if err = MarshalPutObjectInputShapeAWSXML(r, m.Input); err != nil { + // Todo Instead of passing aws.Request directly to MarshalPutObjectInputShapeAWSXML; + // we should pass the payload as an argument + if err = MarshalPutObjectInputShapeAWSXML(m.Input, r); err != nil { r.Error = err + return } } // MarshalPutObjectInputShapeAWSREST is a stand alone function used to marshal the HTTP bindings a input shape. // This method uses the rest encoder utility -func MarshalPutObjectInputShapeAWSREST(input *types.PutObjectInput, encoder *v2.Encoder) error { +func MarshalPutObjectInputShapeAWSREST(input *types.PutObjectInput, encoder *restV2.Encoder) error { // Encoding shapes with location `headers` marshalShapeMapForHeaders(encoder, "x-amz-meta-", input.Metadata) // Encoding shapes with location `header` @@ -60,35 +64,33 @@ func MarshalPutObjectInputShapeAWSREST(input *types.PutObjectInput, encoder *v2. encoder.AddHeader("x-amz-storage-class").String(string(input.StorageClass)) encoder.AddHeader("x-amz-server-side-encryption").String(string(input.ServerSideEncryption)) if err := encoder.AddHeader("Expires").Time(*input.Expires, protocol.RFC822TimeFormatName); err != nil { - log.Fatalf("Failed to encode header for shape Expires: \n \t %v", err) + return fmt.Errorf("failed to encode header for shape Expires: \n \t %v", err) } if err := encoder.AddHeader("x-amz-object-lock-retain-until-date").Time(*input.ObjectLockRetainUntilDate, protocol.ISO8601TimeFormatName); err != nil { - log.Fatalf("Failed to encode header for shape Expires: \n \t %v", err) + return fmt.Errorf("failed to encode header for shape Expires: \n \t %v", err) } // Encoding shapes with location `uri` if err := encoder.SetURI("Bucket").String(*input.Bucket); err != nil { - log.Fatalf("Failed to encode URI, \n\t %v\n", err) + return fmt.Errorf("failed to encode URI, \n\t %v", err) } if err := encoder.SetURI("Key").String(*input.Key); err != nil { - log.Fatalf("Failed to encode URI, \n\t %v\n", err) + return fmt.Errorf("failed to encode URI, \n\t %v", err) } - // encode using rest encoder utility - encoder.Encode() return nil } // MarshalPutObjectInputShapeAWSXML is a stand alone function used to marshal the xml payload // This should be generated according to the payload type for rest-xml protocol -func MarshalPutObjectInputShapeAWSXML(r *aws.Request, input *types.PutObjectInput) error { +func MarshalPutObjectInputShapeAWSXML(input *types.PutObjectInput, r *aws.Request) error { if input.Body != nil { r.SetReaderBody(input.Body) } - return nil + return r.Error } // marshalShapeMapForHeaders is marshal function that takes in a map[string]string as an input along with an encoder // and location Name which should be used to marshal the shape with location headers. -func marshalShapeMapForHeaders(encoder *v2.Encoder, locationName string, input map[string]string) { +func marshalShapeMapForHeaders(encoder *restV2.Encoder, locationName string, input map[string]string) { headerObject := encoder.Headers(locationName) for k, v := range input { headerObject.AddHeader(k).String(v)