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

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

Merged
merged 16 commits into from
Nov 12, 2021

Conversation

jdisanti
Copy link
Collaborator

@jdisanti jdisanti commented Nov 10, 2021

Motivation and Context

This PR removes the aws-smithy-types and aws-sigv4 dependency on chrono for date-time parsing/formatting since it is no longer maintained and has a CVE.

Description

  • aws-smithy-types and aws-sigv4 were refactored to use the time crate rather than chrono.
  • Instant was renamed to DateTime to avoid confusion with the standard library type.
  • DateTime formatting now returns a result instead of panicking when the DateTime can't be represented in the requested format.
  • DateTime is now re-exported from service crates so that an explicit dependency on aws-smithy-types isn't required anymore.
  • The chrono conversions were retained in a new aws-smithy-types-convert crate behind an optional feature. Conversions to the time crate were also added.

Testing

  • Ran existing tests and added new ones where necessary.

Checklist

  • I have updated CHANGELOG.md
  • I have updated aws/SDK_CHANGELOG.md if applicable

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@jdisanti jdisanti requested review from a team as code owners November 10, 2021 01:29
@github-actions
Copy link

A new generated diff is ready to view: __generated-main...__generated-jdisanti-replace-chrono

1 similar comment
@github-actions
Copy link

A new generated diff is ready to view: __generated-main...__generated-jdisanti-replace-chrono

@jdisanti
Copy link
Collaborator Author

Looks like I need to revisit DateTime <-> SystemTime conversions to work on Windows, and we should check MacOS too.

Copy link
Collaborator

@rcoh rcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Notes are all extremely minor, this looks great.

rust-runtime/aws-smithy-types/src/instant/mod.rs Outdated Show resolved Hide resolved
rust-runtime/aws-smithy-types/src/instant/mod.rs Outdated Show resolved Hide resolved
aws/rust-runtime/aws-sig-auth/src/signer.rs Show resolved Hide resolved
pub enum Error {
/// Conversion failed because the value being converted is out of range for its destination
#[non_exhaustive]
OutOfRange(Box<dyn StdError + Send + Sync + 'static>),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this error type actually unknown? I figured it would always be DateTimeParseError

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this one open ended so that we can add additional library conversions to the aws-smithy-types-convert crate without having to change the error type at all. In this case, the only error being fed into Error::OutOfRange is the error from time::OffsetDateTime::from_unix_timestamp_nanos.

@@ -1,6 +1,56 @@
vNext (Month Day, Year)
=======================

**Breaking Changes**

Several breaking changes around `aws_smithy_types::Instant` were introduced by smithy-rs#TODO:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you:

  • list out the crates with breaking changes as a top level item (for ease of release cutting)
  • add the changes to aws-sigv4 and aws-sig-auth

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list out the crates with breaking changes as a top level item (for ease of release cutting)

I'm not sure I understand how this makes releasing eaiser.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a changelog entry for aws-sigv4. There weren't any breaking changes to aws-sig-auth.

@github-actions
Copy link

A new generated diff is ready to view: __generated-main...__generated-jdisanti-replace-chrono

1 similar comment
@github-actions
Copy link

A new generated diff is ready to view: __generated-main...__generated-jdisanti-replace-chrono

@github-actions
Copy link

A new generated diff is ready to view: __generated-main...__generated-jdisanti-replace-chrono

Copy link
Contributor

@crisidev crisidev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Nice change!

@crisidev
Copy link
Contributor

Some of the examples in the Tier2 CI need to be updated:

error[E0599]: no method named `to_chrono` found for reference `&DateTime` in the current scope
  --> examples/apigateway/src/bin/get_rest_apis.rs:30:65
   |
30 |         println!("Created:     {}", api.created_date().unwrap().to_chrono());
   |                                                                 ^^^^^^^^^ method not found in `&DateTime`

error: aborting due to previous error

use std::error::Error as StdError;
use std::fmt;

/// Conversion erro/Insta
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfinished comment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Thanks.

}

/// Adds functions to [`DateTime`] to convert it to `time` or `chrono` types.
///
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
///

doc = r##"
# Example with `time`

Make sure your *Cargo.toml* enables the `convert-time` feature:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Make sure your *Cargo.toml* enables the `convert-time` feature:
Make sure your `Cargo.toml` enables the `convert-time` feature:

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that the suggested change is missing a space after your

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This raises the question of what our API doc style is. Our AWS SDK Guide Documentation uses bold for file names, and I'm inclined to be consistent with that. Open to debate though.

doc = r##"
# Example with `chrono`

Make sure your *Cargo.toml* enables the `convert-chrono` feature:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Make sure your *Cargo.toml* enables the `convert-chrono` feature:
Make sure your `Cargo.toml` enables the `convert-chrono` feature:

* SPDX-License-Identifier: Apache-2.0.
*/

//! DateTime value for representing Smithy timestamps.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! DateTime value for representing Smithy timestamps.
//! DateTime type for representing Smithy timestamps.

const NANOS_PER_SECOND: i128 = 1_000_000_000;
const NANOS_PER_SECOND_U32: u32 = 1_000_000_000;

/* ANCHOR: date_time */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these "anchors" about?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when we generate the mdbook of smithy docs, these code snippets get included

Comment on lines 118 to 121
// This code is taken from https://github.com/pyfisch/httpdate and modified under an
// Apache 2.0 License. Modifications:
// - Removed use of unsafe
// - Add serialization and deserialization of subsecond nanos
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first reaction upon seeing this code was "why aren't we using httpdate"? These strike me as valuable additions to contribute upstream. Can we? Also, can't we simply depend on httpdate and wrap it in a newtype to provide our additional functionality?


Also, I'm not a lawyer, but I thought that if one copied MIT-licensed code, a copy of the MIT license has to be included with it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// - Add serialization and deserialization of subsecond nanos this is outside of the HTTP date spec (as in, "wrong" if you're actually parsing and serializing http dates.

@github-actions
Copy link

A new generated diff is ready to view: __generated-main...__generated-jdisanti-replace-chrono

@github-actions
Copy link

A new generated diff is ready to view: __generated-main...__generated-jdisanti-replace-chrono

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants