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

Add support for parsing IS08601 dates (#94)

parent b6b75a7f
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ class InlineDependency(
        ): InlineDependency {
            // The inline crate is loaded as a dependency on the runtime classpath
            val rustFile = this::class.java.getResource("/inlineable/src/$filename")
            check(rustFile != null)
            check(rustFile != null) { "Rust file $filename was missing from the resource bundle!" }
            return InlineDependency(name, module, additionalDepencies.toList()) { writer ->
                writer.raw(rustFile.readText())
            }
@@ -86,6 +86,7 @@ class InlineDependency(
        fun docJson() = forRustFile("doc_json", "doc_json", "doc_json.rs", CargoDependency.Serde)
        fun instantEpoch() = forRustFile("instant_epoch", "instant_epoch", "instant_epoch.rs", CargoDependency.Serde)
        fun instantHttpDate() = forRustFile("instant_httpdate", "instant_httpdate", "instant_httpdate.rs", CargoDependency.Serde)
        fun instant8601() = forRustFile("instant_8601", "instant_8601", "instant_iso8601.rs", CargoDependency.Serde)

        // Stub config implementation as a placeholder before one can be generated dynamically
        fun config() = forRustFile("config", "config", "config.rs", CargoDependency.Rand)
+1 −0
Original line number Diff line number Diff line
@@ -137,6 +137,7 @@ data class RuntimeType(val name: String?, val dependency: RustDependency?, val n

        val InstantEpoch = RuntimeType("instant_epoch", InlineDependency.instantEpoch(), "crate")
        val InstantHttpDate = RuntimeType("instant_httpdate", InlineDependency.instantHttpDate(), "crate")
        val Instant8601 = RuntimeType("instant_8601", InlineDependency.instant8601(), "crate")
        val Config = RuntimeType("config", InlineDependency.config(), "crate")

        fun forInlineFun(name: String, module: String, func: (RustWriter) -> Unit) = RuntimeType(
+0 −4
Original line number Diff line number Diff line
@@ -364,10 +364,6 @@ class HttpProtocolTestGenerator(
                Action.Request
            ),

            // Timestamp parsing: https://github.com/awslabs/smithy-rs/issues/80
            // FailingTest(AwsJson11, "parses_httpdate_timestamps", Action.Response),
            FailingTest(AwsJson11, "parses_iso8601_timestamps", Action.Response),

            // Document deserialization:
            FailingTest(AwsJson11, "PutAndGetInlineDocumentsInput", Action.Response)
        )
+9 −0
Original line number Diff line number Diff line
@@ -242,6 +242,15 @@ class SerializerBuilder(
            """,
                RuntimeType.InstantHttpDate
            )
        },
        "stdoptionoptioninstant_date_time_deser" to { writer ->
            writer.write("use #T;", RuntimeType.Deserialize)
            writer.rust(
                """
                Ok(Option::<#T::InstantIso8601>::deserialize(_deser)?.map(|i|i.0))
            """,
                RuntimeType.Instant8601
            )
        }

    )
+14 −8
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@
 * SPDX-License-Identifier: Apache-2.0.
 */


// TODO: Generate the config dynamically based on the requirements of the service
use std::sync::Mutex;

@@ -40,8 +39,10 @@ fn default_provider() -> impl ProvideIdempotencyToken {
    Mutex::new(rand::thread_rng())
}


impl<T> ProvideIdempotencyToken for Mutex<T> where T: rand::Rng {
impl<T> ProvideIdempotencyToken for Mutex<T>
where
    T: rand::Rng,
{
    fn token(&self) -> String {
        let input: u128 = self.lock().unwrap().gen();
        v4(input)
@@ -56,7 +57,7 @@ impl ProvideIdempotencyToken for &'static str {

pub struct Config {
    #[allow(dead_code)]
    pub(crate) token_provider: Box<dyn ProvideIdempotencyToken>
    pub(crate) token_provider: Box<dyn ProvideIdempotencyToken>,
}

impl Config {
@@ -71,7 +72,7 @@ impl Config {
#[derive(Default)]
pub struct ConfigBuilder {
    #[allow(dead_code)]
    token_provider: Option<Box<dyn ProvideIdempotencyToken>>
    token_provider: Option<Box<dyn ProvideIdempotencyToken>>,
}

impl ConfigBuilder {
@@ -79,14 +80,19 @@ impl ConfigBuilder {
        Self::default()
    }

    pub fn token_provider(mut self, token_provider: impl ProvideIdempotencyToken + 'static) -> Self {
    pub fn token_provider(
        mut self,
        token_provider: impl ProvideIdempotencyToken + 'static,
    ) -> Self {
        self.token_provider = Some(Box::new(token_provider));
        self
    }

    pub fn build(self) -> Config {
        Config {
            token_provider: self.token_provider.unwrap_or_else(|| Box::new(default_provider()))
            token_provider: self
                .token_provider
                .unwrap_or_else(|| Box::new(default_provider())),
        }
    }
}
Loading