Unverified Commit e79ccb14 authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Support Idempotency Token (#91)

This commit adds support for the idempotency token trait via a config. I'm not ready to build a generalized Config generator yet, so intead I'm injecting a static config via inlinable. A follow up diff will flesh out ServiceConfigGenerator to support adding more config sections as required by AWS.
parent 26ff8021
Loading
Loading
Loading
Loading
+67 −1
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ name = "dynamo"
version = "0.0.1"
dependencies = [
 "http",
 "rand",
 "serde",
 "serde_json",
 "smithy-http",
@@ -98,6 +99,7 @@ version = "0.1.0"
dependencies = [
 "dynamo",
 "io-v0",
 "rand",
 "smithy-types",
 "tokio",
]
@@ -169,6 +171,17 @@ dependencies = [
 "pin-utils",
]

[[package]]
name = "getrandom"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6"
dependencies = [
 "cfg-if 0.1.10",
 "libc",
 "wasi 0.9.0+wasi-snapshot-preview1",
]

[[package]]
name = "h2"
version = "0.2.7"
@@ -541,6 +554,12 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"

[[package]]
name = "ppv-lite86"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"

[[package]]
name = "proc-macro2"
version = "1.0.24"
@@ -559,6 +578,47 @@ dependencies = [
 "proc-macro2",
]

[[package]]
name = "rand"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
dependencies = [
 "getrandom",
 "libc",
 "rand_chacha",
 "rand_core",
 "rand_hc",
]

[[package]]
name = "rand_chacha"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
dependencies = [
 "ppv-lite86",
 "rand_core",
]

[[package]]
name = "rand_core"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
dependencies = [
 "getrandom",
]

[[package]]
name = "rand_hc"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
dependencies = [
 "rand_core",
]

[[package]]
name = "redox_syscall"
version = "0.1.57"
@@ -695,7 +755,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [
 "libc",
 "wasi",
 "wasi 0.10.0+wasi-snapshot-preview1",
 "winapi 0.3.9",
]

@@ -995,6 +1055,12 @@ dependencies = [
 "try-lock",
]

[[package]]
name = "wasi"
version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"

[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
+1 −0
Original line number Diff line number Diff line
@@ -11,3 +11,4 @@ smithy-types = { path = "../../rust-runtime/smithy-types" }
dynamo = { version = "0.0.1", path = "../build/smithyprojections/codegen-test/dynamo/rust-codegen/"}
io-v0 = { path = "../../rust-runtime/io-v0" }
tokio = { version = "0.2", features = ["full"] }
rand  = "0.7.3"
+9 −7
Original line number Diff line number Diff line
@@ -3,24 +3,26 @@
 * SPDX-License-Identifier: Apache-2.0.
 */

use dynamo::model::{AttributeDefinition, KeySchemaElement, KeyType, ScalarAttributeType, ProvisionedThroughput};
use dynamo::operation::CreateTable;
use dynamo::output::{ListTablesOutput };
use std::error::Error;

use dynamo::model::{AttributeDefinition, KeySchemaElement, KeyType, ProvisionedThroughput, ScalarAttributeType};
use dynamo::operation::CreateTable;
use dynamo::output::ListTablesOutput;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let table_name = "new_table";
    let client = io_v0::Client::local("dynamodb");
    let config = dynamo::Config::from_env();
    let clear_table = dynamo::operation::DeleteTable::builder()
        .table_name(table_name)
        .build();
        .build(&config);
    match io_v0::dispatch!(client, clear_table).parsed() {
        Ok(table_deleted) => println!("{:?} table was deleted", table_deleted),
        Err(e) => println!("dispatch error: {:?}", e),
    }

    let tables = io_v0::dispatch!(client, dynamo::operation::ListTables::builder().build()).parsed.unwrap();
    let tables = io_v0::dispatch!(client, dynamo::operation::ListTables::builder().build(&config)).parsed.unwrap();
    assert_eq!(
        tables.unwrap(),
        ListTablesOutput::builder().table_names(vec![]).build()
@@ -37,7 +39,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
            .key_type(KeyType::from("HASH"))
            .build()])
        .provisioned_throughput(ProvisionedThroughput::builder().read_capacity_units(100).write_capacity_units(100).build())
        .build();
        .build(&config);

    let response = io_v0::dispatch!(client, create_table);
    match response.parsed {
@@ -45,7 +47,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
        _ => println!("{:?}", response.raw)
    }

    let tables = io_v0::dispatch!(client, dynamo::operation::ListTables::builder().build()).parsed.unwrap();
    let tables = io_v0::dispatch!(client, dynamo::operation::ListTables::builder().build(&config)).parsed.unwrap();
    assert_eq!(
        tables.unwrap(),
        ListTablesOutput::builder().table_names(vec![table_name.to_string()]).build()
+4 −0
Original line number Diff line number Diff line
@@ -84,6 +84,9 @@ class InlineDependency(
        fun genericError() = forRustFile("GenericError", "types", "generic_error.rs", CargoDependency.Serde)
        fun errorCode() = forRustFile("error_code", "error_code", "error_code.rs", CargoDependency.Http)
        fun docJson() = forRustFile("doc_json", "doc_json", "doc_json.rs", CargoDependency.Serde)

        // Stub config implementation as a placeholder before one can be generated dynamically
        fun config() = forRustFile("config", "config", "config.rs", CargoDependency.Rand)
    }
}

@@ -143,6 +146,7 @@ data class CargoDependency(
    }

    companion object {
        val Rand: CargoDependency = CargoDependency("rand", CratesIo("0.7"))
        val Http: CargoDependency = CargoDependency("http", CratesIo("0.2"))
        fun SmithyTypes(runtimeConfig: RuntimeConfig) =
            CargoDependency("${runtimeConfig.cratePrefix}-types", Local(runtimeConfig.relativePath))
+3 −2
Original line number Diff line number Diff line
@@ -153,8 +153,9 @@ fun CodeWriter.escape(text: String): String = text.replace("$expressionStart", "
 */
fun CodeWriter.raw(text: String) = writeInline(escape(text))

class
RustWriter private constructor(
typealias Writable = RustWriter.() -> Unit

class RustWriter private constructor(
    private val filename: String,
    val namespace: String,
    private val commentCharacter: String = "//",
Loading