Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add server RPC v2 CBOR support #2544

Merged
merged 87 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 82 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
b9016ae
Add RPCv2 support
david-perez Jun 4, 2024
f1b7508
Small fixes
david-perez Jun 4, 2024
e0e0366
Fix e2e tests
david-perez Jun 4, 2024
bf0157a
Merge conflict
david-perez Jun 6, 2024
853eb89
Clear RUSTDOCFLAGS
david-perez Jun 6, 2024
9dc23ab
Merge remote-tracking branch 'upstream/main' into smithy-rpc-v2
david-perez Jun 6, 2024
b7d7d60
Fix CborSerializerGeneratorTest
david-perez Jun 6, 2024
7337901
Add clarifying comment to upgrade.rs
david-perez Jun 10, 2024
ab66015
Fix request `Content-Type` header checking in servers
david-perez Jun 11, 2024
89004f7
ServerProtocolTestGenerator
david-perez Jun 11, 2024
0bc7e23
Address some TODOs
david-perez Jun 13, 2024
ce621fd
save work
david-perez Jun 18, 2024
cf99fd1
Merge remote-tracking branch 'upstream/main' into smithy-rpc-v2
david-perez Jun 19, 2024
04e1838
fix merge conflict, fix Content-Type
david-perez Jun 19, 2024
c1b9741
misc fixes
david-perez Jun 19, 2024
c5f1df5
Trying to make CborSerializerGeneratorTest use the upstream protocol …
david-perez Jun 20, 2024
3ac44d0
Comment in OperationNormalizer
david-perez Jun 20, 2024
e84ce5f
Refactor and DRY up protocol test generation
david-perez Jun 21, 2024
9c1b290
Cherry-pick this over to protocol test improvements branch
david-perez Jun 21, 2024
97db4a4
rename file; going to put protocol test generation in CodegenDecorato…
david-perez Jun 21, 2024
b923bf8
save work
david-perez Jun 24, 2024
975fc67
CborSerializerAndParserGeneratorSerdeRoundTripIntegrationTest finally…
david-perez Jun 24, 2024
010bc1b
CborSerializerAndParserGeneratorSerdeRoundTripIntegrationTest works d…
david-perez Jun 25, 2024
465c86d
Unions with unit variants compile
david-perez Jun 25, 2024
b9b34ec
Unknown union variants
david-perez Jun 25, 2024
4064898
DRY up collection decoding
david-perez Jun 26, 2024
dc8452d
Assert token stream ends
david-perez Jun 26, 2024
6ace376
Add TODO about accepting any body when operation input is empty/non-e…
david-perez Jun 27, 2024
75407f9
Address some TODOs, serialize __type correctly; now going to work on …
david-perez Jun 27, 2024
16ca188
Improve broken protocol test case generation
david-perez Jun 28, 2024
1b6b284
Merge remote-tracking branch 'upstream/main' into smithy-rpc-v2
david-perez Jun 28, 2024
a503606
Fix serialization of __type
david-perez Jun 28, 2024
a8ba4fb
fixes in rpcv2Cbor_extras
david-perez Jul 2, 2024
f37b7f6
Merge remote-tracking branch 'upstream/main' into smithy-rpc-v2
david-perez Jul 2, 2024
8da2298
./gradlew ktlintFormat
david-perez Jul 2, 2024
ed17a10
Remove TODO I don't understand
david-perez Jul 2, 2024
9d2e56a
Adjust error message when bodies don't match in `aws-smithy-protocol-…
david-perez Jul 3, 2024
974f214
Instantiate with dev-dependencies appropriately
david-perez Jul 3, 2024
fecbb11
Specify service shape when loading model explicitly; revert this
david-perez Jul 3, 2024
df55249
Revert "Specify service shape when loading model explicitly; revert t…
david-perez Jul 3, 2024
b0309ad
Do not discover smithy-protocol-tests Smithy models when loading mode…
david-perez Jul 3, 2024
b6ff293
Fix CborSerializerAndParserGeneratorSerdeRoundTripIntegrationTest, we…
david-perez Jul 3, 2024
2be4a16
Misc changes in protocol test generation
david-perez Jul 4, 2024
909f8f1
unfix json_rpc10 test
david-perez Jul 4, 2024
8dc346b
fixes
david-perez Jul 4, 2024
665c8b5
address TODO
david-perez Jul 4, 2024
d75c9ec
address Clippy warnings
david-perez Jul 4, 2024
96c740b
Set aws-smithy-cbor version to 0.60.0
david-perez Jul 4, 2024
83bc91a
fix bug encoding cbor maps
david-perez Jul 4, 2024
65b841a
Failing tests, broken hyperlink
david-perez Jul 4, 2024
72daede
clippy, formatting
david-perez Jul 4, 2024
6853b96
./gradlew ktlintFormat
david-perez Jul 4, 2024
8c65e7a
AWS JSON 1.x server request specs can be `&'static str`s
david-perez Jul 4, 2024
61f927a
AWS JSON 1.x server request specs can be `&'static str`s
david-perez Jul 4, 2024
ec50332
Update cbor-diag to avoid minimal-versions issues
david-perez Jul 5, 2024
46671d1
Add aws-smithy-cbor to smithy runtime, start versioning at 0.60.6
david-perez Jul 5, 2024
a1a823c
Remove sample RPCv2 service
david-perez Jul 5, 2024
bdb5747
fix
david-perez Jul 8, 2024
9f40fa5
fix typo
david-perez Jul 8, 2024
a8de362
Merge branch 'davidpz/aws-json-1x-server-request-specs-can-be-static-…
david-perez Jul 8, 2024
2f89061
RpcV2CborServerPopulatesDefaultsWhenMissingInRequestBody expect fail
david-perez Jul 8, 2024
bc65c63
fix
david-perez Jul 8, 2024
6189878
Merge remote-tracking branch 'upstream/main' into davidpz/aws-json-1x…
david-perez Jul 8, 2024
792c215
bump aws-smithy-http-server
david-perez Jul 8, 2024
a65ab89
Merge branch 'davidpz/aws-json-1x-server-request-specs-can-be-static-…
david-perez Jul 8, 2024
f4ab98b
derive thiserror::Error for RPC v2 runtime errors
david-perez Jul 8, 2024
6c6384e
Add some context to TODOs
david-perez Jul 9, 2024
132f8b4
Address more TODOs
david-perez Jul 9, 2024
c5794c7
Bump crate version numbers
david-perez Jul 10, 2024
3816f7a
Merge remote-tracking branch 'upstream/main' into smithy-rpc-v2
david-perez Jul 10, 2024
e33b6b9
Update .cargo-deny-config.toml
david-perez Jul 10, 2024
6781dca
Add and modify router docs
david-perez Jul 10, 2024
8f14505
Rename RpcV2Router to RpcV2CborRouter
david-perez Jul 10, 2024
a98524b
rpc_v2 module -> rpc_v2_cbor module
david-perez Jul 10, 2024
e36704e
More renaming to be rpcv2Cbor, not rpcv2
david-perez Jul 10, 2024
c5440be
Address last TODO?
david-perez Jul 10, 2024
805c177
fixes
david-perez Jul 10, 2024
af4d992
Merge remote-tracking branch 'upstream/main' into smithy-rpc-v2
david-perez Jul 10, 2024
ccde860
fixes
david-perez Jul 10, 2024
c31356c
fixes
david-perez Jul 10, 2024
48def05
copyright headers and other lint fixes
david-perez Jul 10, 2024
03ba0a8
./gradlew ktlintFormat
david-perez Jul 10, 2024
ce7d830
Address comments
david-perez Jul 16, 2024
ccdbea1
Merge remote-tracking branch 'upstream/main' into smithy-rpc-v2
david-perez Jul 16, 2024
7684ec1
Address comments round 2
david-perez Jul 17, 2024
1bf474d
Bump aws-smithy-protocol-test to 0.62.0
david-perez Jul 17, 2024
d485266
./gradlew ktlintFormat
david-perez Jul 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .cargo-deny-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ exceptions = [
{ allow = ["OpenSSL"], name = "ring", version = "*" },
{ allow = ["OpenSSL"], name = "aws-lc-sys", version = "*" },
{ allow = ["OpenSSL"], name = "aws-lc-fips-sys", version = "*" },
{ allow = ["BlueOak-1.0.0"], name = "minicbor", version = "<=0.24.2" },
# Safe to bump as long as license does not change -------------^
# See D105255799.
]

