32
32
import software .amazon .smithy .typescript .codegen .auth .http .sections .ResolveHttpAuthSchemeConfigFunctionReturnBlockCodeSection ;
33
33
import software .amazon .smithy .typescript .codegen .integration .RuntimeClientPlugin ;
34
34
import software .amazon .smithy .typescript .codegen .integration .RuntimeClientPlugin .Convention ;
35
- import software .amazon .smithy .typescript .codegen .sections .ClientBodyExtraCodeSection ;
36
- import software .amazon .smithy .utils .CodeInterceptor ;
37
- import software .amazon .smithy .utils .CodeSection ;
35
+ import software .amazon .smithy .typescript .codegen .util .ClientWriterConsumer ;
38
36
import software .amazon .smithy .utils .SmithyInternalApi ;
39
37
40
38
/**
@@ -52,42 +50,67 @@ public boolean matchesSettings(TypeScriptSettings settings) {
52
50
53
51
@ Override
54
52
public List <RuntimeClientPlugin > getClientPlugins () {
53
+ Map <String , ClientWriterConsumer > httpAuthSchemeParametersProvider = Map .of (
54
+ "httpAuthSchemeParametersProvider" , (w , clientBodySection ) -> {
55
+ String httpAuthSchemeParametersProviderName = "default"
56
+ + CodegenUtils .getServiceName (
57
+ clientBodySection .getSettings (),
58
+ clientBodySection .getModel (),
59
+ clientBodySection .getSymbolProvider ()
60
+ )
61
+ + "HttpAuthSchemeParametersProvider" ;
62
+ w .addImport (httpAuthSchemeParametersProviderName , null , AuthUtils .AUTH_HTTP_PROVIDER_DEPENDENCY );
63
+ w .writeInline (httpAuthSchemeParametersProviderName );
64
+ },
65
+ "identityProviderConfigProvider" , (w , s ) -> {
66
+ w .addDependency (TypeScriptDependency .SMITHY_CORE );
67
+ w .addImport ("DefaultIdentityProviderConfig" , null , TypeScriptDependency .SMITHY_CORE );
68
+ w .openBlock ("""
69
+ async (config: $LResolvedConfig) => \
70
+ new DefaultIdentityProviderConfig({""" , "})" ,
71
+ s .getSymbolProvider ().toSymbol (s .getService ()).getName (),
72
+ () -> {
73
+ SupportedHttpAuthSchemesIndex authIndex = new SupportedHttpAuthSchemesIndex (
74
+ s .getIntegrations (),
75
+ s .getModel (),
76
+ s .getSettings ());
77
+ ServiceIndex serviceIndex = ServiceIndex .of (s .getModel ());
78
+ TopDownIndex topDownIndex = TopDownIndex .of (s .getModel ());
79
+ Map <ShapeId , HttpAuthScheme > httpAuthSchemes = AuthUtils .getAllEffectiveNoAuthAwareAuthSchemes (
80
+ s .getService (), serviceIndex , authIndex , topDownIndex );
81
+ for (HttpAuthScheme scheme : httpAuthSchemes .values ()) {
82
+ if (scheme == null ) {
83
+ continue ;
84
+ }
85
+ for (ConfigField configField : scheme .getConfigFields ()) {
86
+ if (configField .type ().equals (ConfigField .Type .MAIN )) {
87
+ w .writeInline (
88
+ "$S: config.$L," ,
89
+ scheme .getSchemeId ().toString (),
90
+ configField .name ()
91
+ );
92
+ }
93
+ }
94
+ }
95
+ });
96
+ }
97
+ );
55
98
return List .of (
56
99
RuntimeClientPlugin .builder ()
57
100
.servicePredicate ((m , s ) -> s .hasTrait (EndpointRuleSetTrait .ID ))
58
101
.withConventions (
59
102
TypeScriptDependency .SMITHY_CORE .dependency ,
60
103
"HttpAuthSchemeEndpointRuleSet" ,
61
104
Convention .HAS_MIDDLEWARE )
62
- .additionalPluginFunctionParamsSupplier ((model , service , operation ) -> Map .of (
63
- "httpAuthSchemeParametersProvider" , Symbol .builder ()
64
- .name ("this.getDefaultHttpAuthSchemeParametersProvider()" )
65
- .build (),
66
- "identityProviderConfigProvider" , Symbol .builder ()
67
- .name ("this.getIdentityProviderConfigProvider()" )
68
- .build ()
69
- ))
70
- .withWriter (writer -> {
71
- String httpAuthSchemeParametersProviderName = "default"
72
- + CodegenUtils .getServiceName (s .getSettings (), s .getModel (), s .getSymbolProvider ())
73
- + "HttpAuthSchemeParametersProvider" ;
74
- w .addImport (httpAuthSchemeParametersProviderName , null , AuthUtils .AUTH_HTTP_PROVIDER_DEPENDENCY );
75
- })
105
+ .withAdditionalClientParams (httpAuthSchemeParametersProvider )
76
106
.build (),
77
107
RuntimeClientPlugin .builder ()
78
108
.servicePredicate ((m , s ) -> !s .hasTrait (EndpointRuleSetTrait .ID ))
79
109
.withConventions (
80
110
TypeScriptDependency .SMITHY_CORE .dependency ,
81
111
"HttpAuthScheme" ,
82
112
Convention .HAS_MIDDLEWARE )
83
- .additionalPluginFunctionParamsSupplier ((model , service , operation ) -> Map .of (
84
- "httpAuthSchemeParametersProvider" , Symbol .builder ()
85
- .name ("this.getDefaultHttpAuthSchemeParametersProvider()" )
86
- .build (),
87
- "identityProviderConfigProvider" , Symbol .builder ()
88
- .name ("this.getIdentityProviderConfigProvider()" )
89
- .build ()
90
- ))
113
+ .withAdditionalClientParams (httpAuthSchemeParametersProvider )
91
114
.build (),
92
115
RuntimeClientPlugin .builder ()
93
116
.inputConfig (Symbol .builder ()
@@ -106,70 +129,6 @@ public List<RuntimeClientPlugin> getClientPlugins() {
106
129
);
107
130
}
108
131
109
- @ Override
110
- public List <? extends CodeInterceptor <? extends CodeSection , TypeScriptWriter >> interceptors (
111
- TypeScriptCodegenContext codegenContext
112
- ) {
113
- return List .of (CodeInterceptor .appender (ClientBodyExtraCodeSection .class , (w , s ) -> {
114
- if (!s .getSettings ().generateClient ()
115
- || s .getSettings ().useLegacyAuth ()
116
- || !s .getApplicationProtocol ().isHttpProtocol ()) {
117
- return ;
118
- }
119
-
120
- /*
121
- private getDefaultHttpAuthSchemeParametersProvider() {
122
- return defaultWeatherHttpAuthSchemeParametersProvider;
123
- }
124
- */
125
- w .openBlock ("private getDefaultHttpAuthSchemeParametersProvider() {" , "}" , () -> {
126
- String httpAuthSchemeParametersProviderName = "default"
127
- + CodegenUtils .getServiceName (s .getSettings (), s .getModel (), s .getSymbolProvider ())
128
- + "HttpAuthSchemeParametersProvider" ;
129
- w .addImport (httpAuthSchemeParametersProviderName , null , AuthUtils .AUTH_HTTP_PROVIDER_DEPENDENCY );
130
- w .write ("return " + httpAuthSchemeParametersProviderName + ";" );
131
- });
132
-
133
- /*
134
- private getIdentityProviderConfigProvider() {
135
- return async (config: WeatherClientResolvedConfig) => new DefaultIdentityProviderConfig({
136
- "aws.auth#sigv4": config.credentials,
137
- "smithy.api#httpApiKeyAuth": config.apiKey,
138
- "smithy.api#httpBearerAuth": config.token,
139
- });
140
- }
141
- */
142
- w .openBlock ("private getIdentityProviderConfigProvider() {" , "}" , () -> {
143
- w .addDependency (TypeScriptDependency .SMITHY_CORE );
144
- w .addImport ("DefaultIdentityProviderConfig" , null , TypeScriptDependency .SMITHY_CORE );
145
- w .openBlock ("""
146
- return async (config: $LResolvedConfig) => \
147
- new DefaultIdentityProviderConfig({""" , "});" ,
148
- s .getSymbolProvider ().toSymbol (s .getService ()).getName (),
149
- () -> {
150
- SupportedHttpAuthSchemesIndex authIndex = new SupportedHttpAuthSchemesIndex (
151
- s .getIntegrations (),
152
- s .getModel (),
153
- s .getSettings ());
154
- ServiceIndex serviceIndex = ServiceIndex .of (s .getModel ());
155
- TopDownIndex topDownIndex = TopDownIndex .of (s .getModel ());
156
- Map <ShapeId , HttpAuthScheme > httpAuthSchemes = AuthUtils .getAllEffectiveNoAuthAwareAuthSchemes (
157
- s .getService (), serviceIndex , authIndex , topDownIndex );
158
- for (HttpAuthScheme scheme : httpAuthSchemes .values ()) {
159
- if (scheme == null ) {
160
- continue ;
161
- }
162
- for (ConfigField configField : scheme .getConfigFields ()) {
163
- if (configField .type ().equals (ConfigField .Type .MAIN )) {
164
- w .write ("$S: config.$L," , scheme .getSchemeId ().toString (), configField .name ());
165
- }
166
- }
167
- }
168
- });
169
- });
170
- }));
171
- }
172
-
173
132
@ Override
174
133
public void customize (TypeScriptCodegenContext codegenContext ) {
175
134
if (!codegenContext .settings ().generateClient ()
@@ -223,14 +182,6 @@ public void customize(TypeScriptCodegenContext codegenContext) {
223
182
});
224
183
}
225
184
226
- private String inlineHttpAuthSchemeParametersProvider () {
227
- return "" ;
228
- }
229
-
230
- private String inlineIdentityProviderConfigProvider () {
231
- return "" ;
232
- }
233
-
234
185
/*
235
186
export interface HttpAuthSchemeInputConfig {
236
187
httpAuthSchemes?: HttpAuthScheme[];
0 commit comments