From 3175d0c73aea426356372281dd13af4ec7e23177 Mon Sep 17 00:00:00 2001 From: Landon James Date: Sun, 22 Sep 2024 13:12:24 -0700 Subject: [PATCH] Move checksum configs to aws_smithy_types Update codegen to point to new checksum config --- aws/rust-runtime/Cargo.lock | 3 +- aws/rust-runtime/aws-config/Cargo.lock | 63 +------ aws/rust-runtime/aws-config/Cargo.toml | 1 - .../aws-config/external-types.toml | 4 +- .../src/default_provider/checksums.rs | 5 +- aws/rust-runtime/aws-config/src/lib.rs | 4 +- .../src/http_request_checksum.rs | 3 +- .../src/http_response_checksum.rs | 3 +- aws/rust-runtime/aws-types/Cargo.toml | 1 - .../aws-types/external-types.toml | 4 +- aws/rust-runtime/aws-types/src/sdk_config.rs | 8 +- .../rustsdk/HttpRequestChecksumDecorator.kt | 4 +- ...estChecksumMutationInterceptorGenerator.kt | 4 +- .../rustsdk/HttpResponseChecksumDecorator.kt | 4 +- ...nseChecksumMutationInterceptorGenerator.kt | 4 +- rust-runtime/Cargo.lock | 2 +- rust-runtime/aws-smithy-checksums/Cargo.toml | 2 +- .../aws-smithy-checksums/external-types.toml | 2 - .../aws-smithy-checksums/src/error.rs | 62 ------- rust-runtime/aws-smithy-checksums/src/lib.rs | 80 +-------- .../aws-smithy-types/src/checksum_config.rs | 155 ++++++++++++++++++ rust-runtime/aws-smithy-types/src/lib.rs | 1 + 22 files changed, 189 insertions(+), 230 deletions(-) create mode 100644 rust-runtime/aws-smithy-types/src/checksum_config.rs diff --git a/aws/rust-runtime/Cargo.lock b/aws/rust-runtime/Cargo.lock index 7196bf17b15..1ca6cbfe50b 100644 --- a/aws/rust-runtime/Cargo.lock +++ b/aws/rust-runtime/Cargo.lock @@ -240,7 +240,7 @@ dependencies = [ [[package]] name = "aws-smithy-checksums" -version = "0.60.13" +version = "0.62.0" dependencies = [ "aws-smithy-http", "aws-smithy-types", @@ -371,7 +371,6 @@ version = "1.3.4" dependencies = [ "aws-credential-types", "aws-smithy-async", - "aws-smithy-checksums", "aws-smithy-runtime", "aws-smithy-runtime-api", "aws-smithy-types", diff --git a/aws/rust-runtime/aws-config/Cargo.lock b/aws/rust-runtime/aws-config/Cargo.lock index 1e31aa09d79..0b5ccfc6d4b 100644 --- a/aws/rust-runtime/aws-config/Cargo.lock +++ b/aws/rust-runtime/aws-config/Cargo.lock @@ -53,7 +53,6 @@ dependencies = [ "aws-sdk-ssooidc", "aws-sdk-sts", "aws-smithy-async", - "aws-smithy-checksums", "aws-smithy-http", "aws-smithy-json", "aws-smithy-runtime", @@ -202,25 +201,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "aws-smithy-checksums" -version = "0.60.12" -dependencies = [ - "aws-smithy-http", - "aws-smithy-types", - "bytes", - "crc32c", - "crc32fast", - "hex", - "http 0.2.12", - "http-body 0.4.6", - "md-5", - "pin-project-lite", - "sha1", - "sha2", - "tracing", -] - [[package]] name = "aws-smithy-http" version = "0.60.11" @@ -318,7 +298,7 @@ dependencies = [ [[package]] name = "aws-smithy-types" -version = "1.2.6" +version = "1.2.7" dependencies = [ "base64-simd", "bytes", @@ -346,7 +326,7 @@ dependencies = [ [[package]] name = "aws-types" -version = "1.3.3" +version = "1.3.4" dependencies = [ "aws-credential-types", "aws-smithy-async", @@ -495,24 +475,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crc32c" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a47af21622d091a8f0fb295b88bc886ac74efcc613efc19f5d0b21de5c89e47" -dependencies = [ - "rustc_version", -] - -[[package]] -name = "crc32fast" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" -dependencies = [ - "cfg-if", -] - [[package]] name = "crunchy" version = "0.2.2" @@ -907,16 +869,6 @@ dependencies = [ "regex-automata 0.1.10", ] -[[package]] -name = "md-5" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" -dependencies = [ - "cfg-if", - "digest", -] - [[package]] name = "memchr" version = "2.7.4" @@ -1397,17 +1349,6 @@ dependencies = [ "serde", ] -[[package]] -name = "sha1" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - [[package]] name = "sha2" version = "0.10.8" diff --git a/aws/rust-runtime/aws-config/Cargo.toml b/aws/rust-runtime/aws-config/Cargo.toml index 86c290cea98..bedb7d0bcc8 100644 --- a/aws/rust-runtime/aws-config/Cargo.toml +++ b/aws/rust-runtime/aws-config/Cargo.toml @@ -33,7 +33,6 @@ aws-smithy-json = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-json" } aws-smithy-runtime = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-runtime", features = ["client"] } aws-smithy-runtime-api = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-runtime-api", features = ["client"] } aws-smithy-types = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-types" } -aws-smithy-checksums = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-checksums" } aws-types = { path = "../../sdk/build/aws-sdk/sdk/aws-types" } bytes = "1.1.0" http = "0.2.4" diff --git a/aws/rust-runtime/aws-config/external-types.toml b/aws/rust-runtime/aws-config/external-types.toml index 06a63b208bf..3e2c6726d1e 100644 --- a/aws/rust-runtime/aws-config/external-types.toml +++ b/aws/rust-runtime/aws-config/external-types.toml @@ -20,8 +20,6 @@ allowed_external_types = [ "aws_smithy_async::rt::sleep::SharedAsyncSleep", "aws_smithy_async::time::SharedTimeSource", "aws_smithy_async::time::TimeSource", - "aws_smithy_checksums::RequestChecksumCalculation", - "aws_smithy_checksums::ResponseChecksumValidation", "aws_smithy_runtime::client::identity::cache::IdentityCache", "aws_smithy_runtime::client::identity::cache::lazy::LazyCacheBuilder", "aws_smithy_runtime_api::box_error::BoxError", @@ -36,6 +34,8 @@ allowed_external_types = [ "aws_smithy_runtime_api::client::result::SdkError", "aws_smithy_runtime_api::client::stalled_stream_protection::StalledStreamProtectionConfig", "aws_smithy_types::body::SdkBody", + "aws_smithy_types::checksum_config::RequestChecksumCalculation", + "aws_smithy_types::checksum_config::ResponseChecksumValidation", "aws_smithy_types::retry", "aws_smithy_types::retry::*", "aws_smithy_types::timeout", diff --git a/aws/rust-runtime/aws-config/src/default_provider/checksums.rs b/aws/rust-runtime/aws-config/src/default_provider/checksums.rs index 605d8ce015b..3e9298b8e85 100644 --- a/aws/rust-runtime/aws-config/src/default_provider/checksums.rs +++ b/aws/rust-runtime/aws-config/src/default_provider/checksums.rs @@ -81,9 +81,10 @@ mod test { #[allow(deprecated)] use crate::profile::profile_file::{ProfileFileKind, ProfileFiles}; use crate::provider_config::ProviderConfig; - use aws_smithy_checksums::ResponseChecksumValidation; + use aws_smithy_types::checksum_config::{ + RequestChecksumCalculation, ResponseChecksumValidation, + }; use aws_types::os_shim_internal::{Env, Fs}; - use aws_types::sdk_config::RequestChecksumCalculation; use tracing_test::traced_test; #[tokio::test] diff --git a/aws/rust-runtime/aws-config/src/lib.rs b/aws/rust-runtime/aws-config/src/lib.rs index 7c753501d1a..241c8c75496 100644 --- a/aws/rust-runtime/aws-config/src/lib.rs +++ b/aws/rust-runtime/aws-config/src/lib.rs @@ -222,13 +222,15 @@ mod loader { use aws_credential_types::Credentials; use aws_smithy_async::rt::sleep::{default_async_sleep, AsyncSleep, SharedAsyncSleep}; use aws_smithy_async::time::{SharedTimeSource, TimeSource}; - use aws_smithy_checksums::{RequestChecksumCalculation, ResponseChecksumValidation}; use aws_smithy_runtime::client::identity::IdentityCache; use aws_smithy_runtime_api::client::behavior_version::BehaviorVersion; use aws_smithy_runtime_api::client::http::HttpClient; use aws_smithy_runtime_api::client::identity::{ResolveCachedIdentity, SharedIdentityCache}; use aws_smithy_runtime_api::client::stalled_stream_protection::StalledStreamProtectionConfig; use aws_smithy_runtime_api::shared::IntoShared; + use aws_smithy_types::checksum_config::{ + RequestChecksumCalculation, ResponseChecksumValidation, + }; use aws_smithy_types::retry::RetryConfig; use aws_smithy_types::timeout::TimeoutConfig; use aws_types::app_name::AppName; diff --git a/aws/rust-runtime/aws-inlineable/src/http_request_checksum.rs b/aws/rust-runtime/aws-inlineable/src/http_request_checksum.rs index 28ad4a65200..35e1e435f59 100644 --- a/aws/rust-runtime/aws-inlineable/src/http_request_checksum.rs +++ b/aws/rust-runtime/aws-inlineable/src/http_request_checksum.rs @@ -10,8 +10,8 @@ use aws_runtime::content_encoding::{AwsChunkedBody, AwsChunkedBodyOptions}; use aws_runtime::{auth::SigV4OperationSigningConfig, content_encoding::header_value::AWS_CHUNKED}; use aws_sigv4::http_request::SignableBody; +use aws_smithy_checksums::ChecksumAlgorithm; use aws_smithy_checksums::{body::calculate, http::HttpChecksum}; -use aws_smithy_checksums::{ChecksumAlgorithm, RequestChecksumCalculation}; use aws_smithy_runtime_api::box_error::BoxError; use aws_smithy_runtime_api::client::interceptors::context::{ BeforeSerializationInterceptorContextRef, BeforeTransmitInterceptorContextMut, Input, @@ -20,6 +20,7 @@ use aws_smithy_runtime_api::client::interceptors::Intercept; use aws_smithy_runtime_api::client::orchestrator::HttpRequest; use aws_smithy_runtime_api::client::runtime_components::RuntimeComponents; use aws_smithy_types::body::SdkBody; +use aws_smithy_types::checksum_config::RequestChecksumCalculation; use aws_smithy_types::config_bag::{ConfigBag, Layer, Storable, StoreReplace}; use aws_smithy_types::error::operation::BuildError; use http::HeaderValue; diff --git a/aws/rust-runtime/aws-inlineable/src/http_response_checksum.rs b/aws/rust-runtime/aws-inlineable/src/http_response_checksum.rs index fca126c1f2f..90754dbceb7 100644 --- a/aws/rust-runtime/aws-inlineable/src/http_response_checksum.rs +++ b/aws/rust-runtime/aws-inlineable/src/http_response_checksum.rs @@ -7,7 +7,7 @@ //! Interceptor for handling Smithy `@httpChecksum` response checksumming -use aws_smithy_checksums::{ChecksumAlgorithm, ResponseChecksumValidation}; +use aws_smithy_checksums::ChecksumAlgorithm; use aws_smithy_runtime_api::box_error::BoxError; use aws_smithy_runtime_api::client::interceptors::context::{ BeforeDeserializationInterceptorContextMut, BeforeSerializationInterceptorContextMut, Input, @@ -16,6 +16,7 @@ use aws_smithy_runtime_api::client::interceptors::Intercept; use aws_smithy_runtime_api::client::runtime_components::RuntimeComponents; use aws_smithy_runtime_api::http::Headers; use aws_smithy_types::body::SdkBody; +use aws_smithy_types::checksum_config::ResponseChecksumValidation; use aws_smithy_types::config_bag::{ConfigBag, Layer, Storable, StoreReplace}; use std::{fmt, mem}; diff --git a/aws/rust-runtime/aws-types/Cargo.toml b/aws/rust-runtime/aws-types/Cargo.toml index fc4a514b2bf..e13428e4baf 100644 --- a/aws/rust-runtime/aws-types/Cargo.toml +++ b/aws/rust-runtime/aws-types/Cargo.toml @@ -17,7 +17,6 @@ aws-smithy-async = { path = "../../../rust-runtime/aws-smithy-async" } aws-smithy-types = { path = "../../../rust-runtime/aws-smithy-types" } aws-smithy-runtime = { path = "../../../rust-runtime/aws-smithy-runtime", optional = true } aws-smithy-runtime-api = { path = "../../../rust-runtime/aws-smithy-runtime-api", features = ["client"] } -aws-smithy-checksums = {path = "../../../rust-runtime/aws-smithy-checksums"} tracing = "0.1" # cargo does not support optional test dependencies, so to completely disable rustls # we need to add the webpki-roots feature here. diff --git a/aws/rust-runtime/aws-types/external-types.toml b/aws/rust-runtime/aws-types/external-types.toml index af506bc4be5..ee28a1732a5 100644 --- a/aws/rust-runtime/aws-types/external-types.toml +++ b/aws/rust-runtime/aws-types/external-types.toml @@ -6,8 +6,6 @@ allowed_external_types = [ "aws_smithy_async::rt::sleep::SharedAsyncSleep", "aws_smithy_async::time::SharedTimeSource", "aws_smithy_async::time::TimeSource", - "aws_smithy_checksums::ResponseChecksumValidation", - "aws_smithy_checksums::RequestChecksumCalculation", "aws_smithy_runtime_api::client::behavior_version::BehaviorVersion", "aws_smithy_runtime_api::client::http::HttpClient", "aws_smithy_runtime_api::client::http::SharedHttpClient", @@ -15,6 +13,8 @@ allowed_external_types = [ "aws_smithy_runtime_api::client::identity::SharedIdentityCache", "aws_smithy_runtime_api::client::stalled_stream_protection::StalledStreamProtectionConfig", "aws_smithy_runtime_api::http::headers::Headers", + "aws_smithy_types::checksum_config::ResponseChecksumValidation", + "aws_smithy_types::checksum_config::RequestChecksumCalculation", "aws_smithy_types::config_bag::storable::Storable", "aws_smithy_types::config_bag::storable::StoreReplace", "aws_smithy_types::config_bag::storable::Storer", diff --git a/aws/rust-runtime/aws-types/src/sdk_config.rs b/aws/rust-runtime/aws-types/src/sdk_config.rs index 923cb47be04..19220fc526e 100644 --- a/aws/rust-runtime/aws-types/src/sdk_config.rs +++ b/aws/rust-runtime/aws-types/src/sdk_config.rs @@ -19,13 +19,15 @@ pub use aws_credential_types::provider::SharedCredentialsProvider; use aws_smithy_async::rt::sleep::AsyncSleep; pub use aws_smithy_async::rt::sleep::SharedAsyncSleep; pub use aws_smithy_async::time::{SharedTimeSource, TimeSource}; -pub use aws_smithy_checksums::{RequestChecksumCalculation, ResponseChecksumValidation}; use aws_smithy_runtime_api::client::behavior_version::BehaviorVersion; use aws_smithy_runtime_api::client::http::HttpClient; pub use aws_smithy_runtime_api::client::http::SharedHttpClient; use aws_smithy_runtime_api::client::identity::{ResolveCachedIdentity, SharedIdentityCache}; pub use aws_smithy_runtime_api::client::stalled_stream_protection::StalledStreamProtectionConfig; use aws_smithy_runtime_api::shared::IntoShared; +pub use aws_smithy_types::checksum_config::{ + RequestChecksumCalculation, ResponseChecksumValidation, +}; pub use aws_smithy_types::retry::RetryConfig; pub use aws_smithy_types::timeout::TimeoutConfig; use std::collections::HashMap; @@ -183,7 +185,7 @@ impl Builder { /// # Examples /// ``` /// use aws_types::SdkConfig; - /// use aws_smithy_checksums::RequestChecksumCalculation; + /// use aws_smithy_types::checksum_config::RequestChecksumCalculation; /// let config = SdkConfig::builder().request_checksum_calculation(RequestChecksumCalculation::WhenSupported).build(); /// ``` pub fn request_checksum_calculation( @@ -207,7 +209,7 @@ impl Builder { /// # Examples /// ``` /// use aws_types::SdkConfig; - /// use aws_smithy_checksums::ResponseChecksumValidation; + /// use aws_smithy_types::checksum_config::ResponseChecksumValidation; /// let config = SdkConfig::builder().response_checksum_validation(ResponseChecksumValidation::WhenSupported).build(); /// ``` pub fn response_checksum_validation( diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpRequestChecksumDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpRequestChecksumDecorator.kt index b1e439d279c..84f53209b38 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpRequestChecksumDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpRequestChecksumDecorator.kt @@ -220,8 +220,8 @@ class HttpRequestChecksumConfigCustomization(private val codegenContext: ClientC *preludeScope, "RequestChecksumCalculation" to configReexport( - RuntimeType.smithyChecksums(rc) - .resolve("RequestChecksumCalculation"), + RuntimeType.smithyTypes(rc) + .resolve("checksum_config::RequestChecksumCalculation"), ), ) diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpRequestChecksumMutationInterceptorGenerator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpRequestChecksumMutationInterceptorGenerator.kt index 015505c0125..f692891065d 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpRequestChecksumMutationInterceptorGenerator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpRequestChecksumMutationInterceptorGenerator.kt @@ -93,8 +93,8 @@ class HttpRequestChecksumMutationInterceptorGenerator : ClientCodegenDecorator { "Error" to interceptors.resolve("context::Error"), "RuntimeComponents" to RuntimeType.runtimeComponents(rc), "RequestChecksumCalculation" to - CargoDependency.smithyChecksums(rc).toType() - .resolve("RequestChecksumCalculation"), + CargoDependency.smithyTypes(rc).toType() + .resolve("checksum_config::RequestChecksumCalculation"), ) } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpResponseChecksumDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpResponseChecksumDecorator.kt index 38844fe2f7c..98c4b378863 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpResponseChecksumDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpResponseChecksumDecorator.kt @@ -191,8 +191,8 @@ class HttpResponseChecksumConfigCustomization(private val codegenContext: Client *preludeScope, "ResponseChecksumValidation" to configReexport( - RuntimeType.smithyChecksums(rc) - .resolve("ResponseChecksumValidation"), + RuntimeType.smithyTypes(rc) + .resolve("checksum_config::ResponseChecksumValidation"), ), ) diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpResponseChecksumMutationInterceptorGenerator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpResponseChecksumMutationInterceptorGenerator.kt index 30f69e2c467..f3a181533d2 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpResponseChecksumMutationInterceptorGenerator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpResponseChecksumMutationInterceptorGenerator.kt @@ -94,8 +94,8 @@ class HttpResponseChecksumMutationInterceptorGenerator : ClientCodegenDecorator "Error" to interceptors.resolve("context::Error"), "RuntimeComponents" to RuntimeType.runtimeComponents(rc), "ResponseChecksumValidation" to - CargoDependency.smithyChecksums(rc).toType() - .resolve("ResponseChecksumValidation"), + CargoDependency.smithyTypes(rc).toType() + .resolve("checksum_config::ResponseChecksumValidation"), ) } diff --git a/rust-runtime/Cargo.lock b/rust-runtime/Cargo.lock index b78c57ace02..5acf1f25bf5 100644 --- a/rust-runtime/Cargo.lock +++ b/rust-runtime/Cargo.lock @@ -336,7 +336,7 @@ dependencies = [ [[package]] name = "aws-smithy-checksums" -version = "0.60.13" +version = "0.62.0" dependencies = [ "aws-smithy-http 0.60.11", "aws-smithy-types 1.2.7", diff --git a/rust-runtime/aws-smithy-checksums/Cargo.toml b/rust-runtime/aws-smithy-checksums/Cargo.toml index 08882469924..97b295130ce 100644 --- a/rust-runtime/aws-smithy-checksums/Cargo.toml +++ b/rust-runtime/aws-smithy-checksums/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aws-smithy-checksums" -version = "0.60.13" +version = "0.62.0" authors = [ "AWS Rust SDK Team ", "Zelda Hessler ", diff --git a/rust-runtime/aws-smithy-checksums/external-types.toml b/rust-runtime/aws-smithy-checksums/external-types.toml index ddd93c5af15..dbd4b4eee20 100644 --- a/rust-runtime/aws-smithy-checksums/external-types.toml +++ b/rust-runtime/aws-smithy-checksums/external-types.toml @@ -1,7 +1,5 @@ allowed_external_types = [ "aws_smithy_types::body::SdkBody", - "aws_smithy_types::config_bag::storable::StoreReplace", - "aws_smithy_types::config_bag::storable::Storable", "bytes::bytes::Bytes", "http::header::map::HeaderMap", "http::header::name::HeaderName", diff --git a/rust-runtime/aws-smithy-checksums/src/error.rs b/rust-runtime/aws-smithy-checksums/src/error.rs index f184001829b..6a93cddbb7b 100644 --- a/rust-runtime/aws-smithy-checksums/src/error.rs +++ b/rust-runtime/aws-smithy-checksums/src/error.rs @@ -36,65 +36,3 @@ impl fmt::Display for UnknownChecksumAlgorithmError { } impl Error for UnknownChecksumAlgorithmError {} - -/// Unknown setting for `request_checksum_calculation` -#[derive(Debug)] -pub struct UnknownRequestChecksumCalculationError { - request_checksum_calculation: String, -} - -impl UnknownRequestChecksumCalculationError { - pub(crate) fn new(request_checksum_calculation: impl Into) -> Self { - Self { - request_checksum_calculation: request_checksum_calculation.into(), - } - } - - /// The unknown value - pub fn request_checksum_calculation(&self) -> &str { - &self.request_checksum_calculation - } -} - -impl fmt::Display for UnknownRequestChecksumCalculationError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!( - f, - r#"unknown request_checksum_calculation value "{}", please pass a known name ("when_supported", "when_required")"#, - self.request_checksum_calculation - ) - } -} - -impl Error for UnknownRequestChecksumCalculationError {} - -/// Unknown setting for `response_checksum_validation` -#[derive(Debug)] -pub struct UnknownResponseChecksumValidationError { - response_checksum_validation: String, -} - -impl UnknownResponseChecksumValidationError { - pub(crate) fn new(response_checksum_validation: impl Into) -> Self { - Self { - response_checksum_validation: response_checksum_validation.into(), - } - } - - /// The unknown value - pub fn response_checksum_validation(&self) -> &str { - &self.response_checksum_validation - } -} - -impl fmt::Display for UnknownResponseChecksumValidationError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!( - f, - r#"unknown response_checksum_validation value "{}", please pass a known name ("when_supported", "when_required")"#, - self.response_checksum_validation - ) - } -} - -impl Error for UnknownResponseChecksumValidationError {} diff --git a/rust-runtime/aws-smithy-checksums/src/lib.rs b/rust-runtime/aws-smithy-checksums/src/lib.rs index 1e37892f89a..b900bac5fa3 100644 --- a/rust-runtime/aws-smithy-checksums/src/lib.rs +++ b/rust-runtime/aws-smithy-checksums/src/lib.rs @@ -17,10 +17,7 @@ //! Checksum calculation and verification callbacks. use crate::error::UnknownChecksumAlgorithmError; -use crate::error::{ - UnknownRequestChecksumCalculationError, UnknownResponseChecksumValidationError, -}; -use aws_smithy_types::config_bag::{Storable, StoreReplace}; + use bytes::Bytes; use std::str::FromStr; @@ -101,81 +98,6 @@ impl ChecksumAlgorithm { } } -// Valid names for RequestChecksumCalculation and ResponseChecksumValidation -pub const WHEN_SUPPORTED: &str = "when_supported"; -pub const WHEN_REQUIRED: &str = "when_required"; - -/// Determines when a checksum will be calculated for request payloads. Values are: -/// * [RequestChecksumCalculation::WhenSupported] - (default) When set, a checksum will be -/// calculated for all request payloads of operations modeled with the -/// `httpChecksum` trait where `requestChecksumRequired` is `true` and/or a -/// `requestAlgorithmMember` is modeled. -/// * [RequestChecksumCalculation::WhenRequired] - When set, a checksum will only be calculated for -/// request payloads of operations modeled with the `httpChecksum` trait where -/// `requestChecksumRequired` is `true` or where a requestAlgorithmMember -/// is modeled and supplied. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[non_exhaustive] -pub enum RequestChecksumCalculation { - WhenSupported, - WhenRequired, -} - -impl Storable for RequestChecksumCalculation { - type Storer = StoreReplace; -} - -impl FromStr for RequestChecksumCalculation { - type Err = UnknownRequestChecksumCalculationError; - - fn from_str(request_checksum_calculation: &str) -> Result { - if request_checksum_calculation.eq_ignore_ascii_case(WHEN_SUPPORTED) { - Ok(Self::WhenSupported) - } else if request_checksum_calculation.eq_ignore_ascii_case(WHEN_REQUIRED) { - Ok(Self::WhenRequired) - } else { - Err(UnknownRequestChecksumCalculationError::new( - request_checksum_calculation, - )) - } - } -} - -/// Determines when checksum validation will be performed on response payloads. Values are: -/// * [ResponseChecksumValidation::WhenSupported] - (default) When set, checksum validation is performed on all -/// response payloads of operations modeled with the `httpChecksum` trait where -/// `responseAlgorithms` is modeled, except when no modeled checksum algorithms -/// are supported. -/// * [ResponseChecksumValidation::WhenRequired] - When set, checksum validation is not performed on -/// response payloads of operations unless the checksum algorithm is supported and -/// the `requestValidationModeMember` member is set to `ENABLED`. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -#[non_exhaustive] -pub enum ResponseChecksumValidation { - WhenSupported, - WhenRequired, -} - -impl Storable for ResponseChecksumValidation { - type Storer = StoreReplace; -} - -impl FromStr for ResponseChecksumValidation { - type Err = UnknownResponseChecksumValidationError; - - fn from_str(response_checksum_validation: &str) -> Result { - if response_checksum_validation.eq_ignore_ascii_case(WHEN_SUPPORTED) { - Ok(Self::WhenSupported) - } else if response_checksum_validation.eq_ignore_ascii_case(WHEN_REQUIRED) { - Ok(Self::WhenRequired) - } else { - Err(UnknownResponseChecksumValidationError::new( - response_checksum_validation, - )) - } - } -} - /// Types implementing this trait can calculate checksums. /// /// Checksum algorithms are used to validate the integrity of data. Structs that implement this trait diff --git a/rust-runtime/aws-smithy-types/src/checksum_config.rs b/rust-runtime/aws-smithy-types/src/checksum_config.rs new file mode 100644 index 00000000000..f5b412bb798 --- /dev/null +++ b/rust-runtime/aws-smithy-types/src/checksum_config.rs @@ -0,0 +1,155 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +//! Types that allow users to indicate their preferences for checksum calculation and validation + +use std::error::Error; +use std::fmt; +use std::str::FromStr; + +use crate::config_bag::{Storable, StoreReplace}; + +// Valid names for RequestChecksumCalculation and ResponseChecksumValidation +const WHEN_SUPPORTED: &str = "when_supported"; +const WHEN_REQUIRED: &str = "when_required"; + +/// Determines when a checksum will be calculated for request payloads. Values are: +/// * [RequestChecksumCalculation::WhenSupported] - (default) When set, a checksum will be +/// calculated for all request payloads of operations modeled with the +/// `httpChecksum` trait where `requestChecksumRequired` is `true` and/or a +/// `requestAlgorithmMember` is modeled. +/// * [RequestChecksumCalculation::WhenRequired] - When set, a checksum will only be calculated for +/// request payloads of operations modeled with the `httpChecksum` trait where +/// `requestChecksumRequired` is `true` or where a requestAlgorithmMember +/// is modeled and supplied. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[non_exhaustive] +pub enum RequestChecksumCalculation { + /// Calculate request checksums when they are supported. + WhenSupported, + /// Caulculate request checksums only when they are required. + WhenRequired, +} + +impl Storable for RequestChecksumCalculation { + type Storer = StoreReplace; +} + +impl FromStr for RequestChecksumCalculation { + type Err = UnknownRequestChecksumCalculationError; + + fn from_str(request_checksum_calculation: &str) -> Result { + if request_checksum_calculation.eq_ignore_ascii_case(WHEN_SUPPORTED) { + Ok(Self::WhenSupported) + } else if request_checksum_calculation.eq_ignore_ascii_case(WHEN_REQUIRED) { + Ok(Self::WhenRequired) + } else { + Err(UnknownRequestChecksumCalculationError::new( + request_checksum_calculation, + )) + } + } +} + +/// Determines when checksum validation will be performed on response payloads. Values are: +/// * [ResponseChecksumValidation::WhenSupported] - (default) When set, checksum validation is performed on all +/// response payloads of operations modeled with the `httpChecksum` trait where +/// `responseAlgorithms` is modeled, except when no modeled checksum algorithms +/// are supported. +/// * [ResponseChecksumValidation::WhenRequired] - When set, checksum validation is not performed on +/// response payloads of operations unless the checksum algorithm is supported and +/// the `requestValidationModeMember` member is set to `ENABLED`. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[non_exhaustive] +pub enum ResponseChecksumValidation { + /// Validate response checksums when they are supported. + WhenSupported, + /// Validate response checksums only when they are required. + WhenRequired, +} + +impl Storable for ResponseChecksumValidation { + type Storer = StoreReplace; +} + +impl FromStr for ResponseChecksumValidation { + type Err = UnknownResponseChecksumValidationError; + + fn from_str(response_checksum_validation: &str) -> Result { + if response_checksum_validation.eq_ignore_ascii_case(WHEN_SUPPORTED) { + Ok(Self::WhenSupported) + } else if response_checksum_validation.eq_ignore_ascii_case(WHEN_REQUIRED) { + Ok(Self::WhenRequired) + } else { + Err(UnknownResponseChecksumValidationError::new( + response_checksum_validation, + )) + } + } +} + +/// Unknown setting for `request_checksum_calculation` +#[derive(Debug)] +#[non_exhaustive] +pub struct UnknownRequestChecksumCalculationError { + request_checksum_calculation: String, +} + +impl UnknownRequestChecksumCalculationError { + pub(crate) fn new(request_checksum_calculation: impl Into) -> Self { + Self { + request_checksum_calculation: request_checksum_calculation.into(), + } + } + + /// The unknown value + pub fn request_checksum_calculation(&self) -> &str { + &self.request_checksum_calculation + } +} + +impl fmt::Display for UnknownRequestChecksumCalculationError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + r#"unknown request_checksum_calculation value "{}", please pass a known name ("when_supported", "when_required")"#, + self.request_checksum_calculation + ) + } +} + +impl Error for UnknownRequestChecksumCalculationError {} + +/// Unknown setting for `response_checksum_validation` +#[derive(Debug)] +#[non_exhaustive] +pub struct UnknownResponseChecksumValidationError { + response_checksum_validation: String, +} + +impl UnknownResponseChecksumValidationError { + pub(crate) fn new(response_checksum_validation: impl Into) -> Self { + Self { + response_checksum_validation: response_checksum_validation.into(), + } + } + + /// The unknown value + pub fn response_checksum_validation(&self) -> &str { + &self.response_checksum_validation + } +} + +impl fmt::Display for UnknownResponseChecksumValidationError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + r#"unknown response_checksum_validation value "{}", please pass a known name ("when_supported", "when_required")"#, + self.response_checksum_validation + ) + } +} + +impl Error for UnknownResponseChecksumValidationError {} diff --git a/rust-runtime/aws-smithy-types/src/lib.rs b/rust-runtime/aws-smithy-types/src/lib.rs index ed53de191b4..5af73e1fb18 100644 --- a/rust-runtime/aws-smithy-types/src/lib.rs +++ b/rust-runtime/aws-smithy-types/src/lib.rs @@ -20,6 +20,7 @@ pub mod base64; pub mod body; pub mod byte_stream; +pub mod checksum_config; /// A typemap for storing configuration. pub mod config_bag; pub mod date_time;