Skip to content

Commit f8aca1c

Browse files
committed
Small codegen fixes for SigV4 EventStreams
1 parent 80e9ab4 commit f8aca1c

2 files changed

Lines changed: 26 additions & 8 deletions

File tree

codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/SigV4EventStreamDecorator.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package software.amazon.smithy.rust.codegen.server.smithy.customizations
77

8+
import software.amazon.smithy.aws.traits.auth.SigV4ATrait
89
import software.amazon.smithy.aws.traits.auth.SigV4Trait
910
import software.amazon.smithy.codegen.core.Symbol
1011
import software.amazon.smithy.model.knowledge.ServiceIndex
@@ -50,8 +51,10 @@ class SigV4EventStreamDecorator : ServerCodegenDecorator {
5051
}
5152
}
5253

53-
internal fun RustSymbolProvider.usesSigAuth(): Boolean =
54-
ServiceIndex.of(model).getAuthSchemes(moduleProviderContext.serviceShape!!).containsKey(SigV4Trait.ID)
54+
internal fun RustSymbolProvider.usesSigAuth(): Boolean {
55+
val authSchemes = ServiceIndex.of(model).getAuthSchemes(moduleProviderContext.serviceShape!!)
56+
return authSchemes.containsKey(SigV4Trait.ID) || authSchemes.containsKey(SigV4ATrait.ID)
57+
}
5558

5659
// Goes from `T` to `SignedEvent<T>`
5760
fun wrapInSignedEvent(

codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/SigV4EventStreamSupportStructures.kt

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.RustType
1212
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
1313
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig
1414
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType
15+
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.preludeScope
1516
import software.amazon.smithy.rust.codegen.core.smithy.mapRustType
1617
import software.amazon.smithy.rust.codegen.core.smithy.rustType
1718
import software.amazon.smithy.rust.codegen.core.util.PANIC
@@ -77,11 +78,12 @@ object SigV4EventStreamSupportStructures {
7778
##[derive(Debug, Clone)]
7879
pub struct SignatureInfo {
7980
/// The chunk signature bytes from the `:chunk-signature` header
80-
pub chunk_signature: Vec<u8>,
81+
pub chunk_signature: #{Vec}<u8>,
8182
/// The timestamp from the `:date` header
8283
pub timestamp: #{SystemTime},
8384
}
8485
""",
86+
*preludeScope,
8587
"SystemTime" to RuntimeType.std.resolve("time::SystemTime"),
8688
)
8789
}
@@ -116,18 +118,25 @@ object SigV4EventStreamSupportStructures {
116118
##[derive(Debug)]
117119
pub enum SignedEventError<E> {
118120
/// Error from the underlying event stream
119-
Event(E),
121+
Event {
122+
/// The error from the underlying event stream
123+
error: E,
124+
/// Signature information if the message was signed
125+
signature: #{Option}<#{SignatureInfo}>,
126+
},
120127
/// Error extracting signed message
121128
InvalidSignedEvent(#{ExtractionError}),
122129
}
123130
124131
impl<E> From<E> for SignedEventError<E> {
125132
fn from(err: E) -> Self {
126-
SignedEventError::Event(err)
133+
SignedEventError::Event { error: err, signature: None }
127134
}
128135
}
129136
""",
130137
"ExtractionError" to extractionError(runtimeConfig),
138+
"SignatureInfo" to signatureInfo(),
139+
*preludeScope,
131140
)
132141
}
133142

@@ -182,11 +191,14 @@ object SigV4EventStreamSupportStructures {
182191
#{UnmarshalledMessage}::Event(event) => {
183192
Ok(#{UnmarshalledMessage}::Event(#{SignedEvent} {
184193
message: event,
185-
signature: Some(signature),
194+
signature: Some(signature.clone()),
186195
}))
187196
}
188197
#{UnmarshalledMessage}::Error(err) => {
189-
Ok(#{UnmarshalledMessage}::Error(#{SignedEventError}::Event(err)))
198+
Ok(#{UnmarshalledMessage}::Error(#{SignedEventError}::Event {
199+
error: err,
200+
signature: Some(signature),
201+
}))
190202
}
191203
},
192204
Err(err) => Err(err),
@@ -203,7 +215,10 @@ object SigV4EventStreamSupportStructures {
203215
}))
204216
}
205217
#{UnmarshalledMessage}::Error(err) => {
206-
Ok(#{UnmarshalledMessage}::Error(#{SignedEventError}::Event(err)))
218+
Ok(#{UnmarshalledMessage}::Error(#{SignedEventError}::Event {
219+
error: err,
220+
signature: None,
221+
}))
207222
}
208223
},
209224
Err(err) => Err(err),

0 commit comments

Comments
 (0)