|
18 | 18 | import static software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin.Convention.HAS_MIDDLEWARE;
|
19 | 19 |
|
20 | 20 | import java.util.List;
|
| 21 | +import java.util.Map; |
21 | 22 | import java.util.Set;
|
| 23 | +import java.util.stream.Collectors; |
22 | 24 | import software.amazon.smithy.aws.traits.ServiceTrait;
|
23 | 25 | import software.amazon.smithy.model.shapes.Shape;
|
24 | 26 | import software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin;
|
25 | 27 | import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration;
|
26 |
| -import software.amazon.smithy.utils.ListUtils; |
| 28 | +import software.amazon.smithy.utils.MapUtils; |
27 | 29 | import software.amazon.smithy.utils.SetUtils;
|
28 | 30 | import software.amazon.smithy.utils.SmithyInternalApi;
|
29 | 31 |
|
30 | 32 | @SmithyInternalApi
|
31 | 33 | public class AddCrossRegionCopyingPlugin implements TypeScriptIntegration {
|
32 |
| - private static final Set<String> SHARED_PRESIGNED_URL_OPERATIONS = SetUtils.of( |
33 |
| - "CopyDBClusterSnapshot", |
34 |
| - "CreateDBCluster" |
35 |
| - ); |
36 |
| - private static final Set<String> RDS_PRESIGNED_URL_OPERATIONS = SetUtils.of( |
37 |
| - "CopyDBSnapshot", |
38 |
| - "CreateDBInstanceReadReplica", |
39 |
| - "StartDBInstanceAutomatedBackupsReplication" |
| 34 | + private static final Map<String, Set<String>> PRESIGNED_URL_OPERATIONS_MAP = MapUtils.of( |
| 35 | + "RDS", SetUtils.of( |
| 36 | + "CopyDBClusterSnapshot", |
| 37 | + "CreateDBCluster", |
| 38 | + "CopyDBSnapshot", |
| 39 | + "CreateDBInstanceReadReplica", |
| 40 | + "StartDBInstanceAutomatedBackupsReplication"), |
| 41 | + "DocDB", SetUtils.of("CopyDBClusterSnapshot"), |
| 42 | + "Neptune", SetUtils.of("CopyDBClusterSnapshot", "CreateDBCluster") |
40 | 43 | );
|
41 | 44 |
|
42 | 45 | @Override
|
43 | 46 | public List<RuntimeClientPlugin> getClientPlugins() {
|
44 |
| - return ListUtils.of( |
45 |
| - RuntimeClientPlugin.builder() |
46 |
| - .withConventions(AwsDependency.RDS_MIDDLEWARE.dependency, "CrossRegionPresignedUrl", |
47 |
| - HAS_MIDDLEWARE) |
48 |
| - .operationPredicate((m, s, o) -> RDS_PRESIGNED_URL_OPERATIONS.contains(o.getId().getName(s)) |
49 |
| - && testServiceId(s, "RDS")) |
50 |
| - .build(), |
51 |
| - RuntimeClientPlugin.builder() |
52 |
| - .withConventions(AwsDependency.RDS_MIDDLEWARE.dependency, "CrossRegionPresignedUrl", |
53 |
| - HAS_MIDDLEWARE) |
54 |
| - .operationPredicate((m, s, o) -> SHARED_PRESIGNED_URL_OPERATIONS.contains(o.getId().getName(s)) |
55 |
| - && (testServiceId(s, "RDS") || testServiceId(s, "DocDB") || testServiceId(s, "Neptune"))) |
56 |
| - .build() |
57 |
| - ); |
| 47 | + return PRESIGNED_URL_OPERATIONS_MAP.entrySet().stream().map((entry) -> { |
| 48 | + String serviceId = entry.getKey(); |
| 49 | + Set<String> commands = entry.getValue(); |
| 50 | + return RuntimeClientPlugin.builder() |
| 51 | + .withConventions(AwsDependency.RDS_MIDDLEWARE.dependency, "CrossRegionPresignedUrl", HAS_MIDDLEWARE) |
| 52 | + .operationPredicate( |
| 53 | + (m, s, o) -> commands.contains(o.getId().getName(s)) && testServiceId(s, serviceId)) |
| 54 | + .build(); |
| 55 | + }).collect(Collectors.toList()); |
58 | 56 | }
|
59 | 57 |
|
60 | 58 | private static boolean testServiceId(Shape serviceShape, String expectedId) {
|
|
0 commit comments