Unverified Commit 72eae556 authored by John DiSanti's avatar John DiSanti Committed by GitHub
Browse files

Relegate `chrono` to an optional feature in a new conversion crate (#849)

* Refactor Instant to use `time` instead of `chrono`
* Rename methods on Instant to have a consistent naming scheme.
* Remove built-in Instant conversions.
* Remove `chrono` from `aws-sigv4`
* Re-export `Instant` from service crates
* Implement `aws-smithy-types-convert`
* Rename `Instant` to `DateTime`
* Make date-time formatting operations fallible
* Add initial changelog entries
* Update changelog
* Make DateTime to SystemTime conversion fallible
* Incorporate review feedback
* Fix merge issues
* Fix examples
* Fix doc comments
* Fix unused import warning when using `convert-chrono` feature exclusively
parent 3ae9bcf7
Loading
Loading
Loading
Loading
+53 −0
Original line number Diff line number Diff line
vNext (Month Day, Year)
=======================

**TODO Next Release:**
- Update README & aws-sdk-rust CI for MSRV upgrade to 1.54

**Breaking Changes**

Several breaking changes around `aws_smithy_types::Instant` were introduced by smithy-rs#849:
- `aws_smithy_types::Instant` from was renamed to `DateTime` to avoid confusion with the standard library's monotonically nondecreasing `Instant` type.
- `DateParseError` in `aws_smithy_types` has been renamed to `DateTimeParseError` to match the type that's being parsed.
- The `chrono-conversions` feature and associated functions have been moved to the `aws-smithy-types-convert` crate.
  - Calls to `Instant::from_chrono` should be changed to:
    ```rust
    use aws_smithy_types::DateTime;
    use aws_smithy_types_convert::date_time::DateTimeExt;

    // For chrono::DateTime<Utc>
    let date_time = DateTime::from_chrono_utc(chrono_date_time);
    // For chrono::DateTime<FixedOffset>
    let date_time = DateTime::from_chrono_offset(chrono_date_time);
    ```
  - Calls to `instant.to_chrono()` should be changed to:
    ```rust
    use aws_smithy_types_convert::date_time::DateTimeExt;

    date_time.to_chrono_utc();
    ```
- `Instant::from_system_time` and `Instant::to_system_time` have been changed to `From` trait implementations.
  - Calls to `from_system_time` should be changed to:
    ```rust
    DateTime::from(system_time);
    // or
    let date_time: DateTime = system_time.into();
    ```
  - Calls to `to_system_time` should be changed to:
    ```rust
    SystemTime::from(date_time);
    // or
    let system_time: SystemTime = date_time.into();
    ```
- Several functions in `Instant`/`DateTime` were renamed:
  - `Instant::from_f64` -> `DateTime::from_secs_f64`
  - `Instant::from_fractional_seconds` -> `DateTime::from_fractional_secs`
  - `Instant::from_epoch_seconds` -> `DateTime::from_secs`
  - `Instant::from_epoch_millis` -> `DateTime::from_millis`
  - `Instant::epoch_fractional_seconds` -> `DateTime::as_secs_f64`
  - `Instant::has_nanos` -> `DateTime::has_subsec_nanos`
  - `Instant::epoch_seconds` -> `DateTime::secs`
  - `Instant::epoch_subsecond_nanos` -> `DateTime::subsec_nanos`
  - `Instant::to_epoch_millis` -> `DateTime::to_millis`
- The `DateTime::fmt` method is now fallible and fails when a `DateTime`'s value is outside what can be represented by the desired date format.
- In `aws-sigv4`, the `SigningParams` builder's `date_time` setter was renamed to `time` and changed to take a `std::time::SystemTime` instead of a chrono's `DateTime<Utc>`.

**New this week**
- Conversions from `aws_smithy_types::DateTime` to `OffsetDateTime` from the `time` crate are now available from the `aws-smithy-types-convert` crate. (smithy-rs#849)

v0.28.0-alpha (November 11th, 2021)
===================================

+50 −0
Original line number Diff line number Diff line
@@ -2,6 +2,56 @@ vNext (Month Day, Year)
=======================
- Update README & aws-sdk-rust CI for MSRV upgrade to 1.54

**Breaking Changes**

Several breaking changes around `aws_smithy_types::Instant` were introduced by smithy-rs#849:
- `aws_smithy_types::Instant` from was renamed to `DateTime` to avoid confusion with the standard library's monotonically nondecreasing `Instant` type.
- `DateParseError` in `aws_smithy_types` has been renamed to `DateTimeParseError` to match the type that's being parsed.
- The `chrono-conversions` feature and associated functions have been moved to the `aws-smithy-types-convert` crate.
  - Calls to `Instant::from_chrono` should be changed to:
    ```rust
    use aws_smithy_types::DateTime;
    use aws_smithy_types_convert::date_time::DateTimeExt;

    // For chrono::DateTime<Utc>
    let date_time = DateTime::from_chrono_utc(chrono_date_time);
    // For chrono::DateTime<FixedOffset>
    let date_time = DateTime::from_chrono_offset(chrono_date_time);
    ```
  - Calls to `instant.to_chrono()` should be changed to:
    ```rust
    use aws_smithy_types_convert::date_time::DateTimeExt;

    date_time.to_chrono_utc();
    ```
- `Instant::from_system_time` and `Instant::to_system_time` have been changed to `From` trait implementations.
  - Calls to `from_system_time` should be changed to:
    ```rust
    DateTime::from(system_time);
    // or
    let date_time: DateTime = system_time.into();
    ```
  - Calls to `to_system_time` should be changed to:
    ```rust
    SystemTime::from(date_time);
    // or
    let system_time: SystemTime = date_time.into();
    ```
- Several functions in `Instant`/`DateTime` were renamed:
  - `Instant::from_f64` -> `DateTime::from_secs_f64`
  - `Instant::from_fractional_seconds` -> `DateTime::from_fractional_secs`
  - `Instant::from_epoch_seconds` -> `DateTime::from_secs`
  - `Instant::from_epoch_millis` -> `DateTime::from_millis`
  - `Instant::epoch_fractional_seconds` -> `DateTime::as_secs_f64`
  - `Instant::has_nanos` -> `DateTime::has_subsec_nanos`
  - `Instant::epoch_seconds` -> `DateTime::secs`
  - `Instant::epoch_subsecond_nanos` -> `DateTime::subsec_nanos`
  - `Instant::to_epoch_millis` -> `DateTime::to_millis`
- The `DateTime::fmt` method is now fallible and fails when a `DateTime`'s value is outside what can be represented by the desired date format.

**New this week**
- Conversions from `aws_smithy_types::DateTime` to `OffsetDateTime` from the `time` crate are now available from the `aws-smithy-types-convert` crate. (smithy-rs#849)

v0.0.25-alpha (November 11th, 2021)
===================================

+17 −9
Original line number Diff line number Diff line
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

use aws_smithy_json::deserialize::token::skip_value;
use aws_smithy_json::deserialize::{json_token_iter, EscapeError, Token};
use aws_smithy_types::instant::Format;
use aws_smithy_types::Instant;
use aws_smithy_types::date_time::Format;
use aws_smithy_types::DateTime;
use std::borrow::Cow;
use std::convert::TryFrom;
use std::error::Error;
use std::fmt::{Display, Formatter};
use std::time::SystemTime;
@@ -167,13 +173,15 @@ pub(crate) fn parse_json_credentials(
                session_token.ok_or(InvalidJsonCredentials::MissingField("Token"))?;
            let expiration =
                expiration.ok_or(InvalidJsonCredentials::MissingField("Expiration"))?;
            let expiration = Instant::from_str(expiration.as_ref(), Format::DateTime)
                .map_err(|err| {
            let expiration = SystemTime::try_from(
                DateTime::from_str(expiration.as_ref(), Format::DateTime).map_err(|err| {
                    InvalidJsonCredentials::Other(format!("invalid date: {}", err).into())
                })?
                .to_system_time()
                .ok_or_else(|| {
                    InvalidJsonCredentials::Other("invalid expiration (prior to unix epoch)".into())
                })?,
            )
            .map_err(|_| {
                InvalidJsonCredentials::Other(
                    "credential expiration time cannot be represented by a SystemTime".into(),
                )
            })?;
            Ok(JsonCredentials::RefreshableCredentials {
                access_key_id,
+10 −8
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ pub(crate) mod util {
    use aws_sdk_sts::model::Credentials as StsCredentials;
    use aws_types::credentials::{self, CredentialsError};
    use aws_types::Credentials as AwsCredentials;
    use std::convert::TryFrom;
    use std::time::{SystemTime, UNIX_EPOCH};

    /// Convert STS credentials to aws_auth::Credentials
@@ -21,14 +22,15 @@ pub(crate) mod util {
    ) -> credentials::Result {
        let sts_credentials = sts_credentials
            .ok_or_else(|| CredentialsError::unhandled("STS credentials must be defined"))?;
        let expiration = sts_credentials
        let expiration = SystemTime::try_from(
            sts_credentials
                .expiration
            .ok_or_else(|| CredentialsError::unhandled("missing expiration"))?;
        let expiration = expiration.to_system_time().ok_or_else(|| {
            CredentialsError::unhandled(format!(
                "expiration is before unix epoch: {:?}",
                &expiration
            ))
                .ok_or_else(|| CredentialsError::unhandled("missing expiration"))?,
        )
        .map_err(|_| {
            CredentialsError::unhandled(
                "credential expiration time cannot be represented by a SystemTime",
            )
        })?;
        Ok(AwsCredentials::new(
            sts_credentials
+1 −1
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ impl SigV4Signer {
            .secret_key(credentials.secret_access_key())
            .region(region.as_ref())
            .service_name(signing_service.as_ref())
            .date_time(time.into())
            .time(time)
            .settings(());
        builder.set_security_token(credentials.session_token());
        builder.build().unwrap()
Loading