-
Notifications
You must be signed in to change notification settings - Fork 592
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
...-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AddSigv4aPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.aws.typescript.codegen; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.function.Consumer; | ||
import software.amazon.smithy.aws.traits.auth.SigV4ATrait; | ||
import software.amazon.smithy.codegen.core.SymbolProvider; | ||
import software.amazon.smithy.model.Model; | ||
import software.amazon.smithy.model.knowledge.ServiceIndex; | ||
import software.amazon.smithy.typescript.codegen.LanguageTarget; | ||
import software.amazon.smithy.typescript.codegen.TypeScriptSettings; | ||
import software.amazon.smithy.typescript.codegen.TypeScriptWriter; | ||
import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration; | ||
import software.amazon.smithy.utils.MapUtils; | ||
import software.amazon.smithy.utils.SmithyInternalApi; | ||
|
||
/** | ||
* Detects when to add sigv4a signer. | ||
*/ | ||
@SmithyInternalApi | ||
public final class AddSigv4aPlugin implements TypeScriptIntegration { | ||
|
||
@Override | ||
public boolean matchesSettings(TypeScriptSettings settings) { | ||
return !settings.getExperimentalIdentityAndAuth(); | ||
} | ||
|
||
public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters( | ||
TypeScriptSettings settings, | ||
Model model, | ||
SymbolProvider symbolProvider, | ||
LanguageTarget target | ||
) { | ||
final boolean addSigv4aSignerToConfig = ServiceIndex.of(model) | ||
.getEffectiveAuthSchemes(settings.getService(), ServiceIndex.AuthSchemeMode.NO_AUTH_AWARE) | ||
.containsKey(SigV4ATrait.ID); | ||
|
||
// the sigv4a trait also appears on operations, but we will not check | ||
// them individually because it must appear on the service as well in that case. | ||
|
||
if (!addSigv4aSignerToConfig) { | ||
return Collections.emptyMap(); | ||
} | ||
|
||
// TODO: add to shared config when sigv4a implementation is available in browser. | ||
switch (target) { | ||
case NODE: | ||
return MapUtils.of("signerConstructor", writer -> { | ||
writer | ||
.addDependency(AwsDependency.SIGNATURE_V4_MULTIREGION) | ||
.addImport("SignatureV4MultiRegion", null, AwsDependency.SIGNATURE_V4_MULTIREGION) | ||
.write("SignatureV4MultiRegion"); | ||
}); | ||
default: | ||
return Collections.emptyMap(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters