|
| 1 | +/* |
| 2 | + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this file except in compliance with the License. |
| 6 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://aws.amazon.com/apache2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +package software.amazon.smithy.aws.typescript.codegen; |
| 17 | + |
| 18 | +import static software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin.Convention.HAS_MIDDLEWARE; |
| 19 | + |
| 20 | +import java.util.List; |
| 21 | +import java.util.Set; |
| 22 | + |
| 23 | +import software.amazon.smithy.aws.traits.ServiceTrait; |
| 24 | +import software.amazon.smithy.model.shapes.Shape; |
| 25 | +import software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin; |
| 26 | +import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration; |
| 27 | +import software.amazon.smithy.utils.ListUtils; |
| 28 | +import software.amazon.smithy.utils.SetUtils; |
| 29 | + |
| 30 | +public class AddCrossRegionCopyingPlugin implements TypeScriptIntegration { |
| 31 | + private static final Set<String> RDS_PRESIGNED_URL_OPERATIONS = SetUtils.of( |
| 32 | + "CopyDBSnapshot", |
| 33 | + "CreateDBInstanceReadReplica", |
| 34 | + "CreateDBCluster", |
| 35 | + "CopyDBClusterSnapshot" |
| 36 | + ); |
| 37 | + |
| 38 | + @Override |
| 39 | + public List<RuntimeClientPlugin> getClientPlugins() { |
| 40 | + return ListUtils.of( |
| 41 | + RuntimeClientPlugin.builder() |
| 42 | + .withConventions(AwsDependency.RDS_MIDDLEWARE.dependency, "CrossRegionPresignedUrl", |
| 43 | + HAS_MIDDLEWARE) |
| 44 | + .operationPredicate((m, s, o) -> RDS_PRESIGNED_URL_OPERATIONS.contains(o.getId().getName()) |
| 45 | + && testServiceId(s, "RDS")) |
| 46 | + .build() |
| 47 | + ); |
| 48 | + } |
| 49 | + |
| 50 | + private static boolean testServiceId(Shape serviceShape, String expectedId) { |
| 51 | + return serviceShape.getTrait(ServiceTrait.class).map(ServiceTrait::getSdkId).orElse("").equals(expectedId); |
| 52 | + } |
| 53 | +} |
0 commit comments