From d4e2745cfc36a5b1da1bfe9a8a772419fe780958 Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Fri, 10 Nov 2023 18:18:17 -0800 Subject: [PATCH] Move `RequestId` to aws-types (#3160) This PR moves `RequestId` into the aws-types stable crate. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._ --- CHANGELOG.next.toml | 6 ++++ aws/rust-runtime/aws-http/Cargo.toml | 3 +- aws/rust-runtime/aws-http/src/lib.rs | 3 -- .../aws-inlineable/src/s3_request_id.rs | 10 ++----- .../aws-types/external-types.toml | 2 ++ aws/rust-runtime/aws-types/src/lib.rs | 1 + .../{aws-http => aws-types}/src/request_id.rs | 17 +++++------ .../smithy/rustsdk/AwsRequestIdDecorator.kt | 2 +- rust-runtime/aws-smithy-http/src/http.rs | 30 ------------------- rust-runtime/aws-smithy-http/src/lib.rs | 1 - 10 files changed, 22 insertions(+), 53 deletions(-) rename aws/rust-runtime/{aws-http => aws-types}/src/request_id.rs (92%) delete mode 100644 rust-runtime/aws-smithy-http/src/http.rs diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index 952501eeba..dcf5cf917e 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -107,3 +107,9 @@ message = "ProvideCredentials and SharedCredentialsProvider are now re-exported. references = ["smithy-rs#3173", "smithy-rs#3155"] meta = { "breaking" = false, "tada" = false, "bug" = false } author = "rcoh" + +[[aws-sdk-rust]] +message = "The `RequestId` trait has moved from the aws-http crate into aws-types." +references = ["smithy-rs#3160"] +meta = { "breaking" = true, "tada" = false, "bug" = false } +author = "jdisanti" diff --git a/aws/rust-runtime/aws-http/Cargo.toml b/aws/rust-runtime/aws-http/Cargo.toml index d22e473a7c..a6303982f6 100644 --- a/aws/rust-runtime/aws-http/Cargo.toml +++ b/aws/rust-runtime/aws-http/Cargo.toml @@ -8,9 +8,8 @@ license = "Apache-2.0" repository = "https://github.com/smithy-lang/smithy-rs" [dependencies] -aws-smithy-http = { path = "../../../rust-runtime/aws-smithy-http" } aws-smithy-runtime-api = { path = "../../../rust-runtime/aws-smithy-runtime-api", features = ["client"] } -aws-smithy-types = { path = "../../../rust-runtime/aws-smithy-types" } +aws-smithy-types = { path = "../../../rust-runtime/aws-smithy-types", features = ["http-body-0-4-x"] } aws-types = { path = "../aws-types" } bytes = "1.1" http = "0.2.3" diff --git a/aws/rust-runtime/aws-http/src/lib.rs b/aws/rust-runtime/aws-http/src/lib.rs index 4c0f72080f..a5a670988c 100644 --- a/aws/rust-runtime/aws-http/src/lib.rs +++ b/aws/rust-runtime/aws-http/src/lib.rs @@ -19,6 +19,3 @@ pub mod user_agent; /// AWS-specific content-encoding tools pub mod content_encoding; - -/// AWS-specific request ID support -pub mod request_id; diff --git a/aws/rust-runtime/aws-inlineable/src/s3_request_id.rs b/aws/rust-runtime/aws-inlineable/src/s3_request_id.rs index 63e368d9ad..20962244b0 100644 --- a/aws/rust-runtime/aws-inlineable/src/s3_request_id.rs +++ b/aws/rust-runtime/aws-inlineable/src/s3_request_id.rs @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -use aws_smithy_http::http::HttpHeaders; use aws_smithy_runtime_api::client::result::SdkError; use aws_smithy_runtime_api::http::{Headers, Response}; use aws_smithy_types::error::metadata::{ @@ -21,14 +20,11 @@ pub trait RequestIdExt { fn extended_request_id(&self) -> Option<&str>; } -impl RequestIdExt for SdkError -where - R: HttpHeaders, -{ +impl RequestIdExt for SdkError { fn extended_request_id(&self) -> Option<&str> { match self { - Self::ResponseError(err) => err.raw().http_headers().extended_request_id(), - Self::ServiceError(err) => err.raw().http_headers().extended_request_id(), + Self::ResponseError(err) => err.raw().headers().extended_request_id(), + Self::ServiceError(err) => err.raw().headers().extended_request_id(), _ => None, } } diff --git a/aws/rust-runtime/aws-types/external-types.toml b/aws/rust-runtime/aws-types/external-types.toml index e5e613b5ae..6afb663dfd 100644 --- a/aws/rust-runtime/aws-types/external-types.toml +++ b/aws/rust-runtime/aws-types/external-types.toml @@ -9,9 +9,11 @@ allowed_external_types = [ "aws_smithy_runtime_api::client::http::SharedHttpClient", "aws_smithy_runtime_api::client::identity::ResolveCachedIdentity", "aws_smithy_runtime_api::client::identity::SharedIdentityCache", + "aws_smithy_runtime_api::http::headers::Headers", "aws_smithy_types::config_bag::storable::Storable", "aws_smithy_types::config_bag::storable::StoreReplace", "aws_smithy_types::config_bag::storable::Storer", + "aws_smithy_types::error::metadata::Builder", "aws_smithy_types::retry::RetryConfig", "aws_smithy_types::timeout::TimeoutConfig", ] diff --git a/aws/rust-runtime/aws-types/src/lib.rs b/aws/rust-runtime/aws-types/src/lib.rs index e6a0a69dcd..b3fbda83f3 100644 --- a/aws/rust-runtime/aws-types/src/lib.rs +++ b/aws/rust-runtime/aws-types/src/lib.rs @@ -20,6 +20,7 @@ pub mod endpoint_config; #[doc(hidden)] pub mod os_shim_internal; pub mod region; +pub mod request_id; pub mod sdk_config; pub use sdk_config::SdkConfig; diff --git a/aws/rust-runtime/aws-http/src/request_id.rs b/aws/rust-runtime/aws-types/src/request_id.rs similarity index 92% rename from aws/rust-runtime/aws-http/src/request_id.rs rename to aws/rust-runtime/aws-types/src/request_id.rs index ac9e5ac7d9..ed56612984 100644 --- a/aws/rust-runtime/aws-http/src/request_id.rs +++ b/aws/rust-runtime/aws-types/src/request_id.rs @@ -3,10 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -use aws_smithy_http::http::HttpHeaders; -use aws_smithy_runtime_api::client::orchestrator::HttpResponse; +//! AWS-specific request ID support + use aws_smithy_runtime_api::client::result::SdkError; use aws_smithy_runtime_api::http::Headers; +use aws_smithy_runtime_api::http::Response; use aws_smithy_types::error::metadata::{ Builder as ErrorMetadataBuilder, ErrorMetadata, ProvideErrorMetadata, }; @@ -21,14 +22,11 @@ pub trait RequestId { fn request_id(&self) -> Option<&str>; } -impl RequestId for SdkError -where - R: HttpHeaders, -{ +impl RequestId for SdkError { fn request_id(&self) -> Option<&str> { match self { - Self::ResponseError(err) => err.raw().http_headers().request_id(), - Self::ServiceError(err) => err.raw().http_headers().request_id(), + Self::ResponseError(err) => err.raw().headers().request_id(), + Self::ServiceError(err) => err.raw().headers().request_id(), _ => None, } } @@ -46,7 +44,7 @@ impl RequestId for Unhandled { } } -impl RequestId for HttpResponse { +impl RequestId for Response { fn request_id(&self) -> Option<&str> { self.headers().request_id() } @@ -84,6 +82,7 @@ pub fn apply_request_id(builder: ErrorMetadataBuilder, headers: &Headers) -> Err #[cfg(test)] mod tests { use super::*; + use aws_smithy_runtime_api::client::orchestrator::HttpResponse; use aws_smithy_types::body::SdkBody; use http::{HeaderValue, Response}; diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRequestIdDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRequestIdDecorator.kt index 0b496ce2c9..b08e8e495e 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRequestIdDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRequestIdDecorator.kt @@ -19,7 +19,7 @@ class AwsRequestIdDecorator : BaseRequestIdDecorator() { override val accessorFunctionName: String = "request_id" private fun requestIdModule(codegenContext: ClientCodegenContext): RuntimeType = - AwsRuntimeType.awsHttp(codegenContext.runtimeConfig).resolve("request_id") + AwsRuntimeType.awsTypes(codegenContext.runtimeConfig).resolve("request_id") override fun accessorTrait(codegenContext: ClientCodegenContext): RuntimeType = requestIdModule(codegenContext).resolve("RequestId") diff --git a/rust-runtime/aws-smithy-http/src/http.rs b/rust-runtime/aws-smithy-http/src/http.rs deleted file mode 100644 index 257a250e01..0000000000 --- a/rust-runtime/aws-smithy-http/src/http.rs +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -//! Types for abstracting over HTTP requests and responses. - -use aws_smithy_runtime_api::client::orchestrator::HttpResponse; -use aws_smithy_runtime_api::http::Headers; - -/// Trait for accessing HTTP headers. -/// -/// Useful for generic impls so that they can access headers via trait bounds. -pub trait HttpHeaders { - /// Returns a reference to the associated header map. - fn http_headers(&self) -> &Headers; - - /// Returns a mutable reference to the associated header map. - fn http_headers_mut(&mut self) -> &mut Headers; -} - -impl HttpHeaders for HttpResponse { - fn http_headers(&self) -> &Headers { - self.headers() - } - - fn http_headers_mut(&mut self) -> &mut Headers { - self.headers_mut() - } -} diff --git a/rust-runtime/aws-smithy-http/src/lib.rs b/rust-runtime/aws-smithy-http/src/lib.rs index 13318a5e99..3b6113037c 100644 --- a/rust-runtime/aws-smithy-http/src/lib.rs +++ b/rust-runtime/aws-smithy-http/src/lib.rs @@ -35,7 +35,6 @@ pub mod endpoint; #[doc(hidden)] pub mod futures_stream_adapter; pub mod header; -pub mod http; pub mod label; pub mod operation; pub mod query;