Skip to content

Commit 82f8ab2

Browse files
author
Steven Yuan
committed
Add experimentalIdentityAndAuth flag
Add the experimental feature flag for identity and auth `experimentalIdentityAndAuth` in `TypeScriptSettings`. - For `AddHttpApiKeyAuthPlugin`, make the current behavior the control branch for `experimentalIdentityAndAuth`. - Add a test projection in `smithy-typescript-codegen-test` for `experimentalIdentityAndAuth`. Also, add a section in `CONTRIBUTING.md` about experimental features in `smithy-typescript`.
1 parent 3d36329 commit 82f8ab2

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

CONTRIBUTING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ In order to utilise this feature, create a file `local.properties` in the projec
2020
smithy=/Volumes/workplace/smithy
2121
```
2222

23+
## Experimental Features
24+
25+
The `smithy-typescript` repository is under heavy development, and has experimental features that can affect consumers
26+
of code generation packages and TypeScript packages. These features are enabled via opt-in settings in
27+
`smithy-build.json`. Note that any contributions related to these features MUST be reviewed carefully for opt-in
28+
behavior via feature flags as to not break any existing customers. Here are the experimental features that are currently
29+
under development:
30+
31+
Experimental Feature | Flag | Description
32+
---------------------|-------------------------------|------------
33+
Identity & Auth | `experimentalIdentityAndAuth` | Standardize identity and auth integrations to match the Smithy specification (see [Authentication Traits](https://smithy.io/2.0/spec/authentication-traits.html)). Newer capabilities include support for multiple auth schemes, `@optionalAuth`, and standardized identity interfaces for authentication schemes both in code generation and TypeScript packages. In `smithy-typescript`, `@httpApiKeyAuth` will be updated to use the new standardized interfaces. In `aws-sdk-js-v3` (`smithy-typescript`'s largest customer), this will affect `@aws.auth#sigv4` and `@httpBearerAuth` implementations, but is planned to be completely backwards-compatible.
34+
2335
## Reporting Bugs/Feature Requests
2436

2537
We welcome you to use the GitHub issue tracker to report bugs or suggest features.

