-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Server event streams * Rename EventStreamInput to EventStreamSender * Make event stream errors optional * Pokemon service model updated * Pokemon server event handler * Pokemon client to test event streams * EventStreamDecorator to make optional using SigV4 signing Closes: #1157 Signed-off-by: Daniele Ahmed <ahmeddan@amazon.de>
- Loading branch information
Showing
27 changed files
with
544 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
.../main/kotlin/software/amazon/smithy/rust/codegen/smithy/customize/EventStreamDecorator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.rust.codegen.smithy.customize | ||
|
||
import software.amazon.smithy.model.shapes.OperationShape | ||
import software.amazon.smithy.rust.codegen.rustlang.CargoDependency | ||
import software.amazon.smithy.rust.codegen.rustlang.Writable | ||
import software.amazon.smithy.rust.codegen.rustlang.rustTemplate | ||
import software.amazon.smithy.rust.codegen.rustlang.writable | ||
import software.amazon.smithy.rust.codegen.smithy.CodegenContext | ||
import software.amazon.smithy.rust.codegen.smithy.RuntimeConfig | ||
import software.amazon.smithy.rust.codegen.smithy.RuntimeType | ||
import software.amazon.smithy.rust.codegen.smithy.generators.config.ConfigCustomization | ||
import software.amazon.smithy.rust.codegen.smithy.generators.config.ServiceConfig | ||
import software.amazon.smithy.rust.codegen.util.hasEventStreamOperations | ||
|
||
/** | ||
* The EventStreamDecorator: | ||
* - adds a `new_event_stream_signer()` method to `config` to create an Event Stream NoOp signer | ||
* - can be customized by subclassing, see SigV4SigningDecorator | ||
*/ | ||
open class EventStreamDecorator( | ||
private val decorators: List<EventStreamDecorator> | ||
) : RustCodegenDecorator { | ||
override val name: String = "EventStreamDecorator" | ||
override val order: Byte = 0 | ||
|
||
open fun applies(codegenContext: CodegenContext): Boolean = true | ||
|
||
override fun configCustomizations( | ||
codegenContext: CodegenContext, | ||
baseCustomizations: List<ConfigCustomization> | ||
): List<ConfigCustomization> { | ||
decorators.forEach { | ||
if (it.applies(codegenContext)) return it.configCustomizations(codegenContext, baseCustomizations) | ||
} | ||
return baseCustomizations + EventStreamSignConfig( | ||
codegenContext.runtimeConfig, | ||
codegenContext.serviceShape.hasEventStreamOperations(codegenContext.model), | ||
) | ||
} | ||
|
||
override fun operationCustomizations( | ||
codegenContext: CodegenContext, | ||
operation: OperationShape, | ||
baseCustomizations: List<OperationCustomization> | ||
): List<OperationCustomization> { | ||
decorators.forEach { | ||
if (it.applies(codegenContext)) return it.operationCustomizations(codegenContext, operation, baseCustomizations) | ||
} | ||
return baseCustomizations | ||
} | ||
} | ||
|
||
class EventStreamSignConfig( | ||
runtimeConfig: RuntimeConfig, | ||
private val serviceHasEventStream: Boolean, | ||
) : ConfigCustomization() { | ||
private val smithyEventStream = CargoDependency.SmithyEventStream(runtimeConfig) | ||
private val codegenScope = arrayOf( | ||
"NoOpSigner" to RuntimeType("NoOpSigner", smithyEventStream, "aws_smithy_eventstream::frame"), | ||
"SharedPropertyBag" to RuntimeType( | ||
"SharedPropertyBag", | ||
CargoDependency.SmithyHttp(runtimeConfig), | ||
"aws_smithy_http::property_bag" | ||
) | ||
) | ||
|
||
override fun section(section: ServiceConfig): Writable { | ||
return when (section) { | ||
is ServiceConfig.ConfigImpl -> writable { | ||
if (serviceHasEventStream) { | ||
rustTemplate( | ||
""" | ||
/// Creates a new Event Stream `SignMessage` implementor. | ||
pub fn new_event_stream_signer( | ||
&self, | ||
_properties: #{SharedPropertyBag} | ||
) -> #{NoOpSigner} { | ||
#{NoOpSigner}{} | ||
} | ||
""", | ||
*codegenScope | ||
) | ||
} | ||
} | ||
else -> emptySection | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.