Server Test

Server Test

rev. 017463e70903525380130343a50f105c32212f76 (ignoring whitespace)

Files changed:

tmp-codegen-diff/codegen-server-test/rpcv2Cbor_extras/rust-server-codegen/src/input.rs

@@ -1,1 +84,92 @@
    1      1   
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
    2      2   
#[allow(missing_docs)] // documentation missing in model
    3      3   
#[derive(::std::fmt::Debug)]
    4      4   
pub struct StreamingOperationWithInitialDataInput {
    5      5   
    #[allow(missing_docs)] // documentation missing in model
    6      6   
    pub initial_data: ::std::string::String,
    7      7   
    #[allow(missing_docs)] // documentation missing in model
    8      8   
    pub events: ::aws_smithy_http::event_stream::Receiver<
    9         -
        crate::model::Events,
           9  +
        crate::sigv4_event_stream::SignedEvent<crate::model::Events>,
          10  +
        crate::sigv4_event_stream::SignedEventError<
   10     11   
            ::aws_smithy_http::event_stream::MessageStreamError,
   11     12   
        >,
          13  +
    >,
   12     14   
}
   13     15   
impl StreamingOperationWithInitialDataInput {
   14     16   
    #[allow(missing_docs)] // documentation missing in model
   15     17   
    pub fn initial_data(&self) -> &str {
   16     18   
        use std::ops::Deref;
   17     19   
        self.initial_data.deref()
   18     20   
    }
   19     21   
    #[allow(missing_docs)] // documentation missing in model
   20     22   
    pub fn events(
   21     23   
        &self,
   22     24   
    ) -> &::aws_smithy_http::event_stream::Receiver<
   23         -
        crate::model::Events,
          25  +
        crate::sigv4_event_stream::SignedEvent<crate::model::Events>,
          26  +
        crate::sigv4_event_stream::SignedEventError<
   24     27   
            ::aws_smithy_http::event_stream::MessageStreamError,
          28  +
        >,
   25     29   
    > {
   26     30   
        &self.events
   27     31   
    }
   28     32   
}
   29     33   
impl StreamingOperationWithInitialDataInput {
   30     34   
    /// Creates a new builder-style object to manufacture [`StreamingOperationWithInitialDataInput`](crate::input::StreamingOperationWithInitialDataInput).
   31     35   
    pub fn builder() -> crate::input::streaming_operation_with_initial_data_input::Builder {
   32     36   
        crate::input::streaming_operation_with_initial_data_input::Builder::default()
   33     37   
    }
   34     38   
}
   35     39   
impl crate::constrained::Constrained for crate::input::StreamingOperationWithInitialDataInput {
   36     40   
    type Unconstrained = crate::input::streaming_operation_with_initial_data_input::Builder;
   37     41   
}
   38     42   
   39     43   
#[allow(missing_docs)] // documentation missing in model
   40     44   
#[derive(::std::fmt::Debug)]
   41     45   
pub struct StreamingOperationInput {
   42     46   
    #[allow(missing_docs)] // documentation missing in model
   43     47   
    pub events: ::aws_smithy_http::event_stream::Receiver<
   44         -
        crate::model::Events,
          48  +
        crate::sigv4_event_stream::SignedEvent<crate::model::Events>,
          49  +
        crate::sigv4_event_stream::SignedEventError<
   45     50   
            ::aws_smithy_http::event_stream::MessageStreamError,
   46     51   
        >,
          52  +
    >,
   47     53   
}
   48     54   
impl StreamingOperationInput {
   49     55   
    #[allow(missing_docs)] // documentation missing in model
   50     56   
    pub fn events(
   51     57   
        &self,
   52     58   
    ) -> &::aws_smithy_http::event_stream::Receiver<
   53         -
        crate::model::Events,
          59  +
        crate::sigv4_event_stream::SignedEvent<crate::model::Events>,
          60  +
        crate::sigv4_event_stream::SignedEventError<
   54     61   
            ::aws_smithy_http::event_stream::MessageStreamError,
          62  +
        >,
   55     63   
    > {
   56     64   
        &self.events
   57     65   
    }
   58     66   
}
   59     67   
