Unverified Commit c296e8e9 authored by ysaito1001's avatar ysaito1001 Committed by GitHub
Browse files

Move `Message`, `Header`, `HeaderValue`, and `StrBytes` from...

Move `Message`, `Header`, `HeaderValue`, and `StrBytes` from `aws-smithy-eventstream` to `aws-smithy-types` (#3139)

## Motivation and Context
Fixes the following statement in
https://github.com/awslabs/smithy-rs/pull/3114

> A notable breaking change is the error type of the new recv method.
Previously, it was [SdkError<E,
RawMessage>>](https://docs.rs/aws-smithy-http/0.57.0/aws_smithy_http/event_stream/struct.Receiver.html#method.recv)
but it is now a BoxError. This means that upon an event receive error,
customers can only show what the error is, but not match on it and take
some actions.

so that the `recv` method on a new-type wrapper
`aws_smithy_http::event_stream::Receiver` can expose `SdkError<E,
RawMessage>>` in public API. It is the responsibility of the above PR to
move
[RawMessage](https://github.com/awslabs/smithy-rs/blob/c7f0d5dc33937d65841d74b5b828cc77ed1d2db4/rust-runtime/aws-smithy-http/src/event_stream/receiver.rs#L92-L98)
from `aws-smithy-http` to `aws-smithy-types` but doing so first requires
`Message` to be moved to `aws-smithy-types`, hence this PR.


## Description
Moving `Message` to `aws-smithy-types` also requires moving the types it
depends upon, namely `Header`, `HederValue`, and `StrBytes`. However,
their serialization/deserialization methods (`read_from` and `write_to`)
remain in `aws-smithy-eventstream` and they are converted to free
functions, with the aim of moving things as minimally as possible.

`aws-smithy-eventstream` has fuzz testing. It previously implemented the
`Arbitrary` trait for moved types, but since they are now in
`aws-smithy-types`, we need to have newtypes for them to enable the
trait due to the orphan rules. A newly added module
`aws-smithy-eventstream::arbitrary` is exactly for that purpose.

## Testing
Relied on the existing tests.

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent 315d88b6
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -22,3 +22,11 @@ message = "The HTTP `Request`, `Response`, `Headers`, and `HeaderValue` types ha
references = ["smithy-rs#3138"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client" }
author = "jdisanti"

[[smithy-rs]]
message = """
`Message`, `Header`, `HeaderValue`, and `StrBytes` have been moved to `aws-smithy-types` from `aws-smithy-eventstream`. `Message::read_from` and `Message::write_to` remain in `aws-smithy-eventstream` but they are converted to free functions with the names `read_message_from` and `write_message_to` respectively.
"""
references = ["smithy-rs#3139"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "all"}
author = "ysaito1001"
+4 −2
Original line number Diff line number Diff line
@@ -223,8 +223,9 @@ mod event_stream {
    use aws_sigv4::event_stream::{sign_empty_message, sign_message};
    use aws_sigv4::sign::v4;
    use aws_smithy_async::time::SharedTimeSource;
    use aws_smithy_eventstream::frame::{Message, SignMessage, SignMessageError};
    use aws_smithy_eventstream::frame::{SignMessage, SignMessageError};
    use aws_smithy_runtime_api::client::identity::Identity;
    use aws_smithy_types::event_stream::Message;
    use aws_types::region::SigningRegion;
    use aws_types::SigningName;

@@ -293,7 +294,8 @@ mod event_stream {
        use crate::auth::sigv4::event_stream::SigV4MessageSigner;
        use aws_credential_types::Credentials;
        use aws_smithy_async::time::SharedTimeSource;
        use aws_smithy_eventstream::frame::{HeaderValue, Message, SignMessage};
        use aws_smithy_eventstream::frame::SignMessage;
        use aws_smithy_types::event_stream::{HeaderValue, Message};

        use aws_types::region::Region;
        use aws_types::region::SigningRegion;
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ aws-credential-types = { path = "../aws-credential-types" }
aws-smithy-eventstream = { path = "../../../rust-runtime/aws-smithy-eventstream", optional = true }
aws-smithy-http = { path = "../../../rust-runtime/aws-smithy-http" }
aws-smithy-runtime-api = { path = "../../../rust-runtime/aws-smithy-runtime-api", features = ["client"] }
aws-smithy-types = { path = "../../../rust-runtime/aws-smithy-types" }
bytes = "1"
form_urlencoded = { version = "1.0", optional = true }
hex = "0.4"
+1 −1
Original line number Diff line number Diff line
@@ -2,6 +2,6 @@ allowed_external_types = [
    # TODO(refactorHttp): Remove this and remove the signing helpers
    "http::request::Request",
    # TODO(https://github.com/awslabs/smithy-rs/issues/1193): Once tooling permits it, only allow the following types in the `event-stream` feature
    "aws_smithy_eventstream::frame::Message",
    "aws_smithy_types::event_stream::Message",
    "aws_smithy_runtime_api::client::identity::Identity"
]
+7 −5
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@
//!
//! ```rust
//! use aws_sigv4::event_stream::sign_message;
//! use aws_smithy_eventstream::frame::{Header, HeaderValue, Message};
//! use aws_smithy_types::event_stream::{Header, HeaderValue, Message};
//! use std::time::SystemTime;
//! use aws_credential_types::Credentials;
//! use aws_smithy_runtime_api::client::identity::Identity;
@@ -51,7 +51,8 @@ use crate::http_request::SigningError;
use crate::sign::v4::{calculate_signature, generate_signing_key, sha256_hex_string};
use crate::SigningOutput;
use aws_credential_types::Credentials;
use aws_smithy_eventstream::frame::{write_headers_to, Header, HeaderValue, Message};
use aws_smithy_eventstream::frame::{write_headers_to, write_message_to};
use aws_smithy_types::event_stream::{Header, HeaderValue, Message};
use bytes::Bytes;
use std::io::Write;
use std::time::SystemTime;
@@ -102,7 +103,7 @@ pub fn sign_message<'a>(
) -> Result<SigningOutput<Message>, SigningError> {
    let message_payload = {
        let mut payload = Vec::new();
        message.write_to(&mut payload).unwrap();
        write_message_to(message, &mut payload).unwrap();
        payload
    };
    sign_payload(Some(message_payload), last_signature, params)
@@ -161,7 +162,8 @@ mod tests {
    use crate::event_stream::{calculate_string_to_sign, sign_message, SigningParams};
    use crate::sign::v4::sha256_hex_string;
    use aws_credential_types::Credentials;
    use aws_smithy_eventstream::frame::{Header, HeaderValue, Message};
    use aws_smithy_eventstream::frame::write_message_to;
    use aws_smithy_types::event_stream::{Header, HeaderValue, Message};
    use std::time::{Duration, UNIX_EPOCH};

    #[test]
@@ -171,7 +173,7 @@ mod tests {
            HeaderValue::String("value".into()),
        ));
        let mut message_payload = Vec::new();
        message_to_sign.write_to(&mut message_payload).unwrap();
        write_message_to(&message_to_sign, &mut message_payload).unwrap();

        let params = SigningParams {
            identity: &Credentials::for_tests().into(),
Loading