Skip to content

Commit

Permalink
Merge branch 'main' into 1671
Browse files Browse the repository at this point in the history
  • Loading branch information
82marbag authored Nov 1, 2022
2 parents 5dc5d59 + e9f876a commit 1df22af
Show file tree
Hide file tree
Showing 21 changed files with 232 additions and 82 deletions.
4 changes: 4 additions & 0 deletions .github/ISSUE_TEMPLATE/blank_issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
name: Blank Issue
about: Create a blank issue.
---
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blank_issues_enabled: false
27 changes: 27 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,30 @@ message = "`EnumTrait` is deprecated in favor of `EnumShape`. Unnamed members mi
references = ["smithy-rs#1671"]
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "82marbag"

[[smithy-rs]]
message = "Fix bug that can cause panics in paginators"
references = ["smithy-rs#1903", "smithy-rs#1902"]
meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "client"}
author = "rcoh"

[[smithy-rs]]
message = """
Operation metadata is now added to the property bag before sending requests allowing middlewares to behave
differently depending on the operation being sent.
"""
references = ["smithy-rs#1919"]
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client"}
author = "Velfi"

[[smithy-rs]]
message = "Upgrade Smithy to v1.26"
references = ["smithy-rs#1929"]
meta = { "breaking" = false, "tada" = true, "bug" = false, "target" = "all"}
author = "Velfi"

[[smithy-rs]]
message = "Fix cargo audit issue on chrono."
references = ["smithy-rs#1907"]
meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "all" }
author = "ysaito1001"
28 changes: 19 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,29 @@ Some components, such as `codegen-client-test` and `codegen-server-test`, are pu
To test the `rust-runtime` crates:

```bash
# Run all Rust tests for `rust-runtime/`
./gradlew rust-runtime:cargoTest
# Run clippy for `rust-runtime/`
./gradlew rust-runtime:cargoClippy
# Run all Rust tests for `rust-runtime/` (from repo root):
cargo test --manifest-path=rust-runtime/Cargo.toml
# Run clippy for `rust-runtime/` (from repo root):
cargo clippy --manifest-path=rust-runtime/Cargo.toml

# Or
cd rust-runtime
cargo test
cargo clippy
```

For `aws/rust-runtime`, just prefix with `aws:`:
To test the `aws/rust-runtime` crates:

```bash
# Run all Rust tests for `rust-runtime/`
./gradlew aws:rust-runtime:cargoTest
# Run clippy for `rust-runtime/`
./gradlew aws:rust-runtime:cargoClippy
# Run all Rust tests for `aws/rust-runtime/` (from repo root):
cargo test --manifest-path=aws/rust-runtime/Cargo.toml
# Run clippy for `aws/rust-runtime/` (from repo root):
cargo clippy --manifest-path=aws/rust-runtime/Cargo.toml

# Or
cd aws/rust-runtime
cargo test
cargo clippy
```

Some runtime crates have a `additional-ci` script that can also be run. These scripts often require
Expand Down
6 changes: 6 additions & 0 deletions aws/rust-runtime/aws-inlineable/external-types.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
allowed_external_types = [
"aws_endpoint::*",
"aws_http::*",
"aws_sig_auth::*",
"aws_smithy_client::*",
"aws_smithy_http::*",
"aws_smithy_http_tower::*",
"aws_smithy_types::*",
"aws_types::*",
"http::header::map::HeaderMap",
Expand All @@ -12,4 +16,6 @@ allowed_external_types = [

# TODO(https://github.com/awslabs/smithy-rs/issues/1193): Decide if we want to continue exposing tower_layer
"tower_layer::Layer",
"tower_layer::identity::Identity",
"tower_layer::stack::Stack",
]
38 changes: 38 additions & 0 deletions aws/rust-runtime/aws-inlineable/tests/middleware_e2e_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use aws_http::retry::AwsResponseRetryClassifier;
use aws_http::user_agent::AwsUserAgent;
use aws_inlineable::middleware::DefaultMiddleware;
use aws_sig_auth::signer::OperationSigningConfig;
use aws_smithy_client::erase::DynConnector;

use aws_smithy_client::test_connection::TestConnection;
use aws_smithy_http::body::SdkBody;
Expand Down Expand Up @@ -112,6 +113,7 @@ fn test_operation() -> Operation<TestOperationParser, AwsResponseRetryClassifier
.unwrap();
Operation::new(req, TestOperationParser)
.with_retry_classifier(AwsResponseRetryClassifier::new())
.with_metadata(operation::Metadata::new("test-op", "test-service"))
}

