Skip to content

Commit 149711f

Browse files
Merge branch 'main' into RFC30/tests
2 parents c2abf69 + d753827 commit 149711f

File tree

81 files changed

+1857
-436
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1857
-436
lines changed

aws/rust-runtime/aws-config/src/test_case.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ pub(crate) struct Metadata {
136136
name: String,
137137
}
138138

139+
// TODO(enableNewSmithyRuntimeCleanup): Replace Tee, capture_test_logs, and Rx with
140+
// the implementations added to aws_smithy_runtime::test_util::capture_test_logs
139141
struct Tee<W> {
140142
buf: Arc<Mutex<Vec<u8>>>,
141143
quiet: bool,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ class AwsPresignedFluentBuilderMethod(
322322
323323
let runtime_plugins = #{Operation}::operation_runtime_plugins(
324324
self.handle.runtime_plugins.clone(),
325-
self.config_override
325+
&self.handle.conf,
326+
self.config_override,
326327
)
327328
.with_client_plugin(#{SigV4PresigningRuntimePlugin}::new(presigning_config, #{payload_override}))
328329
#{alternate_presigning_serializer_registration};

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,36 @@ class CredentialCacheConfig(codegenContext: ClientCodegenContext) : ConfigCustom
191191
}
192192
}
193193

194+
is ServiceConfig.OperationConfigOverride -> {
195+
rustTemplate(
196+
"""
197+
match (
198+
layer
199+
.load::<#{CredentialsCache}>()
200+
.cloned(),
201+
layer
202+
.load::<#{SharedCredentialsProvider}>()
203+
.cloned(),
204+
) {
205+
(#{None}, #{None}) => {}
206+
(#{None}, _) => {
207+
panic!("also specify `.credentials_cache` when overriding credentials provider for the operation");
208+
}
209+
(_, #{None}) => {
210+
panic!("also specify `.credentials_provider` when overriding credentials cache for the operation");
211+
}
212+
(
213+
#{Some}(credentials_cache),
214+
#{Some}(credentials_provider),
215+
) => {
216+
layer.store_put(credentials_cache.create_cache(credentials_provider));
217+
}
218+
}
219+
""",
220+
*codegenScope,
221+
)
222+
}
223+
194224
else -> emptySection
195225
}
196226
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
1515
import software.amazon.smithy.rust.codegen.core.rustlang.writable
1616
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig
1717
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType
18+
import software.amazon.smithy.rust.codegen.core.util.letIf
1819

1920
class RetryClassifierDecorator : ClientCodegenDecorator {
2021
override val name: String = "RetryPolicy"
@@ -25,10 +26,12 @@ class RetryClassifierDecorator : ClientCodegenDecorator {
2526
operation: OperationShape,
2627
baseCustomizations: List<OperationCustomization>,
2728
): List<OperationCustomization> =
28-
baseCustomizations + RetryClassifierFeature(codegenContext.runtimeConfig) + OperationRetryClassifiersFeature(
29-
codegenContext,
30-
operation,
31-
)
29+
(baseCustomizations + RetryClassifierFeature(codegenContext.runtimeConfig)).letIf(codegenContext.smithyRuntimeMode.generateOrchestrator) {
30+
it + OperationRetryClassifiersFeature(
31+
codegenContext,
32+
operation,
33+
)
34+
}
3235
}
3336

