|
| 1 | +/* |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package software.amazon.smithy.aws.typescript.codegen; |
| 7 | + |
| 8 | +import java.util.Collections; |
| 9 | +import java.util.Map; |
| 10 | +import java.util.function.Consumer; |
| 11 | +import software.amazon.smithy.aws.traits.ServiceTrait; |
| 12 | +import software.amazon.smithy.codegen.core.SymbolProvider; |
| 13 | +import software.amazon.smithy.model.Model; |
| 14 | +import software.amazon.smithy.model.shapes.Shape; |
| 15 | +import software.amazon.smithy.typescript.codegen.LanguageTarget; |
| 16 | +import software.amazon.smithy.typescript.codegen.TypeScriptSettings; |
| 17 | +import software.amazon.smithy.typescript.codegen.TypeScriptWriter; |
| 18 | +import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration; |
| 19 | +import software.amazon.smithy.utils.MapUtils; |
| 20 | +import software.amazon.smithy.utils.SmithyInternalApi; |
| 21 | + |
| 22 | +/** |
| 23 | + * Adds customizations for CloudFront KeyValueStore service. |
| 24 | + */ |
| 25 | +@SmithyInternalApi |
| 26 | +public final class AddCloudFrontKeyValueStorePlugin implements TypeScriptIntegration { |
| 27 | + public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(TypeScriptSettings settings, Model model, |
| 28 | + SymbolProvider symbolProvider, LanguageTarget target) { |
| 29 | + if (!testServiceId(settings.getService(model))) { |
| 30 | + return Collections.emptyMap(); |
| 31 | + } |
| 32 | + switch (target) { |
| 33 | + case SHARED: |
| 34 | + return MapUtils.of("signerConstructor", writer -> { |
| 35 | + writer.addDependency(AwsDependency.SIGNATURE_V4_MULTIREGION) |
| 36 | + .addImport("SignatureV4MultiRegion", "SignatureV4MultiRegion", |
| 37 | + AwsDependency.SIGNATURE_V4_MULTIREGION) |
| 38 | + .write("SignatureV4MultiRegion"); |
| 39 | + }); |
| 40 | + default: |
| 41 | + return Collections.emptyMap(); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + private static boolean testServiceId(Shape serviceShape) { |
| 46 | + return serviceShape.getTrait(ServiceTrait.class) |
| 47 | + .map(ServiceTrait::getSdkId).orElse("") |
| 48 | + .equals("CloudFront KeyValueStore"); |
| 49 | + } |
| 50 | +} |
0 commit comments