#[cfg(any(feature = "native-tls", feature = "rustls"))]
Expand Down Expand Up @@ -148,3 +150,39 @@ async fn e2e_test() {

conn.assert_requests_match(&[]);
}

#[tokio::test]
async fn test_operation_metadata_is_available_to_middlewares() {
let conn = TestConnection::new(vec![(
http::Request::builder()
.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")
.header(AUTHORIZATION, "AWS4-HMAC-SHA256 Credential=access_key/20210215/test-region/test-service-signing/aws4_request, SignedHeaders=host;x-amz-date;x-amz-user-agent, Signature=da249491d7fe3da22c2e09cbf910f37aa5b079a3cedceff8403d0b18a7bfab75")
.header("x-amz-date", "20210215T184017Z")
.uri(Uri::from_static("https://test-service.test-region.amazonaws.com/"))
.body(SdkBody::from("request body")).unwrap(),
http::Response::builder()
.status(200)
.body("response body")
.unwrap(),
)]);
let client = aws_smithy_client::Client::builder()
.middleware_fn(|req| {
let metadata = req
.properties()
.get::<operation::Metadata>()
.cloned()
.unwrap();

assert_eq!("test-op", metadata.name());
assert_eq!("test-service", metadata.service());

req
})
.connector(DynConnector::new(conn))
.build();

let resp = client.call(test_operation()).await;
let resp = resp.expect("successful operation");
assert_eq!(resp, "Hello!");
}
5 changes: 5 additions & 0 deletions aws/sdk/sdk-external-types.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# These are the allowed external types in the `aws-sdk-*` generated crates, checked by CI.
allowed_external_types = [
"aws_endpoint::*",
"aws_http::*",
"aws_sig_auth::*",
"aws_smithy_async::*",
"aws_smithy_client::*",
"aws_smithy_http::*",
"aws_smithy_http_tower::*",
"aws_smithy_types::*",
"aws_types::*",
"http::header::map::HeaderMap",
Expand All @@ -21,4 +24,6 @@ allowed_external_types = [

# TODO(https://github.com/awslabs/smithy-rs/issues/1193): Decide if we want to continue exposing tower_layer
"tower_layer::Layer",
"tower_layer::identity::Identity",
"tower_layer::stack::Stack",
]
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ open class MakeOperationGenerator(
) {
val operationName = symbolProvider.toSymbol(shape).name
val baseReturnType = buildOperationType(implBlockWriter, shape, customizations)
val returnType = "std::result::Result<$baseReturnType, ${implBlockWriter.format(runtimeConfig.operationBuildError())}>"
val returnType =
"std::result::Result<$baseReturnType, ${implBlockWriter.format(runtimeConfig.operationBuildError())}>"
val outputSymbol = symbolProvider.toSymbol(shape)

val takesOwnership = bodyGenerator.payloadMetadata(shape).takesOwnership
Expand All @@ -82,8 +83,10 @@ open class MakeOperationGenerator(

implBlockWriter.docs("Consumes the builder and constructs an Operation<#D>", outputSymbol)
Attribute.AllowUnusedMut.render(implBlockWriter) // For codegen simplicity
Attribute.Custom("allow(clippy::let_and_return)").render(implBlockWriter) // For codegen simplicity, allow `let x = ...; x`
Attribute.Custom("allow(clippy::needless_borrow)").render(implBlockWriter) // Allows builders that don’t consume the input borrow
Attribute.Custom("allow(clippy::let_and_return)")
.render(implBlockWriter) // For codegen simplicity, allow `let x = ...; x`
Attribute.Custom("allow(clippy::needless_borrow)")
.render(implBlockWriter) // Allows builders that don’t consume the input borrow
implBlockWriter.rustBlockTemplate(
"$fnType $functionName($self, _config: &#{config}::Config) -> $returnType",
*codegenScope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ import software.amazon.smithy.rust.codegen.core.util.outputShape
sealed class JsonSection(name: String) : Section(name) {
/** Mutate the server error object prior to finalization. Eg: this can be used to inject `__type` to record the error type. */
data class ServerError(val structureShape: StructureShape, val jsonObject: String) : JsonSection("ServerError")

/** Mutate the input object prior to finalization. */
data class InputStruct(val structureShape: StructureShape, val jsonObject: String) : JsonSection("InputStruct")

/** Mutate the output object prior to finalization. */
data class OutputStruct(val structureShape: StructureShape, val jsonObject: String) : JsonSection("OutputStruct")
}

/**
Expand Down Expand Up @@ -166,13 +172,14 @@ class JsonSerializerGenerator(

/**
* Reusable structure serializer implementation that can be used to generate serializing code for
* operation, error and structure shapes.
* operation outputs or errors.
* This function is only used by the server, the client uses directly [serializeStructure].
*/
private fun serverStructureSerializer(
private fun serverSerializer(
fnName: String,
structureShape: StructureShape,
includedMembers: List<MemberShape>,
makeSection: (StructureShape, String) -> JsonSection,
): RuntimeType {
return RuntimeType.forInlineFun(fnName, operationSerModule) {
rustBlockTemplate(
Expand All @@ -183,7 +190,7 @@ class JsonSerializerGenerator(
rust("let mut out = String::new();")
rustTemplate("let mut object = #{JsonObjectWriter}::new(&mut out);", *codegenScope)
serializeStructure(StructContext("object", "value", structureShape), includedMembers)
customizations.forEach { it.section(JsonSection.ServerError(structureShape, "object"))(this) }
customizations.forEach { it.section(makeSection(structureShape, "object"))(this) }
rust("object.finish();")
rustTemplate("Ok(out)", *codegenScope)
}
Expand Down Expand Up @@ -243,6 +250,7 @@ class JsonSerializerGenerator(
rust("let mut out = String::new();")
rustTemplate("let mut object = #{JsonObjectWriter}::new(&mut out);", *codegenScope)
serializeStructure(StructContext("object", "input", inputShape), httpDocumentMembers)
customizations.forEach { it.section(JsonSection.InputStruct(inputShape, "object"))(this) }
rust("object.finish();")
rustTemplate("Ok(#{SdkBody}::from(out))", *codegenScope)
}
Expand Down Expand Up @@ -284,7 +292,7 @@ class JsonSerializerGenerator(

val outputShape = operationShape.outputShape(model)
val fnName = symbolProvider.serializeFunctionName(outputShape)
return serverStructureSerializer(fnName, outputShape, httpDocumentMembers)
return serverSerializer(fnName, outputShape, httpDocumentMembers, JsonSection::OutputStruct)
}

override fun serverErrorSerializer(shape: ShapeId): RuntimeType {
Expand All @@ -293,7 +301,7 @@ class JsonSerializerGenerator(
httpBindingResolver.errorResponseBindings(shape).filter { it.location == HttpLocation.DOCUMENT }
.map { it.member }
val fnName = symbolProvider.serializeFunctionName(errorShape)
return serverStructureSerializer(fnName, errorShape, includedMembers)
return serverSerializer(fnName, errorShape, includedMembers, JsonSection::ServerError)
}

private fun RustWriter.serializeStructure(
Expand Down
Loading

0 comments on commit 1df22af

Please sign in to comment.