Skip to content

Commit 73399ff

Browse files
authored
chore(codegen): add sigv4a trait detection (#5850)
* chore(codegen): add sigv4a trait detection * chore: no need to check operations for sigv4a * chore: import ordering * chore: add id&auth settings matcher to sigv4a plugin
1 parent 304ca3e commit 73399ff

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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.auth.SigV4ATrait;
12+
import software.amazon.smithy.codegen.core.SymbolProvider;
13+
import software.amazon.smithy.model.Model;
14+
import software.amazon.smithy.model.knowledge.ServiceIndex;
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+
* Detects when to add sigv4a signer.
24+
*/
25+
@SmithyInternalApi
26+
public final class AddSigv4aPlugin implements TypeScriptIntegration {
27+
28+
@Override
29+
public boolean matchesSettings(TypeScriptSettings settings) {
30+
return !settings.getExperimentalIdentityAndAuth();
31+
}
32+
33+
public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
34+
TypeScriptSettings settings,
35+
Model model,
36+
SymbolProvider symbolProvider,
37+
LanguageTarget target
38+
) {
39+
final boolean addSigv4aSignerToConfig = ServiceIndex.of(model)
40+
.getEffectiveAuthSchemes(settings.getService(), ServiceIndex.AuthSchemeMode.NO_AUTH_AWARE)
41+
.containsKey(SigV4ATrait.ID);
42+
43+
// the sigv4a trait also appears on operations, but we will not check
44+
// them individually because it must appear on the service as well in that case.
45+
46+
if (!addSigv4aSignerToConfig) {
47+
return Collections.emptyMap();
48+
}
49+
50+
// TODO: add to shared config when sigv4a implementation is available in browser.
51+
switch (target) {
52+
case NODE:
53+
return MapUtils.of("signerConstructor", writer -> {
54+
writer
55+
.addDependency(AwsDependency.SIGNATURE_V4_MULTIREGION)
56+
.addImport("SignatureV4MultiRegion", null, AwsDependency.SIGNATURE_V4_MULTIREGION)
57+
.write("SignatureV4MultiRegion");
58+
});
59+
default:
60+
return Collections.emptyMap();
61+
}
62+
}
63+
}

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
@@ -24,6 +24,7 @@ software.amazon.smithy.aws.typescript.codegen.AddDocumentClientPlugin
2424
software.amazon.smithy.aws.typescript.codegen.AddEndpointDiscoveryPlugin
2525
software.amazon.smithy.aws.typescript.codegen.AddHttpChecksumDependency
2626
software.amazon.smithy.aws.typescript.codegen.AddEventBridgePlugin
27+
software.amazon.smithy.aws.typescript.codegen.AddSigv4aPlugin
2728
software.amazon.smithy.aws.typescript.codegen.AddCloudFrontKeyValueStorePlugin
2829
software.amazon.smithy.aws.typescript.codegen.auth.http.integration.AwsSdkCustomizeHttpBearerTokenAuth
2930
software.amazon.smithy.aws.typescript.codegen.auth.http.integration.SupportSigV4Auth

0 commit comments

Comments
 (0)