3437
class RetryClassifierFeature(private val runtimeConfig: RuntimeConfig) : OperationCustomization() {

aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/timestream/TimestreamDecorator.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ class TimestreamDecorator : ClientCodegenDecorator {
5252
Visibility.PUBLIC,
5353
CargoDependency.Tokio.copy(scope = DependencyScope.Compile, features = setOf("sync")),
5454
)
55-
val runtimeMode = codegenContext.smithyRuntimeMode
5655
rustCrate.lib {
5756
// helper function to resolve an endpoint given a base client
5857
rustTemplate(
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.rustsdk
7+
8+
import org.junit.jupiter.api.Test
9+
import software.amazon.smithy.rust.codegen.core.rustlang.Attribute
10+
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
11+
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType
12+
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel
13+
import software.amazon.smithy.rust.codegen.core.testutil.testModule
14+
import software.amazon.smithy.rust.codegen.core.testutil.tokioTest
15+
import software.amazon.smithy.rust.codegen.core.testutil.unitTest
16+
17+
internal class CredentialCacheConfigTest {
18+
private val model = """
19+
namespace com.example
20+
use aws.protocols#awsJson1_0
21+
use aws.api#service
22+
use smithy.rules#endpointRuleSet
23+
24+
@service(sdkId: "Some Value")
25+
@awsJson1_0
26+
@endpointRuleSet({
27+
"version": "1.0",
28+
"rules": [{
29+
"type": "endpoint",
30+
"conditions": [{"fn": "isSet", "argv": [{"ref": "Region"}]}],
31+
"endpoint": { "url": "https://example.com" }
32+
}],
33+
"parameters": {
34+
"Region": { "required": false, "type": "String", "builtIn": "AWS::Region" },
35+
}
36+
})
37+
service HelloService {
38+
operations: [SayHello],
39+
version: "1"
40+
}
41+
42+
@optionalAuth
43+
operation SayHello { input: TestInput }
44+
structure TestInput {
45+
foo: String,
46+
}
47+
""".asSmithyModel()
48+
49+
@Test
50+
fun `config override for credentials`() {
51+
awsSdkIntegrationTest(model, defaultToOrchestrator = true) { clientCodegenContext, rustCrate ->
52+
val runtimeConfig = clientCodegenContext.runtimeConfig
53+
val codegenScope = arrayOf(
54+
*RuntimeType.preludeScope,
55+
"Credentials" to AwsRuntimeType.awsCredentialTypesTestUtil(runtimeConfig)
56+
.resolve("Credentials"),
57+
"CredentialsCache" to AwsRuntimeType.awsCredentialTypes(runtimeConfig)
58+
.resolve("cache::CredentialsCache"),
59+
"ProvideCachedCredentials" to AwsRuntimeType.awsCredentialTypes(runtimeConfig)
60+
.resolve("cache::ProvideCachedCredentials"),
61+
"RuntimePlugin" to RuntimeType.smithyRuntimeApi(runtimeConfig)
62+
.resolve("client::runtime_plugin::RuntimePlugin"),
63+
"SharedCredentialsCache" to AwsRuntimeType.awsCredentialTypes(runtimeConfig)
64+
.resolve("cache::SharedCredentialsCache"),
65+
"SharedCredentialsProvider" to AwsRuntimeType.awsCredentialTypes(runtimeConfig)
66+
.resolve("provider::SharedCredentialsProvider"),
67+
)
68+
rustCrate.testModule {
69+
unitTest(
70+
"test_overriding_only_credentials_provider_should_panic",
71+
additionalAttributes = listOf(Attribute.shouldPanic("also specify `.credentials_cache` when overriding credentials provider for the operation")),
72+
) {
73+
rustTemplate(
74+
"""
75+
use #{RuntimePlugin};
76+
77+
let client_config = crate::config::Config::builder().build();
78+
let config_override =
79+
crate::config::Config::builder().credentials_provider(#{Credentials}::for_tests());
80+
let sut = crate::config::ConfigOverrideRuntimePlugin {
81+
client_config: client_config.config().unwrap(),
82+
config_override,
83+
};
84+
85+
// this should cause `panic!`
86+
let _ = sut.config().unwrap();
87+
""",
88+
*codegenScope,
89+
)
90+
}
91+
92+
unitTest(
93+
"test_overriding_only_credentials_cache_should_panic",
94+
additionalAttributes = listOf(Attribute.shouldPanic("also specify `.credentials_provider` when overriding credentials cache for the operation")),
95+
) {
96+
rustTemplate(
97+
"""
98+
use #{RuntimePlugin};
99+
100+
let client_config = crate::config::Config::builder().build();
101+
let config_override = crate::config::Config::builder()
102+
.credentials_cache(#{CredentialsCache}::no_caching());
103+
let sut = crate::config::ConfigOverrideRuntimePlugin {
104+
client_config: client_config.config().unwrap(),
105+
config_override,
106+
};
107+
108+
// this should cause `panic!`
109+
let _ = sut.config().unwrap();
110+
""",
111+
*codegenScope,
112+
)
113+
}
114+
115+
tokioTest("test_overriding_cache_and_provider_leads_to_shared_credentials_cache_in_layer") {
116+
rustTemplate(
117+
"""
118+
use #{ProvideCachedCredentials};
119+
use #{RuntimePlugin};
120+
121+
let client_config = crate::config::Config::builder()
122+
.credentials_provider(#{Credentials}::for_tests())
123+
.build();
124+
let client_config_layer = client_config.config().unwrap();
125+
126+
// make sure test credentials are set in the client config level
127+
assert_eq!(#{Credentials}::for_tests(),
128+
client_config_layer
129+
.load::<#{SharedCredentialsCache}>()
130+
.unwrap()
131+
.provide_cached_credentials()
132+
.await
133+
.unwrap()
134+
);
135+
136+
let credentials = #{Credentials}::new(
137+
"test",
138+
"test",
139+
#{None},
140+
#{None},
141+
"test",
142+
);
143+
let config_override = crate::config::Config::builder()
144+
.credentials_cache(#{CredentialsCache}::lazy())
145+
.credentials_provider(credentials.clone());
146+
let sut = crate::config::ConfigOverrideRuntimePlugin {
147+
client_config: client_config_layer,
148+
config_override,
149+
};
150+
let sut_layer = sut.config().unwrap();
151+
152+
// make sure `.provide_cached_credentials` returns credentials set through `config_override`
153+
assert_eq!(credentials,
154+
sut_layer
155+
.load::<#{SharedCredentialsCache}>()
156+
.unwrap()
157+
.provide_cached_credentials()
158+
.await
159+
.unwrap()
160+
);
161+
""",
162+
*codegenScope,
163+
)
164+
}
165+
166+
unitTest("test_not_overriding_cache_and_provider_leads_to_no_shared_credentials_cache_in_layer") {
167+
rustTemplate(
168+
"""
169+
use #{RuntimePlugin};
170+
171+
let client_config = crate::config::Config::builder().build();
172+
let config_override = crate::config::Config::builder();
173+
let sut = crate::config::ConfigOverrideRuntimePlugin {
174+
client_config: client_config.config().unwrap(),
175+
config_override,
176+
};
177+
let sut_layer = sut.config().unwrap();
178+
assert!(sut_layer
179+
.load::<#{SharedCredentialsCache}>()
180+
.is_none());
181+
""",
182+
*codegenScope,
183+
)
184+
}
185+
}
186+
}
187+
}
188+
}

aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/TestUtil.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package software.amazon.smithy.rustsdk
77

88
import software.amazon.smithy.model.Model
99
import software.amazon.smithy.model.node.ObjectNode
10+
import software.amazon.smithy.model.node.StringNode
1011
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
1112
import software.amazon.smithy.rust.codegen.client.smithy.ClientRustSettings
1213
import software.amazon.smithy.rust.codegen.client.testutil.clientIntegrationTest
@@ -17,6 +18,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.RustCrate
1718
import software.amazon.smithy.rust.codegen.core.testutil.IntegrationTestParams
1819
import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig
1920
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel
21+
import software.amazon.smithy.rust.codegen.core.util.letIf
2022
import java.io.File
2123

2224
// In aws-sdk-codegen, the working dir when gradle runs tests is actually `./aws`. So, to find the smithy runtime, we need
@@ -35,8 +37,10 @@ fun awsTestCodegenContext(model: Model? = null, settings: ClientRustSettings? =
3537
settings = settings ?: testClientRustSettings(runtimeConfig = AwsTestRuntimeConfig),
3638
)
3739

40+
// TODO(enableNewSmithyRuntimeCleanup): Remove defaultToOrchestrator once the runtime switches to the orchestrator
3841
fun awsSdkIntegrationTest(
3942
model: Model,
43+
defaultToOrchestrator: Boolean = false,
4044
test: (ClientCodegenContext, RustCrate) -> Unit = { _, _ -> },
4145
) =
4246
clientIntegrationTest(
@@ -58,6 +62,9 @@ fun awsSdkIntegrationTest(
5862
"codegen",
5963
ObjectNode.builder()
6064
.withMember("includeFluentClient", false)
65+
.letIf(defaultToOrchestrator) {
66+
it.withMember("enableNewSmithyRuntime", StringNode.from("orchestrator"))
67+
}
6168
.build(),
6269
).build(),
6370
),

aws/sdk/build.gradle.kts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
import aws.sdk.AwsExamplesLayout
67
import aws.sdk.AwsServices
78
import aws.sdk.Membership
89
import aws.sdk.discoverServices
@@ -201,6 +202,7 @@ tasks.register("relocateExamples") {
201202
}
202203
into(outputDir)
203204
exclude("**/target")
205+
exclude("**/rust-toolchain.toml")
204206
filter { line -> line.replace("build/aws-sdk/sdk/", "sdk/") }
205207
}
206208
}
@@ -242,13 +244,22 @@ tasks.register<ExecRustBuildTool>("fixExampleManifests") {
242244

243245
toolPath = sdkVersionerToolPath
244246
binaryName = "sdk-versioner"
245-
arguments = listOf(
246-
"use-path-and-version-dependencies",
247-
"--isolate-crates",
248-
"--sdk-path", "../../sdk",
249-
"--versions-toml", outputDir.resolve("versions.toml").absolutePath,
250-
outputDir.resolve("examples").absolutePath,
251-
)
247+
arguments = when (AwsExamplesLayout.detect(project)) {
248+
AwsExamplesLayout.Flat -> listOf(
249+
"use-path-and-version-dependencies",
250+
"--isolate-crates",
251+
"--sdk-path", "../../sdk",
252+
"--versions-toml", outputDir.resolve("versions.toml").absolutePath,
253+
outputDir.resolve("examples").absolutePath,
254+
)
255+
AwsExamplesLayout.Workspaces -> listOf(
256+
"use-path-and-version-dependencies",
257+
"--isolate-crates",
258+
"--sdk-path", sdkOutputDir.absolutePath,
259+
"--versions-toml", outputDir.resolve("versions.toml").absolutePath,
260+
outputDir.resolve("examples").absolutePath,
261+
)
262+
}
252263

253264
outputs.dir(outputDir)
254265
dependsOn("relocateExamples", "generateVersionManifest")

0 commit comments

Comments
 (0)