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._
This commit is contained in:
John DiSanti 2023-11-10 18:18:17 -08:00 committed by GitHub
parent a94a5e086e
commit d4e2745cfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 22 additions and 53 deletions

View File

@ -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"

View File

@ -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"

View File

@ -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;

View File

@ -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<E, R> RequestIdExt for SdkError<E, R>
where
R: HttpHeaders,
{
impl<E> RequestIdExt for SdkError<E, Response> {
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,
}
}

View File

@ -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",
]

View File

@ -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;

View File

@ -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<E, R> RequestId for SdkError<E, R>
where
R: HttpHeaders,
{
impl<E> RequestId for SdkError<E, Response> {
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<B> RequestId for Response<B> {
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};

View File

@ -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")

View File

@ -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()
}
}

View File

@ -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;