impl StreamingOperationInput {
   60     68   
    /// Creates a new builder-style object to manufacture [`StreamingOperationInput`](crate::input::StreamingOperationInput).
   61     69   
    pub fn builder() -> crate::input::streaming_operation_input::Builder {
   62     70   
        crate::input::streaming_operation_input::Builder::default()
   63     71   
    }
   64     72   
}
@@ -567,575 +665,679 @@
  587    595   
        fn try_from(builder: Builder) -> ::std::result::Result<Self, Self::Error> {
  588    596   
            builder.build()
  589    597   
        }
  590    598   
    }
  591    599   
    /// A builder for [`StreamingOperationWithInitialDataInput`](crate::input::StreamingOperationWithInitialDataInput).
  592    600   
    #[derive(::std::default::Default, ::std::fmt::Debug)]
  593    601   
    pub struct Builder {
  594    602   
        pub(crate) initial_data: ::std::option::Option<::std::string::String>,
  595    603   
        pub(crate) events: ::std::option::Option<
  596    604   
            ::aws_smithy_http::event_stream::Receiver<
  597         -
                crate::model::Events,
         605  +
                crate::sigv4_event_stream::SignedEvent<crate::model::Events>,
         606  +
                crate::sigv4_event_stream::SignedEventError<
  598    607   
                    ::aws_smithy_http::event_stream::MessageStreamError,
  599    608   
                >,
  600    609   
            >,
         610  +
        >,
  601    611   
    }
  602    612   
    impl Builder {
  603    613   
        #[allow(missing_docs)] // documentation missing in model
  604    614   
        pub fn initial_data(mut self, input: ::std::string::String) -> Self {
  605    615   
            self.initial_data = Some(input);
  606    616   
            self
  607    617   
        }
  608    618   
        #[allow(missing_docs)] // documentation missing in model
  609    619   
        pub(crate) fn set_initial_data(
  610    620   
            mut self,
  611    621   
            input: impl ::std::convert::Into<::std::string::String>,
  612    622   
        ) -> Self {
  613    623   
            self.initial_data = Some(input.into());
  614    624   
            self
  615    625   
        }
  616    626   
        #[allow(missing_docs)] // documentation missing in model
  617    627   
        pub fn events(
  618    628   
            mut self,
  619    629   
            input: ::aws_smithy_http::event_stream::Receiver<
  620         -
                crate::model::Events,
         630  +
                crate::sigv4_event_stream::SignedEvent<crate::model::Events>,
         631  +
                crate::sigv4_event_stream::SignedEventError<
  621    632   
                    ::aws_smithy_http::event_stream::MessageStreamError,
  622    633   
                >,
         634  +
            >,
  623    635   
        ) -> Self {
  624    636   
            self.events = Some(input);
  625    637   
            self
  626    638   
        }
  627    639   
        #[allow(missing_docs)] // documentation missing in model
  628    640   
        pub(crate) fn set_events(
  629    641   
            mut self,
  630    642   
            input: impl ::std::convert::Into<
  631    643   
                ::aws_smithy_http::event_stream::Receiver<
  632         -
                    crate::model::Events,
         644  +
                    crate::sigv4_event_stream::SignedEvent<crate::model::Events>,
         645  +
                    crate::sigv4_event_stream::SignedEventError<
  633    646   
                        ::aws_smithy_http::event_stream::MessageStreamError,
  634    647   
                    >,
  635    648   
                >,
         649  +
            >,
  636    650   
        ) -> Self {
  637    651   
            self.events = Some(input.into());
  638    652   
            self
  639    653   
        }
  640    654   
        /// Consumes the builder and constructs a [`StreamingOperationWithInitialDataInput`](crate::input::StreamingOperationWithInitialDataInput).
  641    655   
        ///
  642    656   
        /// The builder fails to construct a [`StreamingOperationWithInitialDataInput`](crate::input::StreamingOperationWithInitialDataInput) if a [`ConstraintViolation`] occurs.
  643    657   
        ///
  644    658   
        /// If the builder fails, it will return the _first_ encountered [`ConstraintViolation`].
  645    659   
        pub fn build(
@@ -704,718 +789,809 @@
  724    738   
  725    739   
        fn try_from(builder: Builder) -> ::std::result::Result<Self, Self::Error> {
  726    740   
            builder.build()
  727    741   
        }
  728    742   
    }
  729    743   
    /// A builder for [`StreamingOperationInput`](crate::input::StreamingOperationInput).
  730    744   
    #[derive(::std::default::Default, ::std::fmt::Debug)]
  731    745   
    pub struct Builder {
  732    746   
        pub(crate) events: ::std::option::Option<
  733    747   
            ::aws_smithy_http::event_stream::Receiver<
  734         -
                crate::model::Events,
         748  +
                crate::sigv4_event_stream::SignedEvent<crate::model::Events>,
         749  +
                crate::sigv4_event_stream::SignedEventError<
  735    750   
                    ::aws_smithy_http::event_stream::MessageStreamError,
  736    751   
                >,
  737    752   
            >,
         753  +
        >,
  738    754   
    }
  739    755   
    impl Builder {
  740    756   
        #[allow(missing_docs)] // documentation missing in model
  741    757   
        pub fn events(
  742    758   
            mut self,
  743    759   
            input: ::aws_smithy_http::event_stream::Receiver<
  744         -
                crate::model::Events,
         760  +
                crate::sigv4_event_stream::SignedEvent<crate::model::Events>,
         761  +
                crate::sigv4_event_stream::SignedEventError<
  745    762   
                    ::aws_smithy_http::event_stream::MessageStreamError,
  746    763   
                >,
         764  +
            >,
  747    765   
        ) -> Self {
  748    766   
            self.events = Some(input);
  749    767   
            self
  750    768   
        }
  751    769   
        #[allow(missing_docs)] // documentation missing in model
  752    770   
        pub(crate) fn set_events(
  753    771   
            mut self,
  754    772   
            input: impl ::std::convert::Into<
  755    773   
                ::aws_smithy_http::event_stream::Receiver<
  756         -
                    crate::model::Events,
         774  +
                    crate::sigv4_event_stream::SignedEvent<crate::model::Events>,
         775  +
                    crate::sigv4_event_stream::SignedEventError<
  757    776   
                        ::aws_smithy_http::event_stream::MessageStreamError,
  758    777   
                    >,
  759    778   
                >,
         779  +
            >,
  760    780   
        ) -> Self {
  761    781   
            self.events = Some(input.into());
  762    782   
            self
  763    783   
        }
  764    784   
        /// Consumes the builder and constructs a [`StreamingOperationInput`](crate::input::StreamingOperationInput).
  765    785   
        ///
  766    786   
        /// The builder fails to construct a [`StreamingOperationInput`](crate::input::StreamingOperationInput) if a [`ConstraintViolation`] occurs.
  767    787   
        ///
  768    788   
        pub fn build(self) -> Result<crate::input::StreamingOperationInput, ConstraintViolation> {
  769    789   
            self.build_enforcing_all_constraints()

tmp-codegen-diff/codegen-server-test/rpcv2Cbor_extras/rust-server-codegen/src/lib.rs

@@ -254,254 +286,288 @@
  274    274   
mod service;
  275    275   
  276    276   
/// Data primitives referenced by other data types.
  277    277   
pub mod types;
  278    278   
  279    279   
/// Unconstrained types for constrained shapes.
  280    280   
mod unconstrained;
  281    281   
  282    282   
mod mimes;
  283    283   
         284  +
mod sigv4_event_stream;
         285  +
  284    286   
mod event_stream_serde;
  285    287   
  286    288   
pub(crate) mod protocol_serde;

tmp-codegen-diff/codegen-server-test/rpcv2Cbor_extras/rust-server-codegen/src/protocol_serde/shape_streaming_operation_input.rs

@@ -1,1 +17,20 @@
    1      1   
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
    2      2   
pub fn de_events_payload(
    3      3   
    body: &mut ::aws_smithy_types::body::SdkBody,
    4      4   
) -> std::result::Result<
    5      5   
    ::aws_smithy_http::event_stream::Receiver<
    6         -
        crate::model::Events,
           6  +
        crate::sigv4_event_stream::SignedEvent<crate::model::Events>,
           7  +
        crate::sigv4_event_stream::SignedEventError<
    7      8   
            ::aws_smithy_http::event_stream::MessageStreamError,
    8      9   
        >,
          10  +
    >,
    9     11   
    ::aws_smithy_cbor::decode::DeserializeError,
   10     12   
> {
   11     13   
    let unmarshaller = crate::event_stream_serde::EventsUnmarshaller::new();
          14  +
    let unmarshaller = crate::sigv4_event_stream::SigV4Unmarshaller::new(unmarshaller);
   12     15   
    let body = std::mem::replace(body, ::aws_smithy_types::body::SdkBody::taken());
   13     16   
    Ok(::aws_smithy_http::event_stream::Receiver::new(
   14     17   
        unmarshaller,
   15     18   
        body,
   16     19   
    ))
   17     20   
}

tmp-codegen-diff/codegen-server-test/rpcv2Cbor_extras/rust-server-codegen/src/protocol_serde/shape_streaming_operation_with_initial_data_input.rs

@@ -1,1 +17,20 @@
    1      1   
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
    2      2   
pub fn de_events_payload(
    3      3   
    body: &mut ::aws_smithy_types::body::SdkBody,
    4      4   
) -> std::result::Result<
    5      5   
    ::aws_smithy_http::event_stream::Receiver<
    6         -
        crate::model::Events,
           6  +
        crate::sigv4_event_stream::SignedEvent<crate::model::Events>,
           7  +
        crate::sigv4_event_stream::SignedEventError<
    7      8   
            ::aws_smithy_http::event_stream::MessageStreamError,
    8      9   
        >,
          10  +
    >,
    9     11   
    ::aws_smithy_cbor::decode::DeserializeError,
   10     12   
> {
   11     13   
    let unmarshaller = crate::event_stream_serde::EventsUnmarshaller::new();
          14  +
    let unmarshaller = crate::sigv4_event_stream::SigV4Unmarshaller::new(unmarshaller);
   12     15   
    let body = std::mem::replace(body, ::aws_smithy_types::body::SdkBody::taken());
   13     16   
    Ok(::aws_smithy_http::event_stream::Receiver::new(
   14     17   
        unmarshaller,
   15     18   
        body,
   16     19   
    ))
   17     20   
}

tmp-codegen-diff/codegen-server-test/rpcv2Cbor_extras/rust-server-codegen/src/sigv4_event_stream.rs

@@ -0,1 +0,195 @@
           1  +
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
           2  +
/// Wrapper for event stream messages that may be signed
           3  +
#[derive(Debug)]
           4  +
pub struct SignedEvent<T> {
           5  +
    /// The actual event message
           6  +
    pub message: T,
           7  +
    /// Signature information if the message was signed
           8  +
    pub signature: ::std::option::Option<crate::sigv4_event_stream::SignatureInfo>,
           9  +
}
          10  +
          11  +
/// Error wrapper for signed event stream errors
          12  +
#[derive(Debug)]
          13  +
pub enum SignedEventError<E> {
          14  +
    /// Error from the underlying event stream
          15  +
    Event(E),
          16  +
    /// Error extracting signed message
          17  +
    InvalidSignedEvent(crate::sigv4_event_stream::ExtractionError),
          18  +
}
          19  +
          20  +
impl<E> From<E> for SignedEventError<E> {
          21  +
    fn from(err: E) -> Self {
          22  +
        SignedEventError::Event(err)
          23  +
    }
          24  +
}
          25  +
          26  +
/// Information extracted from a signed event stream message
          27  +
#[non_exhaustive]
          28  +
#[derive(Debug, Clone)]
          29  +
pub struct SignatureInfo {
          30  +
    /// The chunk signature bytes from the `:chunk-signature` header
          31  +
    pub chunk_signature: Vec<u8>,
          32  +
    /// The timestamp from the `:date` header
          33  +
    pub timestamp: ::std::time::SystemTime,
          34  +
}
          35  +
          36  +
/// Error type for signed message extraction operations
          37  +
#[non_exhaustive]
          38  +
#[derive(Debug)]
          39  +
pub enum ExtractionError {
          40  +
    /// The payload could not be decoded as a valid message
          41  +
    #[non_exhaustive]
          42  +
    InvalidPayload {
          43  +
        error: ::aws_smithy_eventstream::error::Error,
          44  +
    },
          45  +
    /// The timestamp header is missing or has an invalid format
          46  +
    #[non_exhaustive]
          47  +
    InvalidTimestamp,
          48  +
}
          49  +
          50  +
/// Unmarshaller wrapper that handles SigV4 signed event stream messages
          51  +
#[derive(Debug)]
          52  +
pub struct SigV4Unmarshaller<T> {
          53  +
    inner: T,
          54  +
}
          55  +
          56  +
impl<T> SigV4Unmarshaller<T> {
          57  +
    pub fn new(inner: T) -> Self {
          58  +
        Self { inner }
          59  +
    }
          60  +
}
          61  +
          62  +
impl<T> ::aws_smithy_eventstream::frame::UnmarshallMessage for SigV4Unmarshaller<T>
          63  +
where
          64  +
    T: ::aws_smithy_eventstream::frame::UnmarshallMessage,
          65  +
{
          66  +
    type Output = crate::sigv4_event_stream::SignedEvent<T::Output>;
          67  +
    type Error = crate::sigv4_event_stream::SignedEventError<T::Error>;
          68  +
          69  +
    fn unmarshall(
          70  +
        &self,
          71  +
        message: &::aws_smithy_types::event_stream::Message,
          72  +
    ) -> ::std::result::Result<
          73  +
        ::aws_smithy_eventstream::frame::UnmarshalledMessage<Self::Output, Self::Error>,
          74  +
        ::aws_smithy_eventstream::error::Error,
          75  +
    > {
          76  +
        // First, try to extract the signed message
          77  +
        match crate::sigv4_event_stream::extract_signed_message(message) {
          78  +
            Ok(MaybeSignedMessage::Signed {
          79  +
                message: inner_message,
          80  +
                signature,
          81  +
            }) => {
          82  +
                // Process the inner message with the base unmarshaller
          83  +
                match self.inner.unmarshall(&inner_message) {
          84  +
                    Ok(unmarshalled) => match unmarshalled {
          85  +
                        ::aws_smithy_eventstream::frame::UnmarshalledMessage::Event(event) => {
          86  +
                            Ok(::aws_smithy_eventstream::frame::UnmarshalledMessage::Event(
          87  +
                                crate::sigv4_event_stream::SignedEvent {
          88  +
                                    message: event,
          89  +
                                    signature: Some(signature),
          90  +
                                },
          91  +
                            ))
          92  +
                        }
          93  +
                        ::aws_smithy_eventstream::frame::UnmarshalledMessage::Error(err) => {
          94  +
                            Ok(::aws_smithy_eventstream::frame::UnmarshalledMessage::Error(
          95  +
                                crate::sigv4_event_stream::SignedEventError::Event(err),
          96  +
                            ))
          97  +
                        }
          98  +
                    },
          99  +
                    Err(err) => Err(err),
         100  +
                }
         101  +
            }
         102  +
            Ok(MaybeSignedMessage::Unsigned) => {
         103  +
                // Process unsigned message directly
         104  +
                match self.inner.unmarshall(message) {
         105  +
                    Ok(unmarshalled) => match unmarshalled {
         106  +
                        ::aws_smithy_eventstream::frame::UnmarshalledMessage::Event(event) => {
         107  +
                            Ok(::aws_smithy_eventstream::frame::UnmarshalledMessage::Event(
         108  +
                                crate::sigv4_event_stream::SignedEvent {
         109  +
                                    message: event,
         110  +
                                    signature: None,
         111  +
                                },
         112  +
                            ))
         113  +
                        }
         114  +
                        ::aws_smithy_eventstream::frame::UnmarshalledMessage::Error(err) => {
         115  +
                            Ok(::aws_smithy_eventstream::frame::UnmarshalledMessage::Error(
         116  +
                                crate::sigv4_event_stream::SignedEventError::Event(err),
         117  +
                            ))
         118  +
                        }
         119  +
                    },
         120  +
                    Err(err) => Err(err),
         121  +
                }
         122  +
            }
         123  +
            Err(extraction_err) => Ok(::aws_smithy_eventstream::frame::UnmarshalledMessage::Error(
         124  +
                crate::sigv4_event_stream::SignedEventError::InvalidSignedEvent(extraction_err),
         125  +
            )),
         126  +
        }
         127  +
    }
         128  +
}
         129  +
         130  +
/// Result of extracting a potentially signed message
         131  +
#[derive(Debug)]
         132  +
pub enum MaybeSignedMessage {
         133  +
    /// Message was signed and has been extracted
         134  +
    Signed {
         135  +
        /// The inner message that was signed
         136  +
        message: ::aws_smithy_types::event_stream::Message,
         137  +
        /// Signature information from the outer message
         138  +
        signature: crate::sigv4_event_stream::SignatureInfo,
         139  +
    },
         140  +
    /// Message was not signed (no `:chunk-signature` header present)
         141  +
    Unsigned,
         142  +
}
         143  +
         144  +
/// Extracts the inner message from a potentially signed event stream message.
         145  +
pub fn extract_signed_message(
         146  +
    message: &::aws_smithy_types::event_stream::Message,
         147  +
) -> ::std::result::Result<MaybeSignedMessage, crate::sigv4_event_stream::ExtractionError> {
         148  +
    // Check if message has chunk signature
         149  +
    let mut chunk_signature = None;
         150  +
    let mut timestamp = None;
         151  +
         152  +
    for header in message.headers() {
         153  +
        match header.name().as_str() {
         154  +
            ":chunk-signature" => {
         155  +
                if let ::aws_smithy_types::event_stream::HeaderValue::ByteArray(bytes) =
         156  +
                    header.value()
         157  +
                {
         158  +
                    chunk_signature = Some(bytes.as_ref().to_vec());
         159  +
                }
         160  +
            }
         161  +
            ":date" => {
         162  +
                if let ::aws_smithy_types::event_stream::HeaderValue::Timestamp(ts) = header.value()
         163  +
                {
         164  +
                    timestamp = Some(::std::time::SystemTime::try_from(*ts).map_err(|_err| {
         165  +
                        crate::sigv4_event_stream::ExtractionError::InvalidTimestamp
         166  +
                    })?);
         167  +
                } else {
         168  +
                    return Err(crate::sigv4_event_stream::ExtractionError::InvalidTimestamp);
         169  +
                }
         170  +
            }
         171  +
            _ => {}
         172  +
        }
         173  +
    }
         174  +
         175  +
    let Some(chunk_signature) = chunk_signature else {
         176  +
        return Ok(MaybeSignedMessage::Unsigned);
         177  +
    };
         178  +
         179  +
    let Some(timestamp) = timestamp else {
         180  +
        return Err(crate::sigv4_event_stream::ExtractionError::InvalidTimestamp);
         181  +
    };
         182  +
         183  +
    // Extract inner message
         184  +
    let cursor = ::std::io::Cursor::new(message.payload());
         185  +
    let inner_message = ::aws_smithy_eventstream::frame::read_message_from(cursor)
         186  +
        .map_err(|err| crate::sigv4_event_stream::ExtractionError::InvalidPayload { error: err })?;
         187  +
         188  +
    Ok(MaybeSignedMessage::Signed {
         189  +
        message: inner_message,
         190  +
        signature: crate::sigv4_event_stream::SignatureInfo {
         191  +
            chunk_signature,
         192  +
            timestamp,
         193  +
        },
         194  +
    })
         195  +
}