Skip to content

Commit 7758b2a

Browse files
author
Steven Yuan
committed
feat(experimentalIdentityAndAuth): add HttpAuthExtensionConfiguration
Add code-generation for `HttpAuthExtensionConfiguration`, which allows configuring: - `httpAuthSchemes` - `httpAuthSchemeProvider` - Any `ConfigField` registered by `HttpAuthScheme`s Also, add relative import dependencies for: - `httpAuthSchemeProvider` - `httpAuthExtensionConfiguration`
1 parent 6f6f6fe commit 7758b2a

File tree

7 files changed

+471
-29
lines changed

7 files changed

+471
-29
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
package software.amazon.smithy.typescript.codegen;
1717

18-
import java.nio.file.Paths;
1918
import java.util.Collections;
2019
import java.util.Iterator;
2120
import java.util.List;
@@ -32,7 +31,6 @@
3231
import software.amazon.smithy.model.shapes.ShapeId;
3332
import software.amazon.smithy.typescript.codegen.auth.AuthUtils;
3433
import software.amazon.smithy.typescript.codegen.auth.http.HttpAuthScheme;
35-
import software.amazon.smithy.typescript.codegen.auth.http.HttpAuthSchemeProviderGenerator;
3634
import software.amazon.smithy.typescript.codegen.auth.http.SupportedHttpAuthSchemesIndex;
3735
import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration;
3836
import software.amazon.smithy.utils.MapUtils;
@@ -212,9 +210,7 @@ private void generateHttpAuthSchemeConfig(
212210
if (target.equals(LanguageTarget.SHARED)) {
213211
configs.put("httpAuthSchemeProvider", w -> {
214212
String providerName = "default" + service.toShapeId().getName() + "HttpAuthSchemeProvider";
215-
w.addRelativeImport(providerName, null, Paths.get(".", CodegenUtils.SOURCE_FOLDER,
216-
HttpAuthSchemeProviderGenerator.HTTP_AUTH_FOLDER,
217-
HttpAuthSchemeProviderGenerator.HTTP_AUTH_SCHEME_RESOLVER_MODULE));
213+
w.addImport(providerName, null, AuthUtils.AUTH_HTTP_PROVIDER_DEPENDENCY);
218214
w.write(providerName);
219215
});
220216
}

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import software.amazon.smithy.model.shapes.OperationShape;
3333
import software.amazon.smithy.model.shapes.ServiceShape;
3434
import software.amazon.smithy.rulesengine.traits.EndpointRuleSetTrait;
35-
import software.amazon.smithy.typescript.codegen.auth.http.HttpAuthSchemeProviderGenerator;
35+
import software.amazon.smithy.typescript.codegen.auth.AuthUtils;
3636
import software.amazon.smithy.typescript.codegen.auth.http.integration.HttpAuthTypeScriptIntegration;
3737
import software.amazon.smithy.typescript.codegen.integration.RuntimeClientPlugin;
3838
import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration;
@@ -313,10 +313,7 @@ private void generateClientDefaults() {
313313
writer.write("httpAuthSchemes?: HttpAuthScheme[];\n");
314314

315315
String httpAuthSchemeProviderName = service.toShapeId().getName() + "HttpAuthSchemeProvider";
316-
writer.addRelativeImport(httpAuthSchemeProviderName, null, Paths.get(".",
317-
CodegenUtils.SOURCE_FOLDER,
318-
HttpAuthSchemeProviderGenerator.HTTP_AUTH_FOLDER,
319-
HttpAuthSchemeProviderGenerator.HTTP_AUTH_SCHEME_RESOLVER_MODULE));
316+
writer.addImport(httpAuthSchemeProviderName, null, AuthUtils.AUTH_HTTP_PROVIDER_DEPENDENCY);
320317
writer.writeDocs("""
321318
experimentalIdentityAndAuth: Configuration of an HttpAuthSchemeProvider for a client which \
322319
resolves which HttpAuthScheme to use.

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/auth/AuthUtils.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55

66
package software.amazon.smithy.typescript.codegen.auth;
77

8+
import java.nio.file.Paths;
9+
import java.util.Collections;
10+
import java.util.List;
811
import java.util.Map;
912
import java.util.TreeMap;
13+
import software.amazon.smithy.codegen.core.SymbolDependency;
1014
import software.amazon.smithy.model.knowledge.ServiceIndex;
1115
import software.amazon.smithy.model.knowledge.ServiceIndex.AuthSchemeMode;
1216
import software.amazon.smithy.model.shapes.ServiceShape;
1317
import software.amazon.smithy.model.shapes.ShapeId;
18+
import software.amazon.smithy.typescript.codegen.CodegenUtils;
19+
import software.amazon.smithy.typescript.codegen.Dependency;
1420
import software.amazon.smithy.typescript.codegen.auth.http.HttpAuthScheme;
1521
import software.amazon.smithy.typescript.codegen.auth.http.SupportedHttpAuthSchemesIndex;
1622
import software.amazon.smithy.utils.SmithyInternalApi;
@@ -20,6 +26,54 @@
2026
*/
2127
@SmithyInternalApi
2228
public final class AuthUtils {
29+
public static final String HTTP_AUTH_FOLDER = "auth";
30+
31+
public static final String HTTP_AUTH_SCHEME_PROVIDER_MODULE = "httpAuthSchemeProvider";
32+
33+
public static final String HTTP_AUTH_SCHEME_PROVIDER_FILE =
34+
HTTP_AUTH_SCHEME_PROVIDER_MODULE + ".ts";
35+
36+
public static final String HTTP_AUTH_SCHEME_PROVIDER_PATH =
37+
Paths.get(".", CodegenUtils.SOURCE_FOLDER, HTTP_AUTH_FOLDER, HTTP_AUTH_SCHEME_PROVIDER_FILE).toString();
38+
39+
public static final Dependency AUTH_HTTP_PROVIDER_DEPENDENCY = new Dependency() {
40+
@Override
41+
public String getPackageName() {
42+
return Paths.get(
43+
".", CodegenUtils.SOURCE_FOLDER,
44+
HTTP_AUTH_FOLDER, HTTP_AUTH_SCHEME_PROVIDER_MODULE
45+
).toString();
46+
}
47+
48+
@Override
49+
public List<SymbolDependency> getDependencies() {
50+
return Collections.emptyList();
51+
}
52+
};
53+
54+
public static final String HTTP_AUTH_SCHEME_EXTENSION_MODULE = "httpAuthExtensionConfiguration";
55+
56+
public static final String HTTP_AUTH_SCHEME_EXTENSION_FILE =
57+
HTTP_AUTH_SCHEME_EXTENSION_MODULE + ".ts";
58+
59+
public static final String HTTP_AUTH_SCHEME_EXTENSION_PATH =
60+
Paths.get(".", CodegenUtils.SOURCE_FOLDER, HTTP_AUTH_FOLDER, HTTP_AUTH_SCHEME_EXTENSION_FILE).toString();
61+
62+
public static final Dependency AUTH_HTTP_EXTENSION_DEPENDENCY = new Dependency() {
63+
@Override
64+
public String getPackageName() {
65+
return Paths.get(
66+
".", CodegenUtils.SOURCE_FOLDER,
67+
HTTP_AUTH_FOLDER, HTTP_AUTH_SCHEME_EXTENSION_MODULE
68+
).toString();
69+
}
70+
71+
@Override
72+
public List<SymbolDependency> getDependencies() {
73+
return Collections.emptyList();
74+
}
75+
};
76+
2377
private AuthUtils() {}
2478

2579
public static Map<ShapeId, HttpAuthScheme> getAllEffectiveNoAuthAwareAuthSchemes(

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/auth/http/HttpAuthSchemeProviderGenerator.java

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,6 @@
4141
*/
4242
@SmithyInternalApi
4343
public class HttpAuthSchemeProviderGenerator implements Runnable {
44-
/**
45-
* Directory segment for {@code auth/}.
46-
*/
47-
public static final String HTTP_AUTH_FOLDER = "auth";
48-
/**
49-
* File name segment for {@code httpAuthSchemeProvder}.
50-
*/
51-
public static final String HTTP_AUTH_SCHEME_RESOLVER_MODULE = "httpAuthSchemeProvider";
52-
53-
private static final String HTTP_AUTH_SCHEME_RESOLVER_FILE =
54-
HTTP_AUTH_SCHEME_RESOLVER_MODULE + ".ts";
55-
private static final String HTTP_AUTH_SCHEME_RESOLVER_PATH =
56-
Paths.get(CodegenUtils.SOURCE_FOLDER, HTTP_AUTH_FOLDER, HTTP_AUTH_SCHEME_RESOLVER_FILE).toString();
57-
5844
private final TypeScriptDelegator delegator;
5945
private final Model model;
6046

@@ -104,7 +90,7 @@ export interface WeatherHttpAuthSchemeParameters {
10490
}
10591
*/
10692
private void generateHttpAuthSchemeParametersInterface() {
107-
delegator.useFileWriter(HTTP_AUTH_SCHEME_RESOLVER_PATH.toString(), w -> {
93+
delegator.useFileWriter(AuthUtils.HTTP_AUTH_SCHEME_PROVIDER_PATH, w -> {
10894
w.openBlock("""
10995
/**
11096
* @internal
@@ -138,7 +124,7 @@ export async function defaultWeatherHttpAuthSchemeParametersProvider(
138124
};
139125
*/
140126
private void generateDefaultHttpAuthSchemeParametersProviderFunction() {
141-
delegator.useFileWriter(HTTP_AUTH_SCHEME_RESOLVER_PATH.toString(), w -> {
127+
delegator.useFileWriter(AuthUtils.HTTP_AUTH_SCHEME_PROVIDER_PATH, w -> {
142128
w.addRelativeImport(serviceSymbol.getName() + "ResolvedConfig", null,
143129
Paths.get(".", serviceSymbol.getNamespace()));
144130
w.addImport("HandlerExecutionContext", null, TypeScriptDependency.SMITHY_TYPES);
@@ -190,7 +176,7 @@ function createSmithyApiHttpApiKeyAuthHttpAuthOption(authParameters: WeatherHttp
190176
};
191177
*/
192178
private void generateHttpAuthOptionFunction(ShapeId shapeId, HttpAuthScheme authScheme) {
193-
delegator.useFileWriter(HTTP_AUTH_SCHEME_RESOLVER_PATH.toString(), w -> {
179+
delegator.useFileWriter(AuthUtils.HTTP_AUTH_SCHEME_PROVIDER_PATH, w -> {
194180
String normalizedAuthSchemeName = normalizeAuthSchemeName(shapeId);
195181
w.addDependency(TypeScriptDependency.EXPERIMENTAL_IDENTITY_AND_AUTH);
196182
w.addImport("HttpAuthOption", null, TypeScriptDependency.EXPERIMENTAL_IDENTITY_AND_AUTH);
@@ -242,7 +228,7 @@ export interface WeatherHttpAuthSchemeProvider {
242228
}
243229
*/
244230
private void generateHttpAuthSchemeProviderInterface() {
245-
delegator.useFileWriter(HTTP_AUTH_SCHEME_RESOLVER_PATH.toString(), w -> {
231+
delegator.useFileWriter(AuthUtils.HTTP_AUTH_SCHEME_PROVIDER_PATH, w -> {
246232
w.write("""
247233
/**
248234
* @internal
@@ -267,7 +253,7 @@ export function defaultWeatherHttpAuthSchemeProvider(authParameters: WeatherHttp
267253
};
268254
*/
269255
private void generateHttpAuthSchemeProviderDefaultFunction() {
270-
delegator.useFileWriter(HTTP_AUTH_SCHEME_RESOLVER_PATH.toString(), w -> {
256+
delegator.useFileWriter(AuthUtils.HTTP_AUTH_SCHEME_PROVIDER_PATH, w -> {
271257
w.openBlock("""
272258
/**
273259
* @internal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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.typescript.codegen.auth.http.integration;
7+
8+
import software.amazon.smithy.typescript.codegen.Dependency;
9+
import software.amazon.smithy.typescript.codegen.auth.AuthUtils;
10+
import software.amazon.smithy.typescript.codegen.extensions.ExtensionConfigurationInterface;
11+
import software.amazon.smithy.utils.Pair;
12+
import software.amazon.smithy.utils.SmithyInternalApi;
13+
14+
/**
15+
* Adds the corresponding interface and functions for {@code HttpAuthExtensionConfiguration}.
16+
*
17+
* This is experimental for `experimentalIdentityAndAuth`.
18+
*/
19+
@SmithyInternalApi
20+
public class HttpAuthExtensionConfigurationInterface implements ExtensionConfigurationInterface {
21+
@Override
22+
public Pair<String, Dependency> name() {
23+
return Pair.of("HttpAuthExtensionConfiguration", AuthUtils.AUTH_HTTP_EXTENSION_DEPENDENCY);
24+
}
25+
26+
@Override
27+
public Pair<String, Dependency> getExtensionConfigurationFn() {
28+
return Pair.of("getHttpAuthExtensionConfiguration", AuthUtils.AUTH_HTTP_EXTENSION_DEPENDENCY);
29+
}
30+
31+
@Override
32+
public Pair<String, Dependency> resolveRuntimeConfigFn() {
33+
return Pair.of("resolveHttpAuthRuntimeConfig", AuthUtils.AUTH_HTTP_EXTENSION_DEPENDENCY);
34+
}
35+
}

0 commit comments

Comments
 (0)