Unverified Commit bfb43567 authored by AWS SDK Rust Bot's avatar AWS SDK Rust Bot Committed by GitHub
Browse files

Cherry-pick commits back into release branch for 0.57.2 (#3187)

parents 6cb0b461 7cc3a6ea
Loading
Loading
Loading
Loading
+55 −0
Original line number Diff line number Diff line
@@ -16,3 +16,58 @@ message = "Fix aws-sdk-rust#930 (PutSnapshotBlock)"
references = ["smithy-rs#3126", "aws-sdk-rust#930"]
meta = { "breaking" = false, "tada" = false, "bug" = true }
author = "rcoh"

[[aws-sdk-rust]]
message = "Fix exclusively setting the credentials provider at operation config-override time. It's now possible to set the credentials when an operation is sent (via `.config_override()`), rather than at client-creation time."
references = ["smithy-rs#3156", "aws-sdk-rust#901"]
meta = { "breaking" = false, "tada" = false, "bug" = true }
author = "ysaito1001"

[[smithy-rs]]
message = """Enable conversion from `BuildError` into `SdkError` & `<service>::Error`. This allows customers to write the following code:
```rust
async fn do_a_thing(client: &Client) -> Result<SdkError<SomeOperationError>> {
    client.run_operation().complex_field(ComplexField::builder()
        .a("a")
        .b("b")
        .build()?
    ).send().await?;
}
```

Previously, `?` could not be used in this position.
"""
references = ["smithy-rs#3173", "smithy-rs#3171"]
meta = { "breaking" = false, "tada" = true, "bug" = false }
author = "rcoh"

[[aws-sdk-rust]]
message = """Enable conversion from `BuildError` into `SdkError` & `<service>::Error`. This allows customers to write the following code:
```rust
async fn create_table(dynamo_client: &Client) -> Result<(), SdkError<CreateTableError>> {
    dynamo_client
        .create_table()
        .table_name("test")
        .key_schema(
            KeySchemaElement::builder()
                .attribute_name("year")
                .key_type(KeyType::Hash)
                .build()?, // Previously, `?` could not be used here
        )
        .send()
        .await?;
    Ok(())
}
```

Previously, `?` could not be used in this position.
"""
references = ["smithy-rs#3173", "smithy-rs#3171"]
meta = { "breaking" = false, "tada" = true, "bug" = false }
author = "rcoh"

[[aws-sdk-rust]]
message = "ProvideCredentials and SharedCredentialsProvider are now re-exported."
references = ["smithy-rs#3173", "smithy-rs#3155"]
meta = { "breaking" = false, "tada" = false, "bug" = false }
author = "rcoh"
+3 −2
Original line number Diff line number Diff line
@@ -119,11 +119,12 @@ internal class AwsCrateDocGenerator(private val codegenContext: ClientCodegenCon
        if (includeHeader) {
            template(asComments, escape("# $moduleName\n"))
        }
        // NOTE: when you change this, you must also change SDK_README.md.hb
        template(
            asComments,
            """
            **Please Note: The SDK is currently in Developer Preview and is intended strictly for
            feedback purposes only. Do not use this SDK for production workloads.**${"\n"}
            **Please Note: The SDK is currently released as a developer preview, without support or assistance for use
            on production workloads. Any use in production is at your own risk.**${"\n"}
            """.trimIndent(),
        )

+0 −3
Original line number Diff line number Diff line
@@ -30,11 +30,9 @@ import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection
import software.amazon.smithy.rust.codegen.core.util.serviceNameOrDefault

private class Types(runtimeConfig: RuntimeConfig) {
    private val smithyHttp = RuntimeType.smithyHttp(runtimeConfig)
    private val smithyTypes = RuntimeType.smithyTypes(runtimeConfig)

    val awsTypes = AwsRuntimeType.awsTypes(runtimeConfig)
    val connectorError = smithyHttp.resolve("result::ConnectorError")
    val retryConfig = smithyTypes.resolve("retry::RetryConfig")
    val timeoutConfig = smithyTypes.resolve("timeout::TimeoutConfig")
}
@@ -102,7 +100,6 @@ class AwsFluentClientDecorator : ClientCodegenDecorator {
private class AwsFluentClientExtensions(private val codegenContext: ClientCodegenContext, private val types: Types) {
    private val codegenScope = arrayOf(
        "Arc" to RuntimeType.Arc,
        "ConnectorError" to types.connectorError,
        "RetryConfig" to types.retryConfig,
        "TimeoutConfig" to types.timeoutConfig,
        "aws_types" to types.awsTypes,
+39 −58
Original line number Diff line number Diff line
@@ -7,20 +7,17 @@ package software.amazon.smithy.rustsdk

import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.ClientRustModule
import software.amazon.smithy.rust.codegen.client.smithy.configReexport
import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator
import software.amazon.smithy.rust.codegen.client.smithy.customize.TestUtilFeature
import software.amazon.smithy.rust.codegen.client.smithy.endpoint.supportedAuthSchemes
import software.amazon.smithy.rust.codegen.client.smithy.generators.ServiceRuntimePluginCustomization
import software.amazon.smithy.rust.codegen.client.smithy.generators.ServiceRuntimePluginSection
import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization
import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
import software.amazon.smithy.rust.codegen.core.rustlang.featureGateBlock
import software.amazon.smithy.rust.codegen.core.rustlang.rust
import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.core.rustlang.writable
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.preludeScope
import software.amazon.smithy.rust.codegen.core.smithy.RustCrate
import software.amazon.smithy.rust.codegen.core.smithy.customize.AdHocCustomization
@@ -30,12 +27,6 @@ class CredentialsProviderDecorator : ClientCodegenDecorator {
    override val name: String = "CredentialsProvider"
    override val order: Byte = 0

    override fun serviceRuntimePluginCustomizations(
        codegenContext: ClientCodegenContext,
        baseCustomizations: List<ServiceRuntimePluginCustomization>,
    ): List<ServiceRuntimePluginCustomization> =
        baseCustomizations + listOf(CredentialsIdentityResolverRegistration(codegenContext))

    override fun configCustomizations(
        codegenContext: ClientCodegenContext,
        baseCustomizations: List<ConfigCustomization>,
@@ -65,15 +56,23 @@ class CredentialsProviderDecorator : ClientCodegenDecorator {
/**
 * Add a `.credentials_provider` field and builder to the `Config` for a given service
 */
class CredentialProviderConfig(codegenContext: ClientCodegenContext) : ConfigCustomization() {
class CredentialProviderConfig(private val codegenContext: ClientCodegenContext) : ConfigCustomization() {
    private val runtimeConfig = codegenContext.runtimeConfig
    private val codegenScope = arrayOf(
        *preludeScope,
        "Credentials" to AwsRuntimeType.awsCredentialTypes(runtimeConfig).resolve("Credentials"),
        "ProvideCredentials" to AwsRuntimeType.awsCredentialTypes(runtimeConfig)
        "Credentials" to configReexport(AwsRuntimeType.awsCredentialTypes(runtimeConfig).resolve("Credentials")),
        "ProvideCredentials" to configReexport(
            AwsRuntimeType.awsCredentialTypes(runtimeConfig)
                .resolve("provider::ProvideCredentials"),
        "SharedCredentialsProvider" to AwsRuntimeType.awsCredentialTypes(runtimeConfig)
        ),
        "SharedCredentialsProvider" to configReexport(
            AwsRuntimeType.awsCredentialTypes(runtimeConfig)
                .resolve("provider::SharedCredentialsProvider"),
        ),
        "SIGV4A_SCHEME_ID" to AwsRuntimeType.awsRuntime(runtimeConfig)
            .resolve("auth::sigv4a::SCHEME_ID"),
        "SIGV4_SCHEME_ID" to AwsRuntimeType.awsRuntime(runtimeConfig)
            .resolve("auth::sigv4::SCHEME_ID"),
        "TestCredentials" to AwsRuntimeType.awsCredentialTypesTestUtil(runtimeConfig).resolve("Credentials"),
    )

@@ -103,60 +102,42 @@ class CredentialProviderConfig(codegenContext: ClientCodegenContext) : ConfigCus
                    *codegenScope,
                )

                rustTemplate(
                rustBlockTemplate(
                    """
                    /// Sets the credentials provider for this service
                    pub fn set_credentials_provider(&mut self, credentials_provider: #{Option}<#{SharedCredentialsProvider}>) -> &mut Self {
                        self.config.store_or_unset(credentials_provider);
                        self
                    }
                    pub fn set_credentials_provider(&mut self, credentials_provider: #{Option}<#{SharedCredentialsProvider}>) -> &mut Self
                    """,
                    *codegenScope,
                ) {
                    rustBlockTemplate(
                        """
                        if let Some(credentials_provider) = credentials_provider
                        """,
                        *codegenScope,
                    ) {
                        if (codegenContext.serviceShape.supportedAuthSchemes().contains("sigv4a")) {
                            featureGateBlock("sigv4a") {
                                rustTemplate(
                                    "self.runtime_components.push_identity_resolver(#{SIGV4A_SCHEME_ID}, credentials_provider.clone());",
                                    *codegenScope,
                                )
                            }

            is ServiceConfig.DefaultForTests -> rustTemplate(
                "${section.configBuilderRef}.set_credentials_provider(Some(#{SharedCredentialsProvider}::new(#{TestCredentials}::for_tests())));",
                        }
                        rustTemplate(
                            "self.runtime_components.push_identity_resolver(#{SIGV4_SCHEME_ID}, credentials_provider);",
                            *codegenScope,
                        )

            else -> emptySection
                    }
                    rust("self")
                }
            }

class CredentialsIdentityResolverRegistration(
    private val codegenContext: ClientCodegenContext,
) : ServiceRuntimePluginCustomization() {
    private val runtimeConfig = codegenContext.runtimeConfig

    override fun section(section: ServiceRuntimePluginSection): Writable = writable {
        when (section) {
            is ServiceRuntimePluginSection.RegisterRuntimeComponents -> {
                rustBlockTemplate("if let Some(creds_provider) = ${section.serviceConfigName}.credentials_provider()") {
                    val codegenScope = arrayOf(
                        "SharedIdentityResolver" to RuntimeType.smithyRuntimeApi(runtimeConfig)
                            .resolve("client::identity::SharedIdentityResolver"),
                        "SIGV4A_SCHEME_ID" to AwsRuntimeType.awsRuntime(runtimeConfig)
                            .resolve("auth::sigv4a::SCHEME_ID"),
                        "SIGV4_SCHEME_ID" to AwsRuntimeType.awsRuntime(runtimeConfig)
                            .resolve("auth::sigv4::SCHEME_ID"),
            is ServiceConfig.DefaultForTests -> rustTemplate(
                "${section.configBuilderRef}.set_credentials_provider(Some(#{SharedCredentialsProvider}::new(#{TestCredentials}::for_tests())));",
                *codegenScope,
            )

                    if (codegenContext.serviceShape.supportedAuthSchemes().contains("sigv4a")) {
                        featureGateBlock("sigv4a") {
                            section.registerIdentityResolver(this) {
                                rustTemplate("#{SIGV4A_SCHEME_ID}, creds_provider.clone()", *codegenScope)
                            }
                        }
                    }
                    section.registerIdentityResolver(this) {
                        rustTemplate("#{SIGV4_SCHEME_ID}, creds_provider,", *codegenScope)
                    }
                }
            }

            else -> {}
            else -> emptySection
        }
    }
}
+2 −11
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ import software.amazon.smithy.model.node.Node
import software.amazon.smithy.rulesengine.aws.language.functions.AwsBuiltIns
import software.amazon.smithy.rulesengine.language.syntax.parameters.Parameter
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.ClientRustModule
import software.amazon.smithy.rust.codegen.client.smithy.configReexport
import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator
import software.amazon.smithy.rust.codegen.client.smithy.endpoint.EndpointCustomization
import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization
@@ -22,7 +22,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.core.rustlang.writable
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.preludeScope
import software.amazon.smithy.rust.codegen.core.smithy.RustCrate
import software.amazon.smithy.rust.codegen.core.smithy.customize.AdHocCustomization
import software.amazon.smithy.rust.codegen.core.smithy.customize.adhocCustomization
import software.amazon.smithy.rust.codegen.core.util.dq
@@ -109,14 +108,6 @@ class RegionDecorator : ClientCodegenDecorator {
        }
    }

    override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) {
        if (usesRegion(codegenContext)) {
            rustCrate.withModule(ClientRustModule.config) {
                rust("pub use #T::Region;", region(codegenContext.runtimeConfig))
            }
        }
    }

    override fun endpointCustomizations(codegenContext: ClientCodegenContext): List<EndpointCustomization> {
        if (!usesRegion(codegenContext)) {
            return listOf()
@@ -157,7 +148,7 @@ class RegionProviderConfig(codegenContext: ClientCodegenContext) : ConfigCustomi
    private val moduleUseName = codegenContext.moduleUseName()
    private val codegenScope = arrayOf(
        *preludeScope,
        "Region" to region.resolve("Region"),
        "Region" to configReexport(region.resolve("Region")),
    )

    override fun section(section: ServiceConfig) = writable {
Loading