Skip to content

Commit 7f9329d

Browse files
Merge branch 'main' into RFC30/tests
2 parents 2284425 + 47b3d23 commit 7f9329d

File tree

7 files changed

+65
-91
lines changed

7 files changed

+65
-91
lines changed

aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsPresigningDecorator.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,8 @@ class AwsPresignedFluentBuilderMethod(
320320
"""
321321
#{alternate_presigning_serializer}
322322
323-
let runtime_plugins = #{Operation}::register_runtime_plugins(
324-
#{RuntimePlugins}::new(),
325-
self.handle.clone(),
323+
let runtime_plugins = #{Operation}::operation_runtime_plugins(
324+
self.handle.runtime_plugins.clone(),
326325
self.config_override
327326
)
328327
.with_client_plugin(#{SigV4PresigningRuntimePlugin}::new(presigning_config, #{payload_override}))
@@ -344,8 +343,7 @@ class AwsPresignedFluentBuilderMethod(
344343
*codegenScope,
345344
"Operation" to codegenContext.symbolProvider.toSymbol(section.operationShape),
346345
"OperationError" to section.operationErrorType,
347-
"RuntimePlugins" to RuntimeType.smithyRuntimeApi(runtimeConfig)
348-
.resolve("client::runtime_plugin::RuntimePlugins"),
346+
"RuntimePlugins" to RuntimeType.runtimePlugins(runtimeConfig),
349347
"SharedInterceptor" to RuntimeType.smithyRuntimeApi(runtimeConfig).resolve("client::interceptors")
350348
.resolve("SharedInterceptor"),
351349
"SigV4PresigningRuntimePlugin" to AwsRuntimeType.presigningInterceptor(runtimeConfig)

aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CredentialProviders.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class CredentialsIdentityResolverRegistration(
139139
override fun section(section: ServiceRuntimePluginSection): Writable = writable {
140140
when (section) {
141141
is ServiceRuntimePluginSection.AdditionalConfig -> {
142-
rustBlockTemplate("if let Some(credentials_cache) = self.handle.conf.credentials_cache()") {
142+
rustBlockTemplate("if let Some(credentials_cache) = ${section.serviceConfigName}.credentials_cache()") {
143143
section.registerIdentityResolver(this, runtimeConfig) {
144144
rustTemplate(
145145
"""

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/OperationGenerator.kt

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators
77

88
import software.amazon.smithy.model.shapes.OperationShape
99
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
10-
import software.amazon.smithy.rust.codegen.client.smithy.ClientRustModule
1110
import software.amazon.smithy.rust.codegen.client.smithy.customize.AuthOption
1211
import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator
1312
import software.amazon.smithy.rust.codegen.client.smithy.endpoint.generators.EndpointParamsInterceptorGenerator
@@ -23,7 +22,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.rust
2322
import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock
2423
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
2524
import software.amazon.smithy.rust.codegen.core.rustlang.writable
26-
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig
2725
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType
2826
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.preludeScope
2927
import software.amazon.smithy.rust.codegen.core.smithy.customize.writeCustomizations
@@ -45,39 +43,6 @@ open class OperationGenerator(
4543
// TODO(enableNewSmithyRuntimeCleanup): Remove the `traitGenerator`
4644
private val traitGenerator: HttpBoundProtocolTraitImplGenerator,
4745
) {
48-
companion object {
49-
fun registerDefaultRuntimePluginsFn(runtimeConfig: RuntimeConfig): RuntimeType =
50-
RuntimeType.forInlineFun("register_default_runtime_plugins", ClientRustModule.Operation) {
51-
rustTemplate(
52-
"""
53-
pub(crate) fn register_default_runtime_plugins(
54-
runtime_plugins: #{RuntimePlugins},
55-
operation: impl #{RuntimePlugin} + 'static,
56-
handle: #{Arc}<crate::client::Handle>,
57-
config_override: #{Option}<crate::config::Builder>,
58-
) -> #{RuntimePlugins} {
59-
let mut runtime_plugins = runtime_plugins
60-
.with_client_plugin(handle.conf.clone())
61-
.with_client_plugin(crate::config::ServiceRuntimePlugin::new(handle))
62-
.with_client_plugin(#{NoAuthRuntimePlugin}::new())
63-
.with_operation_plugin(operation);
64-
if let Some(config_override) = config_override {
65-
runtime_plugins = runtime_plugins.with_operation_plugin(config_override);
66-
}
67-
runtime_plugins
68-
}
69-
""",
70-
*preludeScope,
71-
"Arc" to RuntimeType.Arc,
72-
"RuntimePlugin" to RuntimeType.runtimePlugin(runtimeConfig),
73-
"RuntimePlugins" to RuntimeType.smithyRuntimeApi(runtimeConfig)
74-
.resolve("client::runtime_plugin::RuntimePlugins"),
75-
"NoAuthRuntimePlugin" to RuntimeType.smithyRuntime(runtimeConfig)
76-
.resolve("client::auth::no_auth::NoAuthRuntimePlugin"),
77-
)
78-
}
79-
}
80-
8146
private val model = codegenContext.model
8247
private val runtimeConfig = codegenContext.runtimeConfig
8348
private val symbolProvider = codegenContext.symbolProvider
@@ -180,18 +145,16 @@ open class OperationGenerator(
180145
#{invoke_with_stop_point}(input, runtime_plugins, stop_point).await
181146
}
182147
183-
pub(crate) fn register_runtime_plugins(
184-
runtime_plugins: #{RuntimePlugins},
185-
handle: #{Arc}<crate::client::Handle>,
148+
pub(crate) fn operation_runtime_plugins(
149+
client_runtime_plugins: #{RuntimePlugins},
186150
config_override: #{Option}<crate::config::Builder>,
187151
) -> #{RuntimePlugins} {
188-
#{register_default_runtime_plugins}(
189-
runtime_plugins,
190-
Self::new(),
191-
handle,
192-
config_override
193-
)
194-
#{additional_runtime_plugins}
152+
let mut runtime_plugins = client_runtime_plugins.with_operation_plugin(Self::new());
153+
if let Some(config_override) = config_override {
154+
runtime_plugins = runtime_plugins.with_operation_plugin(config_override);
155+
}
156+
runtime_plugins
157+
#{additional_runtime_plugins}
195158
}
196159
""",
197160
*codegenScope,
@@ -200,10 +163,9 @@ open class OperationGenerator(
200163
"InterceptorContext" to RuntimeType.interceptorContext(runtimeConfig),
201164
"OrchestratorError" to RuntimeType.smithyRuntimeApi(runtimeConfig).resolve("client::orchestrator::error::OrchestratorError"),
202165
"RuntimePlugin" to RuntimeType.runtimePlugin(runtimeConfig),
203-
"RuntimePlugins" to RuntimeType.smithyRuntimeApi(runtimeConfig).resolve("client::runtime_plugin::RuntimePlugins"),
166+
"RuntimePlugins" to RuntimeType.runtimePlugins(runtimeConfig),
204167
"StopPoint" to RuntimeType.smithyRuntime(runtimeConfig).resolve("client::orchestrator::StopPoint"),
205168
"invoke_with_stop_point" to RuntimeType.smithyRuntime(runtimeConfig).resolve("client::orchestrator::invoke_with_stop_point"),
206-
"register_default_runtime_plugins" to registerDefaultRuntimePluginsFn(runtimeConfig),
207169
"additional_runtime_plugins" to writable {
208170
writeCustomizations(
209171
operationCustomizations,

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,13 @@ class PaginatorGenerator private constructor(
240240
if (codegenContext.smithyRuntimeMode.defaultToOrchestrator) {
241241
rustTemplate(
242242
"""
243-
let runtime_plugins = #{operation}::register_runtime_plugins(
244-
#{RuntimePlugins}::new(),
245-
handle,
246-
None
243+
let runtime_plugins = #{operation}::operation_runtime_plugins(
244+
handle.runtime_plugins.clone(),
245+
None,
247246
);
248247
""",
249248
*codegenScope,
250-
"RuntimePlugins" to RuntimeType.smithyRuntimeApi(runtimeConfig)
251-
.resolve("client::runtime_plugin::RuntimePlugins"),
249+
"RuntimePlugins" to RuntimeType.runtimePlugins(runtimeConfig),
252250
)
253251
}
254252
},

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ServiceRuntimePluginGenerator.kt

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ sealed class ServiceRuntimePluginSection(name: String) : Section(name) {
3131
/**
3232
* Hook for adding additional things to config inside service runtime plugins.
3333
*/
34-
data class AdditionalConfig(val newLayerName: String) : ServiceRuntimePluginSection("AdditionalConfig") {
34+
data class AdditionalConfig(val newLayerName: String, val serviceConfigName: String) : ServiceRuntimePluginSection("AdditionalConfig") {
3535
/** Adds a value to the config bag */
3636
fun putConfigValue(writer: RustWriter, value: Writable) {
3737
writer.rust("$newLayerName.store_put(#T);", value)
@@ -107,27 +107,28 @@ class ServiceRuntimePluginGenerator(
107107
customizations: List<ServiceRuntimePluginCustomization>,
108108
) {
109109
val additionalConfig = writable {
110-
writeCustomizations(customizations, ServiceRuntimePluginSection.AdditionalConfig("cfg"))
110+
writeCustomizations(customizations, ServiceRuntimePluginSection.AdditionalConfig("cfg", "_service_config"))
111111
}
112112
writer.rustTemplate(
113113
"""
114-
// TODO(enableNewSmithyRuntimeLaunch) Remove `allow(dead_code)` as well as a field `handle` when
115-
// the field is no longer used.
116-
##[allow(dead_code)]
117114
##[derive(Debug)]
118115
pub(crate) struct ServiceRuntimePlugin {
119-
handle: #{Arc}<crate::client::Handle>,
116+
config: #{Option}<#{FrozenLayer}>,
120117
}
121118
122119
impl ServiceRuntimePlugin {
123-
pub fn new(handle: #{Arc}<crate::client::Handle>) -> Self {
124-
Self { handle }
120+
pub fn new(_service_config: crate::config::Config) -> Self {
121+
Self {
122+
config: {
123+
#{config}
124+
},
125+
}
125126
}
126127
}
127128
128129
impl #{RuntimePlugin} for ServiceRuntimePlugin {
129130
fn config(&self) -> #{Option}<#{FrozenLayer}> {
130-
#{config}
131+
self.config.clone()
131132
}
132133
133134
fn interceptors(&self, interceptors: &mut #{InterceptorRegistrar}) {
@@ -145,13 +146,7 @@ class ServiceRuntimePluginGenerator(
145146
rustTemplate(
146147
"""
147148
let mut cfg = #{Layer}::new(${codegenContext.serviceShape.id.name.dq()});
148-
149-
// TODO(enableNewSmithyRuntimeLaunch): Make it possible to set retry classifiers at the service level.
150-
// Retry classifiers can also be set at the operation level and those should be added to the
151-
// list of classifiers defined here, rather than replacing them.
152-
153149
#{additional_config}
154-
155150
Some(cfg.freeze())
156151
""",
157152
*codegenScope,

codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.rustTypeParameters
4141
import software.amazon.smithy.rust.codegen.core.rustlang.stripOuter
4242
import software.amazon.smithy.rust.codegen.core.rustlang.withBlockTemplate
4343
import software.amazon.smithy.rust.codegen.core.rustlang.writable
44+
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig
4445
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType
4546
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.preludeScope
4647
import software.amazon.smithy.rust.codegen.core.smithy.RustCrate
@@ -125,6 +126,7 @@ class FluentClientGenerator(
125126
}
126127
},
127128
"RetryConfig" to RuntimeType.smithyTypes(runtimeConfig).resolve("retry::RetryConfig"),
129+
"RuntimePlugins" to RuntimeType.runtimePlugins(runtimeConfig),
128130
"TimeoutConfig" to RuntimeType.smithyTypes(runtimeConfig).resolve("timeout::TimeoutConfig"),
129131
// TODO(enableNewSmithyRuntimeCleanup): Delete the generics when cleaning up middleware
130132
"generics_decl" to generics.decl,
@@ -182,18 +184,13 @@ class FluentClientGenerator(
182184
##[derive(Debug)]
183185
pub(crate) struct Handle {
184186
pub(crate) conf: crate::Config,
187+
pub(crate) runtime_plugins: #{RuntimePlugins},
185188
}
186189
187190
#{client_docs:W}
188-
##[derive(::std::fmt::Debug)]
191+
##[derive(#{Clone}, ::std::fmt::Debug)]
189192
pub struct Client {
190-
handle: #{Arc}<Handle>
191-
}
192-
193-
impl #{Clone} for Client {
194-
fn clone(&self) -> Self {
195-
Self { handle: self.handle.clone() }
196-
}
193+
handle: #{Arc}<Handle>,
197194
}
198195
199196
impl Client {
@@ -215,7 +212,12 @@ class FluentClientGenerator(
215212
}
216213
217214
Self {
218-
handle: #{Arc}::new(Handle { conf })
215+
handle: #{Arc}::new(
216+
Handle {
217+
conf: conf.clone(),
218+
runtime_plugins: #{base_client_runtime_plugins}(conf),
219+
}
220+
)
219221
}
220222
}
221223
@@ -229,9 +231,7 @@ class FluentClientGenerator(
229231
// This is currently kept around so the tests still compile in both modes
230232
/// Creates a client with the given service configuration.
231233
pub fn with_config<C, M, R>(_client: #{client}::Client<C, M, R>, conf: crate::Config) -> Self {
232-
Self {
233-
handle: #{Arc}::new(Handle { conf })
234-
}
234+
Self::from_conf(conf)
235235
}
236236
237237
##[doc(hidden)]
@@ -244,6 +244,7 @@ class FluentClientGenerator(
244244
}
245245
""",
246246
*clientScope,
247+
"base_client_runtime_plugins" to baseClientRuntimePluginsFn(runtimeConfig),
247248
)
248249
}
249250
}
@@ -505,8 +506,7 @@ class FluentClientGenerator(
505506
"Operation" to operationSymbol,
506507
"OperationError" to errorType,
507508
"OperationOutput" to outputType,
508-
"RuntimePlugins" to RuntimeType.smithyRuntimeApi(runtimeConfig)
509-
.resolve("client::runtime_plugin::RuntimePlugins"),
509+
"RuntimePlugins" to RuntimeType.runtimePlugins(runtimeConfig),
510510
"SendResult" to ClientRustModule.Client.customize.toType()
511511
.resolve("internal::SendResult"),
512512
"SdkError" to RuntimeType.sdkError(runtimeConfig),
@@ -516,9 +516,8 @@ class FluentClientGenerator(
516516
##[doc(hidden)]
517517
pub async fn send_orchestrator(self) -> #{Result}<#{OperationOutput}, #{SdkError}<#{OperationError}, #{HttpResponse}>> {
518518
let input = self.inner.build().map_err(#{SdkError}::construction_failure)?;
519-
let runtime_plugins = #{Operation}::register_runtime_plugins(
520-
#{RuntimePlugins}::new(),
521-
self.handle,
519+
let runtime_plugins = #{Operation}::operation_runtime_plugins(
520+
self.handle.runtime_plugins.clone(),
522521
self.config_override
523522
);
524523
#{Operation}::orchestrate(&runtime_plugins, input).await
@@ -647,6 +646,26 @@ class FluentClientGenerator(
647646
}
648647
}
649648

649+
private fun baseClientRuntimePluginsFn(runtimeConfig: RuntimeConfig): RuntimeType =
650+
RuntimeType.forInlineFun("base_client_runtime_plugins", ClientRustModule.config) {
651+
rustTemplate(
652+
"""
653+
pub(crate) fn base_client_runtime_plugins(
654+
config: crate::Config,
655+
) -> #{RuntimePlugins} {
656+
#{RuntimePlugins}::new()
657+
.with_client_plugin(config.clone())
658+
.with_client_plugin(crate::config::ServiceRuntimePlugin::new(config))
659+
.with_client_plugin(#{NoAuthRuntimePlugin}::new())
660+
}
661+
""",
662+
*preludeScope,
663+
"RuntimePlugins" to RuntimeType.runtimePlugins(runtimeConfig),
664+
"NoAuthRuntimePlugin" to RuntimeType.smithyRuntime(runtimeConfig)
665+
.resolve("client::auth::no_auth::NoAuthRuntimePlugin"),
666+
)
667+
}
668+
650669
/**
651670
* For a given `operation` shape, return a list of strings where each string describes the name and input type of one of
652671
* the operation's corresponding fluent builder methods as well as that method's documentation from the smithy model

codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ data class RuntimeType(val path: String, val dependency: RustDependency? = null)
338338
smithyTypes(runtimeConfig).resolve("config_bag::ConfigBag")
339339
fun configBagAccessors(runtimeConfig: RuntimeConfig): RuntimeType =
340340
smithyRuntimeApi(runtimeConfig).resolve("client::config_bag_accessors::ConfigBagAccessors")
341+
fun runtimePlugins(runtimeConfig: RuntimeConfig): RuntimeType =
342+
smithyRuntimeApi(runtimeConfig).resolve("client::runtime_plugin::RuntimePlugins")
341343
fun boxError(runtimeConfig: RuntimeConfig): RuntimeType =
342344
smithyRuntimeApi(runtimeConfig).resolve("box_error::BoxError")
343345
fun interceptor(runtimeConfig: RuntimeConfig): RuntimeType =

0 commit comments

Comments
 (0)