smithy-typescript-codegen-test/smithy-build.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@
2323
"disableDefaultValidation": true
2424
}
2525
}
26+
},
27+
"client-experimental-identity-and-auth": {
28+
"plugins": {
29+
"typescript-codegen": {
30+
"service": "example.weather#Weather",
31+
"targetNamespace": "Weather",
32+
"package": "weather",
33+
"packageVersion": "0.0.1",
34+
"packageJson": {
35+
"license": "Apache-2.0",
36+
"private": true
37+
},
38+
"experimentalIdentityAndAuth": true
39+
}
40+
}
2641
}
2742
},
2843
"plugins": {

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/TypeScriptSettings.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public final class TypeScriptSettings {
5858
private static final String PRIVATE = "private";
5959
private static final String PACKAGE_MANAGER = "packageManager";
6060
private static final String CREATE_DEFAULT_README = "createDefaultReadme";
61+
private static final String EXPERIMENTAL_IDENTITY_AND_AUTH = "experimentalIdentityAndAuth";
6162

6263
private String packageName;
6364
private String packageDescription = "";
@@ -74,6 +75,7 @@ public final class TypeScriptSettings {
7475
RequiredMemberMode.NULLABLE;
7576
private PackageManager packageManager = PackageManager.YARN;
7677
private boolean createDefaultReadme = false;
78+
private boolean experimentalIdentityAndAuth = false;
7779

7880
@Deprecated
7981
public static TypeScriptSettings from(Model model, ObjectNode config) {
@@ -107,6 +109,8 @@ public static TypeScriptSettings from(Model model, ObjectNode config, ArtifactTy
107109
settings.setPrivate(config.getBooleanMember(PRIVATE).map(BooleanNode::getValue).orElse(false));
108110
settings.setCreateDefaultReadme(
109111
config.getBooleanMember(CREATE_DEFAULT_README).map(BooleanNode::getValue).orElse(false));
112+
settings.setExperimentalIdentityAndAuth(
113+
config.getBooleanMemberOrDefault(EXPERIMENTAL_IDENTITY_AND_AUTH, false));
110114
settings.setPackageManager(
111115
config.getStringMember(PACKAGE_MANAGER)
112116
.map(s -> PackageManager.fromString(s.getValue()))
@@ -352,6 +356,31 @@ public void setPackageManager(PackageManager packageManager) {
352356
this.packageManager = packageManager;
353357
}
354358

359+
/**
360+
* Returns whether to use experimental identity and auth.
361+
*
362+
* @return if experimental identity and auth should used. Default: false
363+
*/
364+
public boolean getExperimentalIdentityAndAuth() {
365+
return experimentalIdentityAndAuth;
366+
}
367+
368+
/**
369+
* Sets whether experimental identity and auth should be used.
370+
*
371+
* @param experimentalIdentityAndAuth whether experimental identity and auth should be used.
372+
*/
373+
public void setExperimentalIdentityAndAuth(boolean experimentalIdentityAndAuth) {
374+
if (experimentalIdentityAndAuth) {
375+
LOGGER.warning("""
376+
Experimental identity and auth is in development, and is subject to \
377+
breaking changes. Behavior may NOT have the same feature parity as \
378+
non-experimental behavior. This setting is also subject to removal \
379+
when the feature is completed.""");
380+
}
381+
this.experimentalIdentityAndAuth = experimentalIdentityAndAuth;
382+
}
383+
355384
/**
356385
* Gets the corresponding {@link ServiceShape} from a model.
357386
*
@@ -440,7 +469,7 @@ public enum ArtifactType {
440469
CLIENT(SymbolVisitor::new,
441470
Arrays.asList(PACKAGE, PACKAGE_DESCRIPTION, PACKAGE_JSON, PACKAGE_VERSION, PACKAGE_MANAGER,
442471
SERVICE, PROTOCOL, TARGET_NAMESPACE, PRIVATE, REQUIRED_MEMBER_MODE,
443-
CREATE_DEFAULT_README)),
472+
CREATE_DEFAULT_README, EXPERIMENTAL_IDENTITY_AND_AUTH)),
444473
SSDK((m, s) -> new ServerSymbolVisitor(m, new SymbolVisitor(m, s)),
445474
Arrays.asList(PACKAGE, PACKAGE_DESCRIPTION, PACKAGE_JSON, PACKAGE_VERSION, PACKAGE_MANAGER,
446475
SERVICE, PROTOCOL, TARGET_NAMESPACE, PRIVATE, REQUIRED_MEMBER_MODE,

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/integration/AddHttpApiKeyAuthPlugin.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public List<RuntimeClientPlugin> getClientPlugins() {
7676
.name("resolveHttpApiKeyAuthConfig")
7777
.build())
7878
.servicePredicate((m, s) -> hasEffectiveHttpApiKeyAuthTrait(m, s))
79+
.settingsPredicate((m, s, settings) -> !settings.getExperimentalIdentityAndAuth())
7980
.build(),
8081

8182
// Add the middleware to operations that use HTTP API key authorization.
@@ -96,12 +97,17 @@ public List<RuntimeClientPlugin> getClientPlugins() {
9697
.keySet()
9798
.contains(HttpApiKeyAuthTrait.ID)
9899
&& !o.hasTrait(OptionalAuthTrait.class))
100+
.settingsPredicate((m, s, settings) -> !settings.getExperimentalIdentityAndAuth())
99101
.build()
100102
);
101103
}
102104

103105
@Override
104106
public void customize(TypeScriptCodegenContext codegenContext) {
107+
if (codegenContext.settings().getExperimentalIdentityAndAuth()) {
108+
return;
109+
}
110+
// feat(experimentalIdentityAndAuth): control branch for @httpApiKeyAuth
105111
TypeScriptSettings settings = codegenContext.settings();
106112
Model model = codegenContext.model();
107113
BiConsumer<String, Consumer<TypeScriptWriter>> writerFactory = codegenContext.writerDelegator()::useFileWriter;

0 commit comments

Comments
 (0)