Skip to content

Commit 7fa4eaf

Browse files
authored
chore(codegen): move CrossRegionCopying to separate plugin (#1984)
1 parent d2e8d4f commit 7fa4eaf

File tree

3 files changed

+54
-14
lines changed

3 files changed

+54
-14
lines changed

Diff for: codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddBuiltinPlugins.java

-14
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,8 @@
3939
* Adds all built-in runtime client plugins to clients.
4040
*/
4141
public class AddBuiltinPlugins implements TypeScriptIntegration {
42-
4342
private static final Set<String> ROUTE_53_ID_MEMBERS = SetUtils.of("DelegationSetId", "HostedZoneId", "Id");
4443

45-
private static final Set<String> RDS_PRESIGNED_URL_OPERATIONS = SetUtils.of(
46-
"CopyDBSnapshot",
47-
"CreateDBInstanceReadReplica",
48-
"CreateDBCluster",
49-
"CopyDBClusterSnapshot"
50-
);
51-
5244
@Override
5345
public List<RuntimeClientPlugin> getClientPlugins() {
5446
// Note that order is significant because configurations might
@@ -104,12 +96,6 @@ && testServiceId(s, "Machine Learning"))
10496
.operationPredicate((m, s, o) -> o.getId().getName().equals("ChangeResourceRecordSets")
10597
&& testServiceId(s, "Route 53"))
10698
.build(),
107-
RuntimeClientPlugin.builder()
108-
.withConventions(AwsDependency.RDS_MIDDLEWARE.dependency, "CrossRegionPresignedUrl",
109-
HAS_MIDDLEWARE)
110-
.operationPredicate((m, s, o) -> RDS_PRESIGNED_URL_OPERATIONS.contains(o.getId().getName())
111-
&& testServiceId(s, "RDS"))
112-
.build(),
11399
RuntimeClientPlugin.builder()
114100
.withConventions(AwsDependency.ROUTE53_MIDDLEWARE.dependency, "IdNormalizer",
115101
HAS_MIDDLEWARE)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
}

Diff for: codegen/smithy-aws-typescript-codegen/src/main/resources/META-INF/services/software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ software.amazon.smithy.aws.typescript.codegen.AddTranscribeStreamingDependency
1515
software.amazon.smithy.aws.typescript.codegen.AddUserAgentDependency
1616
software.amazon.smithy.aws.typescript.codegen.AddOmitRetryHeadersDependency
1717
software.amazon.smithy.aws.typescript.codegen.StripNewEnumNames
18+
software.amazon.smithy.aws.typescript.codegen.AddCrossRegionCopyingPlugin

0 commit comments

Comments
 (0)