Skip to content

Commit

Permalink
Merge branch 'main' into ysaito/ua-to-support-business-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
ysaito1001 committed Aug 2, 2024
2 parents 34919f5 + bb1971a commit 709168a
Show file tree
Hide file tree
Showing 53 changed files with 2,012 additions and 1,156 deletions.
10 changes: 10 additions & 0 deletions .changelog/.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Example changelog entry, Markdown with YAML front matter
# ---
# applies_to: ["client", "server", "aws-sdk-rust"] # "aws-sdk-rust" here duplicates this entry into release notes in `aws-sdk-rust`
# authors: ["rcoh"]
# references: ["smithy-rs#920"]
# breaking: false
# new_feature: false
# bug_fix: false
# ---
# Fix typos in module documentation for generated crates
14 changes: 14 additions & 0 deletions .changelog/1722464864.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
applies_to:
- aws-sdk-rust
- client
authors:
- landonxjames
references:
- smithy-rs#3765
- smithy-rs#3757
breaking: false
new_feature: false
bug_fix: true
---
Fix incorrect redaction of `@sensitive` types in maps and lists.
12 changes: 12 additions & 0 deletions .changelog/1722464947.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
applies_to:
- client
authors:
- ysaito1001
references:
- smithy-rs#3767
breaking: false
new_feature: false
bug_fix: true
---
Fix client error correction to properly parse structure members that target a `Union` containing that structure recursively.
4 changes: 2 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it rather than leaving it unchecked -->
- [ ] I have updated `CHANGELOG.next.toml` if I made changes to the smithy-rs codegen or runtime crates
- [ ] I have updated `CHANGELOG.next.toml` if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates
- [ ] For changes to the smithy-rs codegen or runtime crates, I have created a changelog entry Markdown file in the `.changelog` directory, specifying "client," "server," or both in the `applies_to` key.
- [ ] For changes to the AWS SDK, generated SDK code, or SDK runtime crates, I have created a changelog entry Markdown file in the `.changelog` directory, specifying "aws-sdk-rust" in the `applies_to` key.

----

Expand Down
24 changes: 0 additions & 24 deletions CHANGELOG.next.toml

This file was deleted.

2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
/rust-runtime/aws-smithy-http-server-typescript/ @smithy-lang/smithy-rs-server

