From f51c1fb528bd07a8d6a1fa8ec1713cbee1d0864f Mon Sep 17 00:00:00 2001 From: Jason Del Ponte Date: Wed, 16 Dec 2020 15:31:31 -0800 Subject: [PATCH 1/2] codegen: Add backfilling boxed trait to S3Control API shape Adds backfilling @boxed trait to the S3Control ExpirationInDays shape. --- .../customization/BackfillBoxTrait.java | 78 +++++++++++++++++++ ...mithy.go.codegen.integration.GoIntegration | 1 + 2 files changed, 79 insertions(+) create mode 100644 codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/BackfillBoxTrait.java diff --git a/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/BackfillBoxTrait.java b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/BackfillBoxTrait.java new file mode 100644 index 00000000000..4cd495c22f1 --- /dev/null +++ b/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/customization/BackfillBoxTrait.java @@ -0,0 +1,78 @@ +/* + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + * + * + */ + +package software.amazon.smithy.aws.go.codegen.customization; + +import java.util.Map; +import java.util.Set; +import java.util.logging.Logger; +import software.amazon.smithy.go.codegen.GoSettings; +import software.amazon.smithy.go.codegen.integration.GoIntegration; +import software.amazon.smithy.model.Model; +import software.amazon.smithy.model.shapes.IntegerShape; +import software.amazon.smithy.model.shapes.ShapeId; +import software.amazon.smithy.model.traits.BoxTrait; +import software.amazon.smithy.utils.MapUtils; +import software.amazon.smithy.utils.SetUtils; + +/** + * Integration that back fills the `boxed` traits to API shapes that were not decorated with the trait in the model. + */ +public class BackfillBoxTrait implements GoIntegration { + private static final Logger LOGGER = Logger.getLogger(BackfillBoxTrait.class.getName()); + + /** + * Map of service shape to Set of operation shapes that need to have this + * presigned url auto fill customization. + */ + public static final Map> SERVICE_TO_MEMBER_MAP = MapUtils.of( + ShapeId.from("com.amazonaws.s3control#AWSS3ControlServiceV20180820"), SetUtils.of( + ShapeId.from("com.amazonaws.s3control#S3ExpirationInDays") + )); + + /** + * /** + * Updates the API model to add additional members to the operation input shape that are needed for presign url + * customization. + * + * @param model API model + * @param settings Go codegen settings + * @return updated API model + */ + @Override + public Model preprocessModel(Model model, GoSettings settings) { + ShapeId serviceId = settings.getService(); + if (!SERVICE_TO_MEMBER_MAP.containsKey(serviceId)) { + return model; + } + Model.Builder builder = model.toBuilder(); + + Set shapeIds = SERVICE_TO_MEMBER_MAP.get(serviceId); + for (ShapeId shapeId : shapeIds) { + IntegerShape shape = model.expectShape(shapeId, IntegerShape.class); + if (shape.getTrait(BoxTrait.class).isPresent()) { + LOGGER.warning("BoxTrait is present in model and does not require backfill"); + continue; + } + builder.addShape(shape.toBuilder() + .addTrait(new BoxTrait()) + .build()); + } + + return builder.build(); + } +} diff --git a/codegen/smithy-aws-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.go.codegen.integration.GoIntegration b/codegen/smithy-aws-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.go.codegen.integration.GoIntegration index 7e1dfee480e..9b93a002d9d 100644 --- a/codegen/smithy-aws-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.go.codegen.integration.GoIntegration +++ b/codegen/smithy-aws-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.go.codegen.integration.GoIntegration @@ -10,6 +10,7 @@ software.amazon.smithy.aws.go.codegen.AwsSdkServiceId software.amazon.smithy.aws.go.codegen.AwsRetryMiddlewareHelper software.amazon.smithy.aws.go.codegen.AWSRequestIDRetriever software.amazon.smithy.aws.go.codegen.AWSResponseErrorWrapper +software.amazon.smithy.aws.go.codegen.customization.BackfillBoxTrait software.amazon.smithy.aws.go.codegen.customization.DynamoDBValidateResponseChecksum software.amazon.smithy.aws.go.codegen.customization.S3UpdateEndpoint software.amazon.smithy.aws.go.codegen.customization.APIGatewayAcceptHeader From 83c59a186f2b8d4de286cd3fab4c64763abe5fbe Mon Sep 17 00:00:00 2001 From: Jason Del Ponte Date: Wed, 16 Dec 2020 15:36:20 -0800 Subject: [PATCH 2/2] regenerate s3 control api --- service/s3control/deserializers.go | 2 +- service/s3control/serializers.go | 4 ++-- service/s3control/types/types.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/service/s3control/deserializers.go b/service/s3control/deserializers.go index 92f1da7eacf..dd2df1681e9 100644 --- a/service/s3control/deserializers.go +++ b/service/s3control/deserializers.go @@ -8767,7 +8767,7 @@ func awsRestxml_deserializeDocumentS3InitiateRestoreObjectOperation(v **types.S3 if err != nil { return err } - sv.ExpirationInDays = int32(i64) + sv.ExpirationInDays = ptr.Int32(int32(i64)) } case strings.EqualFold("GlacierJobTier", t.Name.Local): diff --git a/service/s3control/serializers.go b/service/s3control/serializers.go index b6fd037d7be..be74b2c7997 100644 --- a/service/s3control/serializers.go +++ b/service/s3control/serializers.go @@ -4475,7 +4475,7 @@ func awsRestxml_serializeDocumentS3GrantList(v []types.S3Grant, value smithyxml. func awsRestxml_serializeDocumentS3InitiateRestoreObjectOperation(v *types.S3InitiateRestoreObjectOperation, value smithyxml.Value) error { defer value.Close() - if v.ExpirationInDays != 0 { + if v.ExpirationInDays != nil { rootAttr := []smithyxml.Attr{} root := smithyxml.StartElement{ Name: smithyxml.Name{ @@ -4484,7 +4484,7 @@ func awsRestxml_serializeDocumentS3InitiateRestoreObjectOperation(v *types.S3Ini Attr: rootAttr, } el := value.MemberElement(root) - el.Integer(v.ExpirationInDays) + el.Integer(*v.ExpirationInDays) } if len(v.GlacierJobTier) > 0 { rootAttr := []smithyxml.Attr{} diff --git a/service/s3control/types/types.go b/service/s3control/types/types.go index 6cbe13afa78..cc13afbf940 100644 --- a/service/s3control/types/types.go +++ b/service/s3control/types/types.go @@ -748,7 +748,7 @@ type S3Grantee struct { type S3InitiateRestoreObjectOperation struct { // - ExpirationInDays int32 + ExpirationInDays *int32 // GlacierJobTier S3GlacierJobTier