Skip to content

Commit 6e6e572

Browse files
authored
fix: allow authscheme resolver to access client ref (#1548)
1 parent 5aea94e commit 6e6e572

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

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

8+
import java.util.ArrayList;
9+
import java.util.List;
810
import java.util.Optional;
911
import software.amazon.smithy.codegen.core.Symbol;
1012
import software.amazon.smithy.utils.SmithyBuilder;
@@ -19,6 +21,7 @@ public final record ResolveConfigFunction(
1921
Symbol resolveConfigFunction,
2022
Symbol inputConfig,
2123
Symbol resolvedConfig,
24+
List<String> addArgs,
2225
Optional<Symbol> previouslyResolved
2326
) implements ToSmithyBuilder<ResolveConfigFunction> {
2427

@@ -32,13 +35,15 @@ public Builder toBuilder() {
3235
.resolveConfigFunction(resolveConfigFunction)
3336
.inputConfig(inputConfig)
3437
.resolvedConfig(resolvedConfig)
38+
.addArgs(addArgs)
3539
.previouslyResolved(previouslyResolved.orElse(null));
3640
}
3741

3842
public static final class Builder implements SmithyBuilder<ResolveConfigFunction> {
3943
private Symbol resolveConfigFunction;
4044
private Symbol inputConfig;
4145
private Symbol resolvedConfig;
46+
private List<String> addArgs = new ArrayList<>();
4247
private Symbol previouslyResolved;
4348

4449
@Override
@@ -47,6 +52,7 @@ public ResolveConfigFunction build() {
4752
SmithyBuilder.requiredState("resolveConfigFunction", resolveConfigFunction),
4853
SmithyBuilder.requiredState("inputConfig", inputConfig),
4954
SmithyBuilder.requiredState("resolvedConfig", resolvedConfig),
55+
SmithyBuilder.requiredState("addArgs", addArgs),
5056
Optional.ofNullable(previouslyResolved));
5157
}
5258

@@ -65,6 +71,11 @@ public Builder resolvedConfig(Symbol resolvedConfig) {
6571
return this;
6672
}
6773

74+
public Builder addArgs(List<String> args) {
75+
this.addArgs = args;
76+
return this;
77+
}
78+
6879
public Builder previouslyResolved(Symbol previouslyResolved) {
6980
this.previouslyResolved = previouslyResolved;
7081
return this;

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ public List<RuntimeClientPlugin> getClientPlugins() {
8585
.namespace(AuthUtils.HTTP_AUTH_SCHEME_PROVIDER_MODULE, "/")
8686
.name("resolveHttpAuthSchemeConfig")
8787
.build())
88+
.additionalResolveFunctionParamsSupplier((m, s, o) -> Map.of(
89+
"client", Symbol.builder().name("() => this").build()
90+
))
8891
.build()
8992
);
9093
}
@@ -364,7 +367,8 @@ private void generateResolveHttpAuthSchemeConfigFunction(
364367
.filter(e -> e.getValue().previouslyResolved().isPresent())
365368
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
366369
w.writeDocs("@internal");
367-
w.writeInline("export const resolveHttpAuthSchemeConfig = <T>(config: T & HttpAuthSchemeInputConfig");
370+
w.writeInline("""
371+
export const resolveHttpAuthSchemeConfig = <T>(config: T & HttpAuthSchemeInputConfig""");
368372
if (!previousResolvedFunctions.isEmpty()) {
369373
w.writeInline(" & ");
370374
Iterator<ResolveConfigFunction> iter = previousResolvedFunctions.values().iterator();
@@ -376,7 +380,9 @@ private void generateResolveHttpAuthSchemeConfigFunction(
376380
}
377381
}
378382
}
379-
w.write("): T & HttpAuthSchemeResolvedConfig => {");
383+
w.write("""
384+
, { client }: { client: () => { config: AwsSdkSigV4AuthResolvedConfig } }
385+
): T & HttpAuthSchemeResolvedConfig => {""");
380386
w.indent();
381387
w.pushState(ResolveHttpAuthSchemeConfigFunctionConfigFieldsCodeSection.builder()
382388
.service(s.getService())
@@ -402,7 +408,18 @@ private void generateResolveHttpAuthSchemeConfigFunction(
402408
Integer i = 0;
403409
String configName = "config";
404410
for (ResolveConfigFunction resolveConfigFunction : resolveConfigFunctions.values()) {
405-
w.write("const config_$L = $T($L);", i, resolveConfigFunction.resolveConfigFunction(), configName);
411+
w.openBlock(
412+
"const config_$L = $T($L",
413+
");",
414+
i,
415+
resolveConfigFunction.resolveConfigFunction(),
416+
configName,
417+
() -> {
418+
for (String addArg : resolveConfigFunction.addArgs()) {
419+
w.writeInline(", $L", addArg);
420+
}
421+
}
422+
);
406423
configName = "config_" + i;
407424
i++;
408425
}

0 commit comments

Comments
 (0)