Unverified Commit 89802592 authored by John DiSanti's avatar John DiSanti Committed by GitHub
Browse files

Remove middleware - part 1 (#2920)

This PR removes the runtime mode flag, test compile flags, and CI checks
for client middleware.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent 88d38510
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -84,9 +84,6 @@ jobs:
        test:
        - action: check-aws-sdk-adhoc-tests
          runner: ubuntu-latest
        # TODO(enableNewSmithyRuntimeCleanup): Remove `check-aws-sdk-middleware-impl` when cleaning up middleware
        - action: check-aws-sdk-middleware-impl
          runner: smithy_ubuntu-latest_8-core
        - action: check-client-codegen-integration-tests
          runner: smithy_ubuntu-latest_8-core
        - action: check-client-codegen-unit-tests
+1 −1
Original line number Diff line number Diff line
@@ -792,7 +792,7 @@ mod loader {
            assert_eq!(Some(&app_name), conf.app_name());
        }

        #[cfg(all(not(aws_sdk_middleware_mode), feature = "rustls"))]
        #[cfg(feature = "rustls")]
        #[tokio::test]
        async fn disable_default_credentials() {
            let config = from_env().no_credentials().load().await;
+2 −6
Original line number Diff line number Diff line
@@ -37,8 +37,6 @@ dependencies {
    implementation("software.amazon.smithy:smithy-aws-traits:$smithyVersion")
}

fun getSmithyRuntimeMode(): String = properties.get("smithy.runtime.mode") ?: "orchestrator"

val allCodegenTests = listOf(
    CodegenTest(
        "com.amazonaws.apigateway#BackplaneControlService",
@@ -47,8 +45,7 @@ val allCodegenTests = listOf(
        extraConfig = """
            ,
            "codegen": {
                "includeFluentClient": false,
                "enableNewSmithyRuntime": "${getSmithyRuntimeMode()}"
                "includeFluentClient": false
            },
            "customizationConfig": {
                "awsSdk": {
@@ -64,8 +61,7 @@ val allCodegenTests = listOf(
        extraConfig = """
            ,
            "codegen": {
                "includeFluentClient": false,
                "enableNewSmithyRuntime": "${getSmithyRuntimeMode()}"
                "includeFluentClient": false
            },
            "customizationConfig": {
                "awsSdk": {
+0 −1
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ val DECORATORS: List<ClientCodegenDecorator> = listOf(
        ServiceConfigDecorator(),
        AwsPresigningDecorator(),
        AwsCrateDocsDecorator(),
        HttpConnectorDecorator(),
        AwsEndpointsStdLib(),
        *PromotedBuiltInsDecorators,
        GenericSmithySdkConfigSettings(),
+3 −81
Original line number Diff line number Diff line
@@ -13,7 +13,6 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.client.Fluen
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientGenerator
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientSection
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.NoClientGenerics
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.renderCustomizableOperationSend
import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.DefaultProtocolTestGenerator
import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolTestGenerator
import software.amazon.smithy.rust.codegen.core.rustlang.Attribute
@@ -30,7 +29,6 @@ import software.amazon.smithy.rust.codegen.core.smithy.RustCrate
import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization
import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection
import software.amazon.smithy.rust.codegen.core.util.serviceNameOrDefault
import software.amazon.smithy.rustsdk.AwsRuntimeType.defaultMiddleware

private class Types(runtimeConfig: RuntimeConfig) {
    private val smithyClient = RuntimeType.smithyClient(runtimeConfig)
@@ -69,9 +67,6 @@ class AwsFluentClientDecorator : ClientCodegenDecorator {
            ),
            retryClassifier = AwsRuntimeType.awsHttp(runtimeConfig).resolve("retry::AwsResponseRetryClassifier"),
        ).render(rustCrate, listOf(CustomizableOperationTestHelpers(runtimeConfig)))
        rustCrate.withModule(ClientRustModule.Client.customize) {
            renderCustomizableOperationSend(codegenContext, generics, this)
        }
        rustCrate.withModule(ClientRustModule.client) {
            AwsFluentClientExtensions(codegenContext, types).render(this)
        }
@@ -103,21 +98,11 @@ class AwsFluentClientDecorator : ClientCodegenDecorator {
        baseGenerator.protocolSupport,
        baseGenerator.operationShape,
        renderClientCreation = { params ->
            rust("let mut ${params.configBuilderName} = ${params.configBuilderName};")
            if (codegenContext.smithyRuntimeMode.generateOrchestrator) {
                rust("""${params.configBuilderName}.set_region(Some(crate::config::Region::new("us-east-1")));""")
            } else {
                rust(
                    """
                    // If the test case was missing endpoint parameters, default a region so it doesn't fail
                    if ${params.configBuilderName}.region.is_none() {
                        ${params.configBuilderName}.set_region(Some(crate::config::Region::new("us-east-1")));
                    }
                    """,
                )
            }
            rustTemplate(
                """
                let mut ${params.configBuilderName} = ${params.configBuilderName};
                ${params.configBuilderName}.set_region(Some(crate::config::Region::new("us-east-1")));

                let config = ${params.configBuilderName}.http_connector(${params.connectorName}).build();
                let ${params.clientName} = #{Client}::from_conf(config);
                """,
@@ -160,69 +145,6 @@ private class AwsFluentClientExtensions(private val codegenContext: ClientCodege
                """,
                *codegenScope,
            )
            if (codegenContext.smithyRuntimeMode.generateMiddleware) {
                rustTemplate(
                    """
                    /// Creates a new client from the service [`Config`](crate::Config).
                    ///
                    /// ## Panics
                    ///
                    /// - This method will panic if the `conf` is missing an async sleep implementation. If you experience this panic, set
                    ///     the `sleep_impl` on the Config passed into this function to fix it.
                    /// - This method will panic if the `conf` is missing an HTTP connector. If you experience this panic, set the
                    ///     `http_connector` on the Config passed into this function to fix it.
                    pub fn from_conf(conf: crate::Config) -> Self {
                        let retry_config = conf.retry_config().cloned().unwrap_or_else(#{RetryConfig}::disabled);
                        let timeout_config = conf.timeout_config().cloned().unwrap_or_else(#{TimeoutConfig}::disabled);
                        let sleep_impl = conf.sleep_impl();
                        if (retry_config.has_retry() || timeout_config.has_timeouts()) && sleep_impl.is_none() {
                            panic!("An async sleep implementation is required for retries or timeouts to work. \
                                    Set the `sleep_impl` on the Config passed into this function to fix this panic.");
                        }

                        let connector = conf.http_connector().and_then(|c| {
                            let timeout_config = conf
                                .timeout_config()
                                .cloned()
                                .unwrap_or_else(#{TimeoutConfig}::disabled);
                            let connector_settings = #{ConnectorSettings}::from_timeout_config(
                                &timeout_config,
                            );
                            c.connector(&connector_settings, conf.sleep_impl())
                        });

                        let builder = #{SmithyClientBuilder}::new();

                        let builder = match connector {
                            // Use provided connector
                            Some(c) => builder.connector(c),
                            None =>{
                                ##[cfg(feature = "rustls")]
                                {
                                    // Use default connector based on enabled features
                                    builder.dyn_https_connector(#{ConnectorSettings}::from_timeout_config(&timeout_config))
                                }
                                ##[cfg(not(feature = "rustls"))]
                                {
                                    panic!("No HTTP connector was available. Enable the `rustls` crate feature or set a connector to fix this.");
                                }
                            }
                        };
                        let mut builder = builder
                            .middleware(#{DynMiddleware}::new(#{Middleware}::new()))
                            .reconnect_mode(retry_config.reconnect_mode())
                            .retry_config(retry_config.into())
                            .operation_timeout_config(timeout_config.into());
                        builder.set_sleep_impl(sleep_impl);
                        let client = builder.build();

                        Self { handle: #{Arc}::new(Handle { client, conf }) }
                    }
                    """,
                    *codegenScope,
                    "Middleware" to codegenContext.runtimeConfig.defaultMiddleware(),
                )
            }
        }
    }
}
Loading