[[licenses.clarify]]
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ allprojects {
val allowLocalDeps: String by project
repositories {
if (allowLocalDeps.toBoolean()) {
mavenLocal()
mavenLocal()
}
mavenCentral()
google()
Expand Down
41 changes: 40 additions & 1 deletion buildSrc/src/main/kotlin/CodegenTestCommon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,45 @@ fun generateImports(imports: List<String>): String =
"\"imports\": [${imports.map { "\"$it\"" }.joinToString(", ")}],"
}

fun toRustCrateName(input: String): String {
val rustKeywords =
drganjoo marked this conversation as resolved.
Show resolved Hide resolved
setOf(
// Strict Keywords.
"as", "break", "const", "continue", "crate", "else", "enum", "extern",
"false", "fn", "for", "if", "impl", "in", "let", "loop", "match", "mod",
"move", "mut", "pub", "ref", "return", "Self", "self", "static", "struct",
"super", "trait", "true", "type", "unsafe", "use", "where", "while",
// Weak Keywords.
"dyn", "async", "await", "try",
// Reserved for Future Use.
"abstract", "become", "box", "do", "final", "macro", "override", "priv",
"typeof", "unsized", "virtual", "yield",
// Primitive Types.
"bool", "char", "i8", "i16", "i32", "i64", "i128", "isize",
"u8", "u16", "u32", "u64", "u128", "usize", "f32", "f64", "str",
// Additional significant identifiers.
"proc_macro",
)

if (input.isBlank()) {
throw IllegalArgumentException("Rust crate name cannot be empty")
}
val lowerCased = input.lowercase()
// Replace any sequence of characters that are not lowercase letters, numbers, dashes, or underscores with a single underscore.
val sanitized = lowerCased.replace(Regex("[^a-z0-9_-]+"), "_")
// Trim leading or trailing underscores.
val trimmed = sanitized.trim('_')
// Check if the resulting string is empty, purely numeric, or a reserved name
val finalName =
when {
trimmed.isEmpty() -> throw IllegalArgumentException("Rust crate name after sanitizing cannot be empty.")
trimmed.matches(Regex("\\d+")) -> "n$trimmed" // Prepend 'n' if the name is purely numeric.
trimmed in rustKeywords -> "${trimmed}_" // Append an underscore if the name is reserved.
else -> trimmed
}
return finalName
}

