diff --git a/aws/sdk-adhoc-test/build.gradle.kts b/aws/sdk-adhoc-test/build.gradle.kts index 98ad9531052dea96cecc13335becfbd0de6e6f4b..fbd40ae1ca244c09bc0e3854fc0905d939574db6 100644 --- a/aws/sdk-adhoc-test/build.gradle.kts +++ b/aws/sdk-adhoc-test/build.gradle.kts @@ -46,7 +46,6 @@ val allCodegenTests = listOf( , "codegen": { "includeFluentClient": false, - "enableNewCrateOrganizationScheme": true }, "customizationConfig": { "awsSdk": { @@ -63,7 +62,6 @@ val allCodegenTests = listOf( , "codegen": { "includeFluentClient": false, - "enableNewCrateOrganizationScheme": true }, "customizationConfig": { "awsSdk": { diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CredentialProviders.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CredentialProviders.kt index 84d644a43caa2c9d830069c8dbe9c750f616d41f..eb032121359ab315452c0188317a52b7b2f031ac 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CredentialProviders.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CredentialProviders.kt @@ -32,7 +32,7 @@ class CredentialsProviderDecorator : ClientCodegenDecorator { codegenContext: ClientCodegenContext, baseCustomizations: List, ): List = - baseCustomizations.letIf(codegenContext.settings.codegenConfig.enableNewSmithyRuntime) { + baseCustomizations.letIf(codegenContext.smithyRuntimeMode.generateOrchestrator) { it + listOf(CredentialsIdentityResolverRegistration(codegenContext)) } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpConnectorConfigCustomization.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpConnectorConfigCustomization.kt index 75c252d0fbc3142f7715c9699f7f776a460cefa4..d64ddea9b3ffe539cd751e1d6bbcc0f20ba180f2 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpConnectorConfigCustomization.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpConnectorConfigCustomization.kt @@ -26,7 +26,7 @@ class HttpConnectorDecorator : ClientCodegenDecorator { codegenContext: ClientCodegenContext, baseCustomizations: List, ): List = - baseCustomizations.letIf(!codegenContext.settings.codegenConfig.enableNewSmithyRuntime) { + baseCustomizations.letIf(codegenContext.smithyRuntimeMode.exclusivelyGenerateMiddleware) { it + HttpConnectorConfigCustomization(codegenContext) } } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpRequestChecksumDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpRequestChecksumDecorator.kt index f2913a1aa7e56e51e110d7e807ae4d9046c15082..b72293b1fa450c28b24fc5512a04af2aa0ffb2b6 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpRequestChecksumDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpRequestChecksumDecorator.kt @@ -44,7 +44,7 @@ class HttpRequestChecksumDecorator : ClientCodegenDecorator { // TODO(enableNewSmithyRuntime): Implement checksumming via interceptor and delete this decorator private fun applies(codegenContext: ClientCodegenContext): Boolean = - !codegenContext.settings.codegenConfig.enableNewSmithyRuntime + codegenContext.smithyRuntimeMode.exclusivelyGenerateMiddleware override fun operationCustomizations( codegenContext: ClientCodegenContext, diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpResponseChecksumDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpResponseChecksumDecorator.kt index 832ab7e07dffef91fe5cd98c900cbd406296462e..cebc4e5cbac707fa6c4477e26831fb509ff6724a 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpResponseChecksumDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpResponseChecksumDecorator.kt @@ -35,7 +35,7 @@ class HttpResponseChecksumDecorator : ClientCodegenDecorator { // TODO(enableNewSmithyRuntime): Implement checksumming via interceptor and delete this decorator private fun applies(codegenContext: ClientCodegenContext, operationShape: OperationShape): Boolean = - !codegenContext.settings.codegenConfig.enableNewSmithyRuntime && operationShape.outputShape != ShapeId.from("com.amazonaws.s3#GetObjectOutput") + codegenContext.smithyRuntimeMode.generateMiddleware && operationShape.outputShape != ShapeId.from("com.amazonaws.s3#GetObjectOutput") override fun operationCustomizations( codegenContext: ClientCodegenContext, diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/IntegrationTestDependencies.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/IntegrationTestDependencies.kt index 6eedc44a897dde9b4f82ccaffa2e0189218a9fee..556e71d2b064092c9529c4737f4bac08b59d86b9 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/IntegrationTestDependencies.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/IntegrationTestDependencies.kt @@ -126,7 +126,7 @@ class S3TestDependencies(private val codegenContext: ClientCodegenContext) : Lib // TODO(enableNewSmithyRuntime): These additional dependencies may not be needed anymore when removing this flag // depending on if the sra-test is kept around or not. - if (codegenContext.settings.codegenConfig.enableNewSmithyRuntime) { + if (codegenContext.smithyRuntimeMode.generateOrchestrator) { addDependency(CargoDependency.smithyRuntime(codegenContext.runtimeConfig).toDevDependency()) addDependency(CargoDependency.smithyRuntimeApi(codegenContext.runtimeConfig).toDevDependency()) } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/InvocationIdDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/InvocationIdDecorator.kt index abf317570fc942cd2d0cbf478348724e09ac7299..c608f1c573f8d85d9ce00fb43b496ce4600e3007 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/InvocationIdDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/InvocationIdDecorator.kt @@ -21,7 +21,7 @@ class InvocationIdDecorator : ClientCodegenDecorator { codegenContext: ClientCodegenContext, baseCustomizations: List, ): List = - baseCustomizations.letIf(codegenContext.settings.codegenConfig.enableNewSmithyRuntime) { + baseCustomizations.letIf(codegenContext.smithyRuntimeMode.generateOrchestrator) { it + listOf(InvocationIdRuntimePluginCustomization(codegenContext)) } } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RecursionDetectionDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RecursionDetectionDecorator.kt index 09e6a30742963599be9b263e8a24816b30345964..4685acad75899e27442f56a5c69067fe39b6a981 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RecursionDetectionDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RecursionDetectionDecorator.kt @@ -22,7 +22,7 @@ class RecursionDetectionDecorator : ClientCodegenDecorator { codegenContext: ClientCodegenContext, baseCustomizations: List, ): List = - baseCustomizations.letIf(codegenContext.settings.codegenConfig.enableNewSmithyRuntime) { + baseCustomizations.letIf(codegenContext.smithyRuntimeMode.generateOrchestrator) { it + listOf(RecursionDetectionRuntimePluginCustomization(codegenContext)) } } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SigV4AuthDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SigV4AuthDecorator.kt index f4973330c516ff7e8b20f5bc4b4ad745af4f1b5a..6131e50c79a6910e42ca39e29578576e3fcc772b 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SigV4AuthDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SigV4AuthDecorator.kt @@ -33,7 +33,7 @@ class SigV4AuthDecorator : ClientCodegenDecorator { codegenContext: ClientCodegenContext, baseCustomizations: List, ): List = - baseCustomizations.letIf(codegenContext.settings.codegenConfig.enableNewSmithyRuntime) { + baseCustomizations.letIf(codegenContext.smithyRuntimeMode.generateOrchestrator) { it + listOf(AuthServiceRuntimePluginCustomization(codegenContext)) } @@ -42,7 +42,7 @@ class SigV4AuthDecorator : ClientCodegenDecorator { operation: OperationShape, baseCustomizations: List, ): List = - baseCustomizations.letIf(codegenContext.settings.codegenConfig.enableNewSmithyRuntime) { + baseCustomizations.letIf(codegenContext.smithyRuntimeMode.generateOrchestrator) { it + listOf(AuthOperationRuntimePluginCustomization(codegenContext)) } } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/UserAgentDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/UserAgentDecorator.kt index 0e83d2c99dab5a2aa70f909ab9bdf23017935750..90183fbf93ca0142396e2feb70cf3386efae21ee 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/UserAgentDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/UserAgentDecorator.kt @@ -55,7 +55,7 @@ class UserAgentDecorator : ClientCodegenDecorator { codegenContext: ClientCodegenContext, baseCustomizations: List, ): List = - baseCustomizations.letIf(codegenContext.settings.codegenConfig.enableNewSmithyRuntime) { + baseCustomizations.letIf(codegenContext.smithyRuntimeMode.generateOrchestrator) { it + listOf(AddApiMetadataIntoConfigBag(codegenContext)) } diff --git a/aws/sdk/build.gradle.kts b/aws/sdk/build.gradle.kts index 06355aaab66ef7860c1c79a41429c3e173e9bc09..1f92a77b7507f9c5b7b3701460d97cad9ba5cf56 100644 --- a/aws/sdk/build.gradle.kts +++ b/aws/sdk/build.gradle.kts @@ -102,8 +102,7 @@ fun generateSmithyBuild(services: AwsServices): String { "renameErrors": false, "debugMode": $debugMode, "eventStreamAllowList": [$eventStreamAllowListMembers], - "enableNewCrateOrganizationScheme": true, - "enableNewSmithyRuntime": false + "enableNewSmithyRuntime": "middleware" }, "service": "${service.service}", "module": "$moduleName", diff --git a/aws/sra-test/build.gradle.kts b/aws/sra-test/build.gradle.kts index 7344916af095da157363e93f6eaffc25a62d7aa2..669f231741c1e41de9c234e3ab16daa5d967ec5e 100644 --- a/aws/sra-test/build.gradle.kts +++ b/aws/sra-test/build.gradle.kts @@ -65,7 +65,8 @@ val allCodegenTests = servicesToGenerate.map { , "codegen": { "includeFluentClient": false, - "enableNewSmithyRuntime": true + ${ ""/* "enableNewSmithyRuntime": "both_default_middleware" */ } + "enableNewSmithyRuntime": "orchestrator" }, "customizationConfig": { "awsSdk": { diff --git a/aws/sra-test/integration-tests/aws-sdk-s3/benches/middleware_vs_orchestrator.rs b/aws/sra-test/integration-tests/aws-sdk-s3/benches/middleware_vs_orchestrator.rs index ba9d003aa33c2bfc6ea1aeaba7cc3f6848509f14..622cdaca44cfb9fe072fdc7a2c07014e00199999 100644 --- a/aws/sra-test/integration-tests/aws-sdk-s3/benches/middleware_vs_orchestrator.rs +++ b/aws/sra-test/integration-tests/aws-sdk-s3/benches/middleware_vs_orchestrator.rs @@ -107,7 +107,7 @@ async fn orchestrator(client: &s3::Client) { .list_objects_v2() .bucket("test-bucket") .prefix("prefix~") - .send_v2_with_plugin(Some(FixupPlugin { + .send_orchestrator_with_plugin(Some(FixupPlugin { region: client .conf() .region() diff --git a/aws/sra-test/integration-tests/aws-sdk-s3/tests/sra_test.rs b/aws/sra-test/integration-tests/aws-sdk-s3/tests/sra_test.rs index 464c815d686d14a79cc22ce1374534d5825e642a..3fe7e6373ea336ef7b9684676a577e8423e96bcb 100644 --- a/aws/sra-test/integration-tests/aws-sdk-s3/tests/sra_test.rs +++ b/aws/sra-test/integration-tests/aws-sdk-s3/tests/sra_test.rs @@ -41,7 +41,7 @@ async fn sra_test() { .config_override(aws_sdk_s3::Config::builder().force_path_style(false)) .bucket("test-bucket") .prefix("prefix~") - .send_v2_with_plugin(Some(fixup)) + .send_orchestrator_with_plugin(Some(fixup)) .await ); // To regenerate the test: diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientCodegenContext.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientCodegenContext.kt index e0ec0afb6e25b5efadf50927b0f6a6946a2c5874..92a8a9f8ca9638752d343464eaf4a4a4550c9622 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientCodegenContext.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientCodegenContext.kt @@ -32,4 +32,6 @@ data class ClientCodegenContext( val rootDecorator: ClientCodegenDecorator, ) : CodegenContext( model, symbolProvider, moduleDocProvider, serviceShape, protocol, settings, CodegenTarget.CLIENT, -) +) { + val smithyRuntimeMode: SmithyRuntimeMode get() = settings.codegenConfig.enableNewSmithyRuntime +} diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientRustSettings.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientRustSettings.kt index e6680d3e0e9559e160d9814ab6d282d066409021..d7246cf986cade87333b3614b5e1f665b1ad5269 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientRustSettings.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientRustSettings.kt @@ -72,6 +72,43 @@ data class ClientRustSettings( } } +// TODO(enableNewSmithyRuntime): Remove this mode after switching to the orchestrator +enum class SmithyRuntimeMode { + Middleware, + BothDefaultMiddleware, + BothDefaultOrchestrator, + Orchestrator, + ; + + val exclusivelyGenerateMiddleware: Boolean get() = generateMiddleware && !generateOrchestrator + + val generateMiddleware: Boolean get() = when (this) { + Middleware, BothDefaultMiddleware, BothDefaultOrchestrator -> true + else -> false + } + + val generateOrchestrator: Boolean get() = when (this) { + Orchestrator, BothDefaultMiddleware, BothDefaultOrchestrator -> true + else -> false + } + + val defaultToMiddleware: Boolean get() = when (this) { + Middleware, BothDefaultMiddleware -> true + else -> false + } + val defaultToOrchestrator: Boolean get() = !defaultToMiddleware + + companion object { + fun fromString(value: String): SmithyRuntimeMode = when (value) { + "middleware" -> Middleware + "orchestrator" -> Orchestrator + "both_default_middleware" -> BothDefaultMiddleware + "both_default_orchestrator" -> BothDefaultOrchestrator + else -> throw IllegalArgumentException("unknown runtime mode: $value") + } + } +} + /** * [renameExceptions]: Rename `Exception` to `Error` in the generated SDK * [includeFluentClient]: Generate a `client` module in the generated SDK (currently the AWS SDK sets this to `false` @@ -87,7 +124,7 @@ data class ClientCodegenConfig( // TODO(EventStream): [CLEANUP] Remove this property when turning on Event Stream for all services val eventStreamAllowList: Set = defaultEventStreamAllowList, // TODO(SmithyRuntime): Remove this once we commit to switch to aws-smithy-runtime and aws-smithy-runtime-api - val enableNewSmithyRuntime: Boolean = defaultEnableNewSmithyRuntime, + val enableNewSmithyRuntime: SmithyRuntimeMode = defaultEnableNewSmithyRuntime, ) : CoreCodegenConfig( formatTimeoutSeconds, debugMode, ) { @@ -96,7 +133,7 @@ data class ClientCodegenConfig( private const val defaultIncludeFluentClient = true private const val defaultAddMessageToErrors = true private val defaultEventStreamAllowList: Set = emptySet() - private const val defaultEnableNewSmithyRuntime = false + private val defaultEnableNewSmithyRuntime = SmithyRuntimeMode.Middleware fun fromCodegenConfigAndNode(coreCodegenConfig: CoreCodegenConfig, node: Optional) = if (node.isPresent) { @@ -109,7 +146,9 @@ data class ClientCodegenConfig( renameExceptions = node.get().getBooleanMemberOrDefault("renameErrors", defaultRenameExceptions), includeFluentClient = node.get().getBooleanMemberOrDefault("includeFluentClient", defaultIncludeFluentClient), addMessageToErrors = node.get().getBooleanMemberOrDefault("addMessageToErrors", defaultAddMessageToErrors), - enableNewSmithyRuntime = node.get().getBooleanMemberOrDefault("enableNewSmithyRuntime", defaultEnableNewSmithyRuntime), + enableNewSmithyRuntime = SmithyRuntimeMode.fromString( + node.get().getStringMemberOrDefault("enableNewSmithyRuntime", "middleware"), + ), ) } else { ClientCodegenConfig( diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ApiKeyAuthDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ApiKeyAuthDecorator.kt index 58fd14e6a53b1a1adfe40fc6925fa8648d2cf160..14fe1fd1c7126f64617789dba9e21f323caf2371 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ApiKeyAuthDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ApiKeyAuthDecorator.kt @@ -38,7 +38,7 @@ class ApiKeyAuthDecorator : ClientCodegenDecorator { override val order: Byte = 10 private fun applies(codegenContext: ClientCodegenContext) = - !codegenContext.settings.codegenConfig.enableNewSmithyRuntime && + codegenContext.smithyRuntimeMode.generateMiddleware && isSupportedApiKeyAuth(codegenContext) override fun configCustomizations( diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/EndpointPrefixGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/EndpointPrefixGenerator.kt index 2fe90239de522da02e83d52aa981cec7b5d9631f..190aac3680f6c75da4a4a4824b37688db81542ec 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/EndpointPrefixGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/EndpointPrefixGenerator.kt @@ -32,7 +32,7 @@ class EndpointPrefixGenerator(private val codegenContext: ClientCodegenContext, endpointTraitBindings.render( this, "self", - codegenContext.settings.codegenConfig.enableNewSmithyRuntime, + codegenContext.smithyRuntimeMode, ) } rust("request.properties_mut().insert(endpoint_prefix);") diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpAuthDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpAuthDecorator.kt index 53aa5ee2aaa985e2a6608f2d24d525ce8b24b208..5b0eba15da9373c7f2930aa48f9a796a90da2769 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpAuthDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpAuthDecorator.kt @@ -68,12 +68,12 @@ private data class HttpAuthSchemes( companion object { fun from(codegenContext: ClientCodegenContext): HttpAuthSchemes { val authSchemes = ServiceIndex.of(codegenContext.model).getAuthSchemes(codegenContext.serviceShape).keys - val newRuntimeEnabled = codegenContext.settings.codegenConfig.enableNewSmithyRuntime + val generateOrchestrator = codegenContext.smithyRuntimeMode.generateOrchestrator return HttpAuthSchemes( - apiKey = newRuntimeEnabled && authSchemes.contains(HttpApiKeyAuthTrait.ID), - basic = newRuntimeEnabled && authSchemes.contains(HttpBasicAuthTrait.ID), - bearer = newRuntimeEnabled && authSchemes.contains(HttpBearerAuthTrait.ID), - digest = newRuntimeEnabled && authSchemes.contains(HttpDigestAuthTrait.ID), + apiKey = generateOrchestrator && authSchemes.contains(HttpApiKeyAuthTrait.ID), + basic = generateOrchestrator && authSchemes.contains(HttpBasicAuthTrait.ID), + bearer = generateOrchestrator && authSchemes.contains(HttpBearerAuthTrait.ID), + digest = generateOrchestrator && authSchemes.contains(HttpDigestAuthTrait.ID), ) } } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpConnectorConfigDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpConnectorConfigDecorator.kt index 102c50e718fadf91ef6996773256c8ed67155c79..d5ecd078b1086762d7d8be71218d5a2c4130daa3 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpConnectorConfigDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpConnectorConfigDecorator.kt @@ -25,7 +25,7 @@ class HttpConnectorConfigDecorator : ClientCodegenDecorator { codegenContext: ClientCodegenContext, baseCustomizations: List, ): List = - baseCustomizations.letIf(codegenContext.settings.codegenConfig.enableNewSmithyRuntime) { + baseCustomizations.letIf(codegenContext.smithyRuntimeMode.generateOrchestrator) { it + HttpConnectorConfigCustomization(codegenContext) } } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/EndpointParamsDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/EndpointParamsDecorator.kt index ba728bcdf8666e9c4bdf646d4a9a328a912934a3..f35becb55a0d22795f2520f13ff781cdd6026798 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/EndpointParamsDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/EndpointParamsDecorator.kt @@ -31,7 +31,7 @@ class EndpointParamsDecorator : ClientCodegenDecorator { operation: OperationShape, baseCustomizations: List, ): List = - baseCustomizations.letIf(codegenContext.settings.codegenConfig.enableNewSmithyRuntime) { + baseCustomizations.letIf(codegenContext.smithyRuntimeMode.generateOrchestrator) { it + listOf(EndpointParametersRuntimePluginCustomization(codegenContext, operation)) } } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/generators/EndpointParamsInterceptorGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/generators/EndpointParamsInterceptorGenerator.kt index b00a020508ba5bc9d00a0fc1091640faa91a7251..2dc2f2e1e881b605650481a057c35b40c1bd713c 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/generators/EndpointParamsInterceptorGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/generators/EndpointParamsInterceptorGenerator.kt @@ -118,7 +118,7 @@ class EndpointParamsInterceptorGenerator( endpointTraitBindings.render( this, "_input", - codegenContext.settings.codegenConfig.enableNewSmithyRuntime, + codegenContext.smithyRuntimeMode, ) } rust("cfg.put(endpoint_prefix);") diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingGenerator.kt index 4cc4b93347ce70c998eb87f529bfe7c3445b7340..f02cb5cde2bdc0dce8b77460fa13c7e4be1ecb53 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingGenerator.kt @@ -8,6 +8,7 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.traits.EndpointTrait +import software.amazon.smithy.rust.codegen.client.smithy.SmithyRuntimeMode import software.amazon.smithy.rust.codegen.client.smithy.generators.http.rustFormatString import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.rust @@ -44,7 +45,7 @@ class EndpointTraitBindings( * * The returned expression is a `Result` */ - fun render(writer: RustWriter, input: String, enableNewSmithyRuntime: Boolean) { + fun render(writer: RustWriter, input: String, smithyRuntimeMode: SmithyRuntimeMode) { // the Rust format pattern to make the endpoint prefix e.g. "{}.foo" val formatLiteral = endpointTrait.prefixFormatString() if (endpointTrait.hostPrefix.labels.isEmpty()) { @@ -67,7 +68,7 @@ class EndpointTraitBindings( // NOTE: this is dead code until we start respecting @required rust("let $field = &$input.$field;") } - val contents = if (enableNewSmithyRuntime) { + val contents = if (smithyRuntimeMode.generateOrchestrator) { // TODO(enableNewSmithyRuntime): Remove the allow attribute once all places need .into method """ if $field.is_empty() { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ServiceGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ServiceGenerator.kt index 764efb35df249dd6db15831bfd0a629d62abcc21..050e124376859e27ebf364ec66bb7c7b80976767 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ServiceGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ServiceGenerator.kt @@ -47,7 +47,7 @@ class ServiceGenerator( ) serviceConfigGenerator.render(this) - if (codegenContext.settings.codegenConfig.enableNewSmithyRuntime) { + if (codegenContext.smithyRuntimeMode.generateOrchestrator) { // Enable users to opt in to the test-utils in the runtime crate rustCrate.mergeFeature(TestUtilFeature.copy(deps = listOf("aws-smithy-runtime/test-util"))) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientDecorator.kt index e5e2760ceee1508ce456d6c01a270e81139651ee..7fb225fa48b8be9b6482d2d1d9ce14d9c573f20a 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientDecorator.kt @@ -36,7 +36,7 @@ class FluentClientDecorator : ClientCodegenDecorator { return } - val generics = if (codegenContext.settings.codegenConfig.enableNewSmithyRuntime) { + val generics = if (codegenContext.smithyRuntimeMode.generateOrchestrator) { NoClientGenerics(codegenContext.runtimeConfig) } else { FlexibleClientGenerics( diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt index 6c085fd673bed3cc3d9d809a1adb0f2e95d5632c..f10de15ee457c04a3defe6663a0538d1310c07c3 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt @@ -78,7 +78,7 @@ class FluentClientGenerator( private val model = codegenContext.model private val runtimeConfig = codegenContext.runtimeConfig private val core = FluentClientCore(model) - private val enableNewSmithyRuntime = codegenContext.settings.codegenConfig.enableNewSmithyRuntime + private val smithyRuntimeMode = codegenContext.smithyRuntimeMode fun render(crate: RustCrate) { renderFluentClient(crate) @@ -255,7 +255,7 @@ class FluentClientGenerator( "Inner" to symbolProvider.symbolForBuilder(input), "generics" to generics.decl, ) - if (enableNewSmithyRuntime) { + if (smithyRuntimeMode.generateOrchestrator) { rust("config_override: std::option::Option,") } } @@ -279,11 +279,26 @@ class FluentClientGenerator( "}", ) { rust("handle, inner: Default::default(),") - if (enableNewSmithyRuntime) { + if (smithyRuntimeMode.generateOrchestrator) { rust("config_override: None,") } } } + val middlewareScope = arrayOf( + "CustomizableOperation" to ClientRustModule.Client.customize.toType() + .resolve("CustomizableOperation"), + "ClassifyRetry" to RuntimeType.classifyRetry(runtimeConfig), + "OperationError" to errorType, + "OperationOutput" to outputType, + "SdkError" to RuntimeType.sdkError(runtimeConfig), + "SdkSuccess" to RuntimeType.sdkSuccess(runtimeConfig), + "send_bounds" to generics.sendBounds(operationSymbol, outputType, errorType, retryClassifier), + "customizable_op_type_params" to rustTypeParameters( + symbolProvider.toSymbol(operation), + retryClassifier, + generics.toRustGenerics(), + ), + ) rustTemplate( """ /// Consume this builder, creating a customizable operation that can be modified before being @@ -300,15 +315,9 @@ class FluentClientGenerator( Ok(#{CustomizableOperation} { handle, operation }) } - /// Sends the request and returns the response. - /// - /// If an error occurs, an `SdkError` will be returned with additional details that - /// can be matched against. - /// - /// By default, any retryable failures will be retried twice. Retry behavior - /// is configurable with the [RetryConfig](aws_smithy_types::retry::RetryConfig), which can be - /// set when configuring the client. - pub async fn send(self) -> std::result::Result<#{OperationOutput}, #{SdkError}<#{OperationError}>> + // This function will go away in the near future. Do not rely on it. + ##[doc(hidden)] + pub async fn send_middleware(self) -> std::result::Result<#{OperationOutput}, #{SdkError}<#{OperationError}>> #{send_bounds:W} { let op = self.inner.build().map_err(#{SdkError}::construction_failure)? .make_operation(&self.handle.conf) @@ -317,24 +326,11 @@ class FluentClientGenerator( self.handle.client.call(op).await } """, - "CustomizableOperation" to ClientRustModule.Client.customize.toType() - .resolve("CustomizableOperation"), - "ClassifyRetry" to RuntimeType.classifyRetry(runtimeConfig), - "OperationError" to errorType, - "OperationOutput" to outputType, - "SdkError" to RuntimeType.sdkError(runtimeConfig), - "SdkSuccess" to RuntimeType.sdkSuccess(runtimeConfig), - "send_bounds" to generics.sendBounds(operationSymbol, outputType, errorType, retryClassifier), - "customizable_op_type_params" to rustTypeParameters( - symbolProvider.toSymbol(operation), - retryClassifier, - generics.toRustGenerics(), - ), + *middlewareScope, ) - if (enableNewSmithyRuntime) { + if (smithyRuntimeMode.defaultToMiddleware) { rustTemplate( """ - // TODO(enableNewSmithyRuntime): Replace `send` with `send_v2` /// Sends the request and returns the response. /// /// If an error occurs, an `SdkError` will be returned with additional details that @@ -343,13 +339,40 @@ class FluentClientGenerator( /// By default, any retryable failures will be retried twice. Retry behavior /// is configurable with the [RetryConfig](aws_smithy_types::retry::RetryConfig), which can be /// set when configuring the client. - pub async fn send_v2(self) -> std::result::Result<#{OperationOutput}, #{SdkError}<#{OperationError}, #{HttpResponse}>> { - self.send_v2_with_plugin(Option::>::None).await + pub async fn send(self) -> std::result::Result<#{OperationOutput}, #{SdkError}<#{OperationError}>> + #{send_bounds:W} { + self.send_middleware().await } + """, + *middlewareScope, + ) + } + if (smithyRuntimeMode.generateOrchestrator) { + val orchestratorScope = arrayOf( + "HttpResponse" to RuntimeType.smithyRuntimeApi(runtimeConfig) + .resolve("client::orchestrator::HttpResponse"), + "OperationError" to errorType, + "Operation" to symbolProvider.toSymbol(operation), + "OperationOutput" to outputType, + "RuntimePlugin" to RuntimeType.runtimePlugin(runtimeConfig), + "RuntimePlugins" to RuntimeType.smithyRuntimeApi(runtimeConfig) + .resolve("client::runtime_plugin::RuntimePlugins"), + "SdkError" to RuntimeType.sdkError(runtimeConfig), + "TypedBox" to RuntimeType.smithyRuntimeApi(runtimeConfig).resolve("type_erasure::TypedBox"), + "invoke" to RuntimeType.smithyRuntime(runtimeConfig).resolve("client::orchestrator::invoke"), + ) + rustTemplate( + """ + ##[doc(hidden)] + pub async fn send_orchestrator(self) -> std::result::Result<#{OperationOutput}, #{SdkError}<#{OperationError}, #{HttpResponse}>> { + self.send_orchestrator_with_plugin(Option::>::None).await + } + + ##[doc(hidden)] // TODO(enableNewSmithyRuntime): Delete when unused - /// Equivalent to [`Self::send_v2`] but adds a final runtime plugin to shim missing behavior - pub async fn send_v2_with_plugin(self, final_plugin: Option) -> std::result::Result<#{OperationOutput}, #{SdkError}<#{OperationError}, #{HttpResponse}>> { + /// Equivalent to [`Self::send_orchestrator`] but adds a final runtime plugin to shim missing behavior + pub async fn send_orchestrator_with_plugin(self, final_plugin: Option) -> std::result::Result<#{OperationOutput}, #{SdkError}<#{OperationError}, #{HttpResponse}>> { let mut runtime_plugins = #{RuntimePlugins}::new() .with_client_plugin(crate::config::ServiceRuntimePlugin::new(self.handle.clone())); if let Some(config_override) = self.config_override { @@ -373,18 +396,26 @@ class FluentClientGenerator( Ok(#{TypedBox}::<#{OperationOutput}>::assume_from(output).expect("correct output type").unwrap()) } """, - "HttpResponse" to RuntimeType.smithyRuntimeApi(runtimeConfig) - .resolve("client::orchestrator::HttpResponse"), - "OperationError" to errorType, - "Operation" to symbolProvider.toSymbol(operation), - "OperationOutput" to outputType, - "RuntimePlugin" to RuntimeType.runtimePlugin(runtimeConfig), - "RuntimePlugins" to RuntimeType.smithyRuntimeApi(runtimeConfig) - .resolve("client::runtime_plugin::RuntimePlugins"), - "SdkError" to RuntimeType.sdkError(runtimeConfig), - "TypedBox" to RuntimeType.smithyRuntimeApi(runtimeConfig).resolve("type_erasure::TypedBox"), - "invoke" to RuntimeType.smithyRuntime(runtimeConfig).resolve("client::orchestrator::invoke"), + *orchestratorScope, ) + if (smithyRuntimeMode.defaultToOrchestrator) { + rustTemplate( + """ + /// Sends the request and returns the response. + /// + /// If an error occurs, an `SdkError` will be returned with additional details that + /// can be matched against. + /// + /// By default, any retryable failures will be retried twice. Retry behavior + /// is configurable with the [RetryConfig](aws_smithy_types::retry::RetryConfig), which can be + /// set when configuring the client. + pub async fn send(self) -> std::result::Result<#{OperationOutput}, #{SdkError}<#{OperationError}, #{HttpResponse}>> { + self.send_orchestrator().await + } + """, + *orchestratorScope, + ) + } rustTemplate( """ @@ -426,20 +457,24 @@ class FluentClientGenerator( """, ) } - PaginatorGenerator.paginatorType(codegenContext, generics, operation, retryClassifier) - ?.also { paginatorType -> - rustTemplate( - """ - /// Create a paginator for this request - /// - /// Paginators are used by calling [`send().await`](#{Paginator}::send) which returns a `Stream`. - pub fn into_paginator(self) -> #{Paginator}${generics.inst} { - #{Paginator}::new(self.handle, self.inner) - } - """, - "Paginator" to paginatorType, - ) - } + + // TODO(enableNewSmithyRuntime): Port paginators to the orchestrator + if (smithyRuntimeMode.generateMiddleware) { + PaginatorGenerator.paginatorType(codegenContext, generics, operation, retryClassifier) + ?.also { paginatorType -> + rustTemplate( + """ + /// Create a paginator for this request + /// + /// Paginators are used by calling [`send().await`](#{Paginator}::send) which returns a `Stream`. + pub fn into_paginator(self) -> #{Paginator}${generics.inst} { + #{Paginator}::new(self.handle, self.inner) + } + """, + "Paginator" to paginatorType, + ) + } + } writeCustomizations( customizations, FluentClientSection.FluentBuilderImpl( diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ClientProtocolGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ClientProtocolGenerator.kt index 3c8fc7c97491815ba98611e9421dcd28696b8cda..85dcb206db06c42f7e17016c2b8c09f6c55954fd 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ClientProtocolGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ClientProtocolGenerator.kt @@ -97,7 +97,7 @@ open class ClientProtocolGenerator( } traitGenerator.generateTraitImpls(operationWriter, operationShape, operationCustomizations) - if (codegenContext.settings.codegenConfig.enableNewSmithyRuntime) { + if (codegenContext.smithyRuntimeMode.generateOrchestrator) { OperationRuntimePluginGenerator(codegenContext).render( operationWriter, operationShape, diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpAuthDecoratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpAuthDecoratorTest.kt index 29c3b2e8535fac97b5a6db00fa8bf58b9b4c3d4c..bcb5ec2f4ee0597aa3be99adf44beae38b2bd837 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpAuthDecoratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpAuthDecoratorTest.kt @@ -6,8 +6,8 @@ package software.amazon.smithy.rust.codegen.client.smithy.customizations import org.junit.jupiter.api.Test -import software.amazon.smithy.model.node.BooleanNode import software.amazon.smithy.model.node.ObjectNode +import software.amazon.smithy.model.node.StringNode import software.amazon.smithy.rust.codegen.client.testutil.clientIntegrationTest import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency @@ -22,7 +22,7 @@ private fun additionalSettings(): ObjectNode = ObjectNode.objectNodeBuilder() .withMember( "codegen", ObjectNode.objectNodeBuilder() - .withMember("enableNewSmithyRuntime", BooleanNode.from(true)).build(), + .withMember("enableNewSmithyRuntime", StringNode.from("orchestrator")).build(), ) .build() @@ -67,7 +67,7 @@ class HttpAuthDecoratorTest { .build_dyn(); let client = $moduleName::Client::with_config(smithy_client, config); let _ = client.some_operation() - .send_v2() + .send_orchestrator() .await .expect("success"); connector.assert_requests_match(&[]); @@ -101,7 +101,7 @@ class HttpAuthDecoratorTest { .build_dyn(); let client = $moduleName::Client::with_config(smithy_client, config); let _ = client.some_operation() - .send_v2() + .send_orchestrator() .await .expect("success"); connector.assert_requests_match(&[]); @@ -146,7 +146,7 @@ class HttpAuthDecoratorTest { .build_dyn(); let client = $moduleName::Client::with_config(smithy_client, config); let _ = client.some_operation() - .send_v2() + .send_orchestrator() .await .expect("success"); connector.assert_requests_match(&[]); @@ -192,7 +192,7 @@ class HttpAuthDecoratorTest { .build_dyn(); let client = $moduleName::Client::with_config(smithy_client, config); let _ = client.some_operation() - .send_v2() + .send_orchestrator() .await .expect("success"); connector.assert_requests_match(&[]); @@ -238,7 +238,7 @@ class HttpAuthDecoratorTest { .build_dyn(); let client = $moduleName::Client::with_config(smithy_client, config); let _ = client.some_operation() - .send_v2() + .send_orchestrator() .await .expect("success"); connector.assert_requests_match(&[]); @@ -284,7 +284,7 @@ class HttpAuthDecoratorTest { .build_dyn(); let client = $moduleName::Client::with_config(smithy_client, config); let _ = client.some_operation() - .send_v2() + .send_orchestrator() .await .expect("success"); connector.assert_requests_match(&[]); diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt index 6fe1328bb856e1346c660fccc6db9bb95c17b50c..34225e8dfd6b9dea4e54e9a0f07e79a12a298a35 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt @@ -11,6 +11,7 @@ import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ValueSource import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.traits.EndpointTrait +import software.amazon.smithy.rust.codegen.client.smithy.SmithyRuntimeMode import software.amazon.smithy.rust.codegen.client.testutil.clientIntegrationTest import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.core.rustlang.Attribute @@ -37,8 +38,9 @@ internal class EndpointTraitBindingsTest { } @ParameterizedTest - @ValueSource(booleans = [true, false]) - fun `generate endpoint prefixes`(enableNewSmithyRuntime: Boolean) { + @ValueSource(strings = ["middleware", "orchestrator"]) + fun `generate endpoint prefixes`(smithyRuntimeModeStr: String) { + val smithyRuntimeMode = SmithyRuntimeMode.fromString(smithyRuntimeModeStr) val model = """ namespace test @readonly @@ -76,7 +78,7 @@ internal class EndpointTraitBindingsTest { RuntimeType.smithyHttp(TestRuntimeConfig), TestRuntimeConfig.operationBuildError(), ) { - endpointBindingGenerator.render(this, "self", enableNewSmithyRuntime) + endpointBindingGenerator.render(this, "self", smithyRuntimeMode) } } unitTest(