# Shared ownership
/.changelog/ @smithy-lang/aws-sdk-rust @smithy-lang/smithy-rs-server
/.github/ @smithy-lang/aws-sdk-rust @smithy-lang/smithy-rs-server
/CHANGELOG.md @smithy-lang/aws-sdk-rust @smithy-lang/smithy-rs-server
/CHANGELOG.next.toml @smithy-lang/aws-sdk-rust @smithy-lang/smithy-rs-server
/README.md @smithy-lang/aws-sdk-rust @smithy-lang/smithy-rs-server
/build.gradle.kts @smithy-lang/aws-sdk-rust @smithy-lang/smithy-rs-server
/buildSrc/ @smithy-lang/aws-sdk-rust @smithy-lang/smithy-rs-server
Expand Down
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ To send us a pull request, please:
2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change.
3. Ensure local tests pass.
4. Commit to your fork using clear commit messages.
5. Send us a pull request, answering any default questions in the pull request interface.
5. Send us a pull request, answering any default questions in the pull request interface. To create a changelog entry Markdown file in the `.changelog` directory, you can do either of the following:
- Use the `new` subcommand of [changelogger](https://github.com/smithy-lang/smithy-rs/tree/main/tools/ci-build/changelogger) CLI (**preferred**)
- Create one manually. Name the file `XXX.md`, where `XXX` can be any name you choose, as long as it is unique in the `.changelog` directory. Ensure the contents follow Markdown syntax with the YAML front matter. For reference, see [.example](https://github.com/smithy-lang/smithy-rs/blob/3e250cf9f61ee17ccd66e16314d4e47f3dd95e25/.changelog/.example) or other Markdown files in the `.changelog` directory.
6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.
7. Ask maintainers to manually trigger [canary](https://github.com/smithy-lang/smithy-rs/actions/workflows/manual-canary.yml) and [PR bot](https://github.com/smithy-lang/smithy-rs/actions/workflows/manual-pull-request-bot.yml) workflows using your pull request number. Those workflows cannot run in your fork and are always skipped as such.

Expand Down
2 changes: 2 additions & 0 deletions aws/sdk-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ dependencies {
implementation("software.amazon.smithy:smithy-protocol-test-traits:$smithyVersion")
implementation("software.amazon.smithy:smithy-rules-engine:$smithyVersion")
implementation("software.amazon.smithy:smithy-aws-endpoints:$smithyVersion")
implementation("software.amazon.smithy:smithy-smoke-test-traits:$smithyVersion")
implementation("software.amazon.smithy:smithy-aws-smoke-test-model:$smithyVersion")
}

java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ val DECORATORS: List<ClientCodegenDecorator> =
TokenProvidersDecorator(),
ServiceEnvConfigDecorator(),
HttpRequestCompressionDecorator(),
SmokeTestsDecorator(),
),
// S3 needs `AwsErrorCodeClassifier` to handle an `InternalError` as a transient error. We need to customize
// that behavior for S3 in a way that does not conflict with the globally applied `RetryClassifierDecorator`.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.smithy.rustsdk

import software.amazon.smithy.aws.smoketests.model.AwsSmokeTestModel
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.node.ObjectNode
import software.amazon.smithy.model.shapes.MemberShape
import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.model.shapes.StructureShape
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator
import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientGenerator
import software.amazon.smithy.rust.codegen.core.rustlang.Attribute
import software.amazon.smithy.rust.codegen.core.rustlang.Attribute.Companion.cfg
import software.amazon.smithy.rust.codegen.core.rustlang.AttributeKind
import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter
import software.amazon.smithy.rust.codegen.core.rustlang.containerDocs
import software.amazon.smithy.rust.codegen.core.rustlang.docs
import software.amazon.smithy.rust.codegen.core.rustlang.rust
import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock
import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext
import software.amazon.smithy.rust.codegen.core.smithy.RustCrate
import software.amazon.smithy.rust.codegen.core.smithy.generators.BuilderGenerator
import software.amazon.smithy.rust.codegen.core.smithy.generators.Instantiator
import software.amazon.smithy.rust.codegen.core.smithy.generators.setterName
import software.amazon.smithy.rust.codegen.core.testutil.integrationTest
import software.amazon.smithy.rust.codegen.core.util.dq
import software.amazon.smithy.rust.codegen.core.util.expectTrait
import software.amazon.smithy.rust.codegen.core.util.inputShape
import software.amazon.smithy.rust.codegen.core.util.orNull
import software.amazon.smithy.rust.codegen.core.util.toSnakeCase
import software.amazon.smithy.smoketests.traits.Expectation
import software.amazon.smithy.smoketests.traits.SmokeTestCase
import software.amazon.smithy.smoketests.traits.SmokeTestsTrait
import java.util.Optional
import java.util.logging.Logger

class SmokeTestsDecorator : ClientCodegenDecorator {
override val name: String = "SmokeTests"
override val order: Byte = 0
private val logger: Logger = Logger.getLogger(javaClass.name)

private fun isSmokeTestSupported(smokeTestCase: SmokeTestCase): Boolean {
AwsSmokeTestModel.getAwsVendorParams(smokeTestCase)?.orNull()?.let { vendorParams ->
if (vendorParams.sigv4aRegionSet.isPresent) {
logger.warning("skipping smoketest `${smokeTestCase.id}` with unsupported vendorParam `sigv4aRegionSet`")
return false
}
// TODO(https://github.com/smithy-lang/smithy-rs/issues/3776) Once Account ID routing is supported,
// update the vendorParams setter and remove this check.
if (vendorParams.useAccountIdRouting()) {
logger.warning("skipping smoketest `${smokeTestCase.id}` with unsupported vendorParam `useAccountIdRouting`")
return false
}
}
AwsSmokeTestModel.getS3VendorParams(smokeTestCase)?.orNull()?.let { s3VendorParams ->
if (s3VendorParams.useGlobalEndpoint()) {
logger.warning("skipping smoketest `${smokeTestCase.id}` with unsupported vendorParam `useGlobalEndpoint`")
return false
}
}

return true
}

override fun extras(
codegenContext: ClientCodegenContext,
rustCrate: RustCrate,
) {
// Get all operations with smoke tests
val smokeTestedOperations =
codegenContext.model.getOperationShapesWithTrait(SmokeTestsTrait::class.java).toList()
val supportedTests =
smokeTestedOperations.map { operationShape ->
// filter out unsupported smoke tests, logging a warning for each one.
val testCases =
operationShape.expectTrait<SmokeTestsTrait>().testCases.filter { smokeTestCase ->
isSmokeTestSupported(smokeTestCase)
}

operationShape to testCases
}
// filter out operations with no supported smoke tests
.filter { (_, testCases) -> testCases.isNotEmpty() }
// Return if there are no supported smoke tests across all operations
if (supportedTests.isEmpty()) return

rustCrate.integrationTest("smoketests") {
// Don't run the tests in this module unless `RUSTFLAGS="--cfg smoketests"` is passed.
Attribute(cfg("smoketests")).render(this, AttributeKind.Inner)

containerDocs(
"""
The tests in this module run against live AWS services. As such,
they are disabled by default. To enable them, run the tests with
```sh
RUSTFLAGS="--cfg smoketests" cargo test.
```""",
)

val model = codegenContext.model
val moduleUseName = codegenContext.moduleUseName()
rust("use $moduleUseName::{ Client, config };")

for ((operationShape, testCases) in supportedTests) {
val operationName = operationShape.id.name.toSnakeCase()
val operationInput = operationShape.inputShape(model)

docs("Smoke tests for the `$operationName` operation")

for (testCase in testCases) {
Attribute.TokioTest.render(this)
this.rustBlock("async fn test_${testCase.id.toSnakeCase()}()") {
val instantiator = SmokeTestsInstantiator(codegenContext)
instantiator.renderConf(this, testCase)
rust("let client = Client::from_conf(conf);")
instantiator.renderInput(this, operationShape, operationInput, testCase.params)
instantiator.renderExpectation(this, model, testCase.expectation)
}
}
}
}
}
}

class SmokeTestsBuilderKindBehavior(val codegenContext: CodegenContext) : Instantiator.BuilderKindBehavior {
override fun hasFallibleBuilder(shape: StructureShape): Boolean =
BuilderGenerator.hasFallibleBuilder(shape, codegenContext.symbolProvider)

override fun setterName(memberShape: MemberShape): String = memberShape.setterName()

override fun doesSetterTakeInOption(memberShape: MemberShape): Boolean = true
}

class SmokeTestsInstantiator(private val codegenContext: ClientCodegenContext) : Instantiator(
codegenContext.symbolProvider,
codegenContext.model,
codegenContext.runtimeConfig,
SmokeTestsBuilderKindBehavior(codegenContext),
) {
fun renderConf(
writer: RustWriter,
testCase: SmokeTestCase,
) {
writer.rust("let conf = config::Builder::new()")
writer.indent()
writer.rust(".behavior_version(config::BehaviorVersion::latest())")

val vendorParams = AwsSmokeTestModel.getAwsVendorParams(testCase)
vendorParams.orNull()?.let { params ->
writer.rust(".region(config::Region::new(${params.region.dq()}))")
writer.rust(".use_dual_stack(${params.useDualstack()})")
writer.rust(".use_fips(${params.useFips()})")
params.uri.orNull()?.let { writer.rust(".endpoint_url($it)") }
}

val s3VendorParams = AwsSmokeTestModel.getS3VendorParams(testCase)
s3VendorParams.orNull()?.let { params ->
writer.rust(".accelerate_(${params.useAccelerate()})")
writer.rust(".force_path_style_(${params.forcePathStyle()})")
writer.rust(".use_arn_region(${params.useArnRegion()})")
writer.rust(".disable_multi_region_access_points(${params.useMultiRegionAccessPoints().not()})")
}

writer.rust(".build();")
writer.dedent()
}

fun renderInput(
writer: RustWriter,
operationShape: OperationShape,
inputShape: StructureShape,
data: Optional<ObjectNode>,
headers: Map<String, String> = mapOf(),
ctx: Ctx = Ctx(),
) {
val operationBuilderName =
FluentClientGenerator.clientOperationFnName(operationShape, codegenContext.symbolProvider)

writer.rust("let res = client.$operationBuilderName()")
writer.indent()
data.orNull()?.let {
renderStructureMembers(writer, inputShape, it, headers, ctx)
}
writer.rust(".send().await;")
writer.dedent()
}

fun renderExpectation(
writer: RustWriter,
model: Model,
expectation: Expectation,
) {
if (expectation.isSuccess) {
writer.rust("""res.expect("request should succeed");""")
} else if (expectation.isFailure) {
val expectedErrShape = expectation.failure.orNull()?.errorId?.orNull()
println(expectedErrShape)
if (expectedErrShape != null) {
val failureShape = model.expectShape(expectedErrShape)
val errName = codegenContext.symbolProvider.toSymbol(failureShape).name.toSnakeCase()
writer.rust(
"""
let err = res.expect_err("request should fail");
let err = err.into_service_error();
assert!(err.is_$errName())
""",
)
} else {
writer.rust("""res.expect_err("request should fail");""")
}
}
}
}
Loading

0 comments on commit 709168a

Please sign in to comment.