private fun generateSmithyBuild(
projectDir: String,
pluginName: String,
Expand All @@ -48,7 +87,7 @@ private fun generateSmithyBuild(
${it.extraCodegenConfig ?: ""}
},
"service": "${it.service}",
"module": "${it.module}",
"module": "${toRustCrateName(it.module)}",
"moduleVersion": "0.0.1",
"moduleDescription": "test",
"moduleAuthors": ["[email protected]"]
Expand Down
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/CrateSet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ object CrateSet {
val SMITHY_RUNTIME_COMMON =
listOf(
"aws-smithy-async",
"aws-smithy-cbor",
"aws-smithy-checksums",
"aws-smithy-compression",
"aws-smithy-client",
Expand Down
3 changes: 2 additions & 1 deletion codegen-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ dependencies {
implementation("software.amazon.smithy:smithy-protocol-test-traits:$smithyVersion")
implementation("software.amazon.smithy:smithy-waiters:$smithyVersion")
implementation("software.amazon.smithy:smithy-rules-engine:$smithyVersion")
implementation("software.amazon.smithy:smithy-protocol-traits:$smithyVersion")

// `smithy.framework#ValidationException` is defined here, which is used in event stream
// marshalling/unmarshalling tests.
// marshalling/unmarshalling tests.
testImplementation("software.amazon.smithy:smithy-validation-model:$smithyVersion")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.error.ErrorC
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
import software.amazon.smithy.rust.codegen.core.smithy.customize.CombinedCoreCodegenDecorator
import software.amazon.smithy.rust.codegen.core.smithy.customize.CoreCodegenDecorator
import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolTestGenerator
import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolMap
import java.util.ServiceLoader
import java.util.logging.Logger
Expand Down Expand Up @@ -93,14 +92,6 @@ interface ClientCodegenDecorator : CoreCodegenDecorator<ClientCodegenContext, Cl
codegenContext: ClientCodegenContext,
baseCustomizations: List<ServiceRuntimePluginCustomization>,
): List<ServiceRuntimePluginCustomization> = baseCustomizations

/**
* Hook to override the protocol test generator
*/
fun protocolTestGenerator(
codegenContext: ClientCodegenContext,
baseGenerator: ProtocolTestGenerator,
): ProtocolTestGenerator = baseGenerator
}

/**
Expand Down Expand Up @@ -176,14 +167,6 @@ open class CombinedClientCodegenDecorator(decorators: List<ClientCodegenDecorato
decorator.serviceRuntimePluginCustomizations(codegenContext, customizations)
}

override fun protocolTestGenerator(
codegenContext: ClientCodegenContext,
baseGenerator: ProtocolTestGenerator,
): ProtocolTestGenerator =
combineCustomizations(baseGenerator) { decorator, gen ->
decorator.protocolTestGenerator(codegenContext, gen)
}

companion object {
fun fromClasspath(
context: PluginContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ class ClientBuilderKindBehavior(val codegenContext: CodegenContext) : Instantiat
override fun doesSetterTakeInOption(memberShape: MemberShape): Boolean = true
}

class ClientInstantiator(private val codegenContext: ClientCodegenContext) : Instantiator(
class ClientInstantiator(private val codegenContext: ClientCodegenContext, withinTest: Boolean = false) : Instantiator(
codegenContext.symbolProvider,
codegenContext.model,
codegenContext.runtimeConfig,
ClientBuilderKindBehavior(codegenContext),
withinTest = false,
) {
fun renderFluentCall(
writer: RustWriter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class ClientProtocolTestGenerator(
get() = AppliesTo.CLIENT
override val expectFail: Set<FailingTest>
get() = ExpectFail
override val runOnly: Set<String>
override val generateOnly: Set<String>
get() = emptySet()
override val disabledTests: Set<String>
get() = emptySet()
Expand All @@ -128,7 +128,7 @@ class ClientProtocolTestGenerator(
private val inputShape = operationShape.inputShape(codegenContext.model)
private val outputShape = operationShape.outputShape(codegenContext.model)

private val instantiator = ClientInstantiator(codegenContext)
private val instantiator = ClientInstantiator(codegenContext, withinTest = true)

private val codegenScope =
arrayOf(
Expand All @@ -149,6 +149,8 @@ class ClientProtocolTestGenerator(
}

private fun RustWriter.renderHttpRequestTestCase(httpRequestTestCase: HttpRequestTestCase) {
logger.info("Generating request test: ${httpRequestTestCase.id}")

if (!protocolSupport.requestSerialization) {
rust("/* test case disabled for this protocol (not yet supported) */")
return
Expand Down Expand Up @@ -234,6 +236,8 @@ class ClientProtocolTestGenerator(
testCase: HttpResponseTestCase,
expectedShape: StructureShape,
) {
logger.info("Generating response test: ${testCase.id}")

if (!protocolSupport.responseDeserialization || (
!protocolSupport.errorDeserialization &&
expectedShape.hasTrait(
Expand Down Expand Up @@ -357,8 +361,8 @@ class ClientProtocolTestGenerator(
if (body == "") {
rustWriter.rustTemplate(
"""
// No body
#{AssertEq}(::std::str::from_utf8(body).unwrap(), "");
// No body.
#{AssertEq}(&body, &bytes::Bytes::new());
""",
*codegenScope,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import software.amazon.smithy.aws.traits.protocols.Ec2QueryTrait
import software.amazon.smithy.aws.traits.protocols.RestJson1Trait
import software.amazon.smithy.aws.traits.protocols.RestXmlTrait
import software.amazon.smithy.model.shapes.ServiceShape
import software.amazon.smithy.protocol.traits.Rpcv2CborTrait
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext
import software.amazon.smithy.rust.codegen.client.smithy.generators.OperationGenerator
import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext
Expand All @@ -28,6 +29,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolLoader
import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolMap
import software.amazon.smithy.rust.codegen.core.smithy.protocols.RestJson
import software.amazon.smithy.rust.codegen.core.smithy.protocols.RestXml
import software.amazon.smithy.rust.codegen.core.smithy.protocols.RpcV2Cbor
import software.amazon.smithy.rust.codegen.core.util.hasTrait

class ClientProtocolLoader(supportedProtocols: ProtocolMap<OperationGenerator, ClientCodegenContext>) :
Expand All @@ -41,6 +43,7 @@ class ClientProtocolLoader(supportedProtocols: ProtocolMap<OperationGenerator, C
Ec2QueryTrait.ID to ClientEc2QueryFactory(),
RestJson1Trait.ID to ClientRestJsonFactory(),
RestXmlTrait.ID to ClientRestXmlFactory(),
Rpcv2CborTrait.ID to ClientRpcV2CborFactory(),
)
val Default = ClientProtocolLoader(DefaultProtocols)
}
Expand Down Expand Up @@ -117,3 +120,12 @@ class ClientRestXmlFactory(

override fun support(): ProtocolSupport = CLIENT_PROTOCOL_SUPPORT
}

class ClientRpcV2CborFactory : ProtocolGeneratorFactory<OperationGenerator, ClientCodegenContext> {
override fun protocol(codegenContext: ClientCodegenContext): Protocol = RpcV2Cbor(codegenContext)

override fun buildProtocolGenerator(codegenContext: ClientCodegenContext): OperationGenerator =
OperationGenerator(codegenContext, protocol(codegenContext))

override fun support(): ProtocolSupport = CLIENT_PROTOCOL_SUPPORT
}
1 change: 1 addition & 0 deletions codegen-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies {
implementation("software.amazon.smithy:smithy-aws-traits:$smithyVersion")
implementation("software.amazon.smithy:smithy-protocol-test-traits:$smithyVersion")
implementation("software.amazon.smithy:smithy-waiters:$smithyVersion")
implementation("software.amazon.smithy:smithy-protocol-traits:$smithyVersion")
}

fun gitCommitHash(): String {
Expand Down
Loading
Loading