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

fix: time not implemented on wasm #2262

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion aws/rust-runtime/aws-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ aws-smithy-json = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-json" }
aws-smithy-types = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-types" }
aws-types = { path = "../../sdk/build/aws-sdk/sdk/aws-types" }
hyper = { version = "0.14.12", default-features = false }
time = { version = "0.3.4", features = ["parsing"] }
time = { version = "0.3.17", features = ["parsing"] }
tokio = { version = "1.8.4", features = ["sync"] }
tracing = { version = "0.1" }

Expand Down
3 changes: 2 additions & 1 deletion aws/rust-runtime/aws-config/src/sts/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use aws_credential_types::provider::{self, error::CredentialsError};
use aws_credential_types::Credentials as AwsCredentials;
use aws_sdk_sts::model::Credentials as StsCredentials;
use aws_smithy_types::date_time;

use std::convert::TryFrom;
use std::time::{SystemTime, UNIX_EPOCH};
Expand Down Expand Up @@ -46,7 +47,7 @@ pub(crate) fn into_credentials(
/// provide a name for the session, the provider will choose a name composed of a base + a timestamp,
/// e.g. `profile-file-provider-123456789`
pub(crate) fn default_session_name(base: &str) -> String {
let now = SystemTime::now()
let now = date_time::now()
.duration_since(UNIX_EPOCH)
.expect("post epoch");
format!("{}-{}", base, now.as_millis())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
//! Lazy, credentials cache implementation

use std::sync::Arc;
use std::time::{Duration, Instant};
use std::time::Duration;

use aws_smithy_async::future::timeout::Timeout;
use aws_smithy_async::rt::sleep::AsyncSleep;
use aws_smithy_types::date_time;
use tracing::{debug, info, info_span, Instrument};

use crate::cache::{ExpiringCache, ProvideCachedCredentials};
Expand Down Expand Up @@ -74,7 +75,7 @@ impl ProvideCachedCredentials for LazyCredentialsCache {
// since the futures are not eagerly executed, and the cache will only run one
// of them.
let future = Timeout::new(provider.provide_credentials(), timeout_future);
let start_time = Instant::now();
let start_time = date_time::now();
let result = cache
.get_or_load(|| {
let span = info_span!("lazy_load_credentials");
Expand Down
3 changes: 2 additions & 1 deletion aws/rust-runtime/aws-credential-types/src/time_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

use aws_smithy_types::date_time;
use std::ops::Deref;
use std::sync::{Arc, Mutex};
use std::time::{Duration, SystemTime};
Expand Down Expand Up @@ -39,7 +40,7 @@ impl TimeSource {
/// Returns the current system time based on the mode.
pub fn now(&self) -> SystemTime {
match &self.0 {
Inner::Default => SystemTime::now(),
Inner::Default => date_time::now(),
Inner::Testing(testing) => testing.now(),
}
}
Expand Down
3 changes: 2 additions & 1 deletion aws/rust-runtime/aws-inlineable/src/presigning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/// Presigning config and builder
pub mod config {
use aws_smithy_types::date_time;
use std::fmt;
use std::time::{Duration, SystemTime};

Expand Down Expand Up @@ -149,7 +150,7 @@ pub mod config {
return Err(ErrorKind::ExpiresInDurationTooLong.into());
}
Ok(PresigningConfig {
start_time: self.start_time.unwrap_or_else(SystemTime::now),
start_time: self.start_time.unwrap_or_else(date_time::now),
expires_in,
})
}
Expand Down
1 change: 1 addition & 0 deletions aws/rust-runtime/aws-sig-auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ aws-credential-types = { path = "../aws-credential-types" }
aws-sigv4 = { path = "../aws-sigv4" }
aws-smithy-eventstream = { path = "../../../rust-runtime/aws-smithy-eventstream", optional = true }
aws-smithy-http = { path = "../../../rust-runtime/aws-smithy-http" }
aws-smithy-types = { path = "../../../rust-runtime/aws-smithy-types" }
aws-types = { path = "../aws-types" }
http = "0.2.2"
tracing = "0.1"
Expand Down
3 changes: 2 additions & 1 deletion aws/rust-runtime/aws-sig-auth/src/event_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use aws_sigv4::event_stream::{sign_empty_message, sign_message};
use aws_sigv4::SigningParams;
use aws_smithy_eventstream::frame::{Message, SignMessage, SignMessageError};
use aws_smithy_http::property_bag::{PropertyBag, SharedPropertyBag};
use aws_smithy_types::date_time;
use aws_types::region::SigningRegion;
use aws_types::SigningService;
use std::time::SystemTime;
Expand Down Expand Up @@ -37,7 +38,7 @@ impl SigV4Signer {
let time = properties
.get::<SystemTime>()
.copied()
.unwrap_or_else(SystemTime::now);
.unwrap_or_else(date_time::now);
let mut builder = SigningParams::builder()
.access_key(credentials.access_key_id())
.secret_key(credentials.secret_access_key())
Expand Down
3 changes: 2 additions & 1 deletion aws/rust-runtime/aws-sig-auth/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::time::SystemTime;
use aws_smithy_http::middleware::MapRequest;
use aws_smithy_http::operation::Request;
use aws_smithy_http::property_bag::PropertyBag;
use aws_smithy_types::date_time;

use aws_credential_types::Credentials;
use aws_sigv4::http_request::SignableBody;
Expand Down Expand Up @@ -147,7 +148,7 @@ fn signing_config(
request_ts: config
.get::<SystemTime>()
.copied()
.unwrap_or_else(SystemTime::now),
.unwrap_or_else(date_time::now),
region,
payload_override,
service: signing_service,
Expand Down
4 changes: 2 additions & 2 deletions aws/rust-runtime/aws-sigv4/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ http = { version = "0.2", optional = true }
once_cell = "1.8"
percent-encoding = { version = "2.1", optional = true }
regex = "1.5"
time = "0.3.5"
time = "0.3.17"
tracing = "0.1"
hmac = "0.12"
sha2 = "0.10"
Expand All @@ -34,7 +34,7 @@ bytes = "1"
httparse = "1.5"
pretty_assertions = "1.0"
proptest = "1"
time = { version = "0.3.4", features = ["parsing"] }
time = { version = "0.3.17", features = ["parsing"] }

[target.'cfg(not(any(target_arch = "powerpc", target_arch = "powerpc64")))'.dev-dependencies]
ring = "0.16"
Expand Down
2 changes: 1 addition & 1 deletion rust-runtime/aws-smithy-types-convert/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ convert-time = ["aws-smithy-types", "time"]
[dependencies]
aws-smithy-types = { path = "../aws-smithy-types", optional = true }
chrono = { version = "0.4.19", optional = true, default-features = false, features = ["std"] }
time = { version = "0.3.4", optional = true }
time = { version = "0.3.17", optional = true }

[package.metadata.docs.rs]
all-features = true
Expand Down
2 changes: 1 addition & 1 deletion rust-runtime/aws-smithy-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repository = "https://github.com/awslabs/smithy-rs"
itoa = "1.0.0"
num-integer = "0.1.44"
ryu = "1.0.5"
time = { version = "0.3.4", features = ["parsing"] }
time = { version = "0.3.17", features = ["parsing", "wasm-bindgen"] }
base64-simd = "0.7"

[dev-dependencies]
Expand Down
12 changes: 12 additions & 0 deletions rust-runtime/aws-smithy-types/src/date_time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::fmt;
use std::time::Duration;
use std::time::SystemTime;
use std::time::UNIX_EPOCH;
use time::OffsetDateTime;

mod format;
pub use self::format::DateTimeFormatError;
Expand All @@ -26,6 +27,17 @@ const NANOS_PER_SECOND_U32: u32 = 1_000_000_000;

/* ANCHOR: date_time */

// A std::time replacement that works on WASM as well .
#[doc(hidden)]
pub fn now_utc() -> OffsetDateTime {
OffsetDateTime::now_utc()
}

#[doc(hidden)]
pub fn now() -> SystemTime {
OffsetDateTime::now_utc().into()
}

/// DateTime in time.
///
/// DateTime in time represented as seconds and sub-second nanos since
Expand Down