Skip to content

Commit

Permalink
Cherry-pick commits back into release branch for 0.57.2 (#3187)
Browse files Browse the repository at this point in the history
  • Loading branch information
aws-sdk-rust-ci authored Nov 13, 2023
2 parents 6cb0b46 + 7cc3a6e commit bfb4356
Show file tree
Hide file tree
Showing 32 changed files with 366 additions and 149 deletions.
55 changes: 55 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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>,
Expand Down Expand Up @@ -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)
.resolve("provider::ProvideCredentials"),
"SharedCredentialsProvider" to AwsRuntimeType.awsCredentialTypes(runtimeConfig)
.resolve("provider::SharedCredentialsProvider"),
"Credentials" to configReexport(AwsRuntimeType.awsCredentialTypes(runtimeConfig).resolve("Credentials")),
"ProvideCredentials" to configReexport(
AwsRuntimeType.awsCredentialTypes(runtimeConfig)
.resolve("provider::ProvideCredentials"),
),
"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"),
)

Expand Down Expand Up @@ -103,16 +102,34 @@ 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,
)
}
}
rustTemplate(
"self.runtime_components.push_identity_resolver(#{SIGV4_SCHEME_ID}, credentials_provider);",
*codegenScope,
)
}
rust("self")
}
}

is ServiceConfig.DefaultForTests -> rustTemplate(
Expand All @@ -124,39 +141,3 @@ class CredentialProviderConfig(codegenContext: ClientCodegenContext) : ConfigCus
}
}
}

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"),
)

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 -> {}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,65 @@ package software.amazon.smithy.rustsdk

import org.junit.jupiter.api.Test
import software.amazon.smithy.rust.codegen.client.testutil.validateConfigCustomizations
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType
import software.amazon.smithy.rust.codegen.core.testutil.integrationTest
import software.amazon.smithy.rust.codegen.core.testutil.tokioTest

internal class CredentialProviderConfigTest {
@Test
fun `generates a valid config`() {
val codegenContext = awsTestCodegenContext()
validateConfigCustomizations(codegenContext, CredentialProviderConfig(codegenContext))
}

@Test
fun `configuring credentials provider at operation level should work`() {
awsSdkIntegrationTest(SdkCodegenIntegrationTest.model) { ctx, rustCrate ->
val rc = ctx.runtimeConfig
val codegenScope = arrayOf(
*RuntimeType.preludeScope,
"capture_request" to RuntimeType.captureRequest(rc),
"Credentials" to AwsRuntimeType.awsCredentialTypesTestUtil(rc)
.resolve("Credentials"),
"Region" to AwsRuntimeType.awsTypes(rc).resolve("region::Region"),
)
rustCrate.integrationTest("credentials_provider") {
// per https://github.com/awslabs/aws-sdk-rust/issues/901
tokioTest("configuring_credentials_provider_at_operation_level_should_work") {
val moduleName = ctx.moduleUseName()
rustTemplate(
"""
let (http_client, _rx) = #{capture_request}(None);
let client_config = $moduleName::Config::builder()
.http_client(http_client)
.build();
let client = $moduleName::Client::from_conf(client_config);
let credentials = #{Credentials}::new(
"test",
"test",
#{None},
#{None},
"test",
);
let operation_config_override = $moduleName::Config::builder()
.credentials_provider(credentials.clone())
.region(#{Region}::new("us-west-2"));
let _ = client
.some_operation()
.customize()
.config_override(operation_config_override)
.send()
.await
.expect("success");
""",
*codegenScope,
)
}
}
}
}
}
41 changes: 41 additions & 0 deletions aws/sdk/integration-tests/dynamodb/tests/build-errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

use aws_sdk_dynamodb::error::SdkError;
use aws_sdk_dynamodb::operation::create_table::CreateTableError;
use aws_sdk_dynamodb::types::{KeySchemaElement, KeyType};
use aws_sdk_dynamodb::Client;

#[allow(dead_code)]
async fn create_table_test(client: &Client) -> Result<(), SdkError<CreateTableError>> {
let _just_checking_compilation = client
.create_table()
.table_name("test")
.key_schema(
KeySchemaElement::builder()
.attribute_name("year")
.key_type(KeyType::Hash)
.build()?,
)
.send()
.await;
Ok(())
}

#[allow(dead_code)]
async fn create_table_test_super_error(client: &Client) -> Result<(), aws_sdk_dynamodb::Error> {
let _just_checking_compilation = client
.create_table()
.table_name("test")
.key_schema(
KeySchemaElement::builder()
.attribute_name("year")
.key_type(KeyType::Hash)
.build()?,
)
.send()
.await;
Ok(())
}
2 changes: 1 addition & 1 deletion aws/sdk/integration-tests/kms/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async fn generate_random() {
.header("content-type", "application/x-amz-json-1.1")
.header("x-amz-target", "TrentService.GenerateRandom")
.header("content-length", "20")
.header("authorization", "AWS4-HMAC-SHA256 Credential=ANOTREAL/20090213/us-east-1/kms/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date;x-amz-target;x-amz-user-agent, Signature=53dcf70f6f852cb576185dcabef5aaa3d068704cf1b7ea7dc644efeaa46674d7")
.header("authorization", "AWS4-HMAC-SHA256 Credential=ANOTREAL/20090213/us-east-1/kms/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date;x-amz-security-token;x-amz-target;x-amz-user-agent, Signature=703f72fe50c310e3ee1a7a106df947b980cb91bc8bad7a4a603b057096603aed")
.header("x-amz-date", "20090213T233130Z")
.header("user-agent", "aws-sdk-rust/0.123.test os/windows/XPSP3 lang/rust/1.50.0")
.header("x-amz-user-agent", "aws-sdk-rust/0.123.test api/test-service/0.123 os/windows/XPSP3 lang/rust/1.50.0")
Expand Down
Loading

0 comments on commit bfb4356

Please sign in to comment.