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

Move result and connection from aws-smithy-http to aws-smithy-runtime-api #3103

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -498,3 +498,11 @@ message = "`ByteStream::poll_next` is now feature-gated. You can turn on a cargo
references = ["smithy-rs#3033", "smithy-rs#3088"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "all" }
author = "ysaito1001"

[[smithy-rs]]
message = """
The [`connection`](https://docs.rs/aws-smithy-http/latest/aws_smithy_http/connection/index.html) and [`result`](https://docs.rs/aws-smithy-http/latest/aws_smithy_http/result/index.html) modules in `aws-smithy-http` have been moved to `aws-smithy-runtime-api`. Type aliases for all affected pub items, except for a trait, are left in `aws-smithy-http` for backwards compatibility but are deprecated. Due to lack of trait aliases, the moved trait `CreateUnhandledError` needs to be used from `aws-smithy-runtime-api`.
"""
references = ["smithy-rs#3092", "smithy-rs#3093"]
meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client" }
author = "ysaito1001"
2 changes: 1 addition & 1 deletion aws/rust-runtime/aws-config/external-types.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ allowed_external_types = [
"aws_smithy_async::time::TimeSource",
"aws_smithy_http::endpoint",
"aws_smithy_http::endpoint::error::InvalidEndpointError",
"aws_smithy_http::result::SdkError",
"aws_smithy_runtime_api::client::result::SdkError",
"aws_smithy_runtime::client::identity::cache::IdentityCache",
"aws_smithy_runtime::client::identity::cache::lazy::LazyCacheBuilder",
"aws_smithy_runtime_api::client::dns::ResolveDns",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::json_credentials::{parse_json_credentials, JsonCredentials, Refreshab
use crate::provider_config::ProviderConfig;
use aws_credential_types::provider::{self, error::CredentialsError};
use aws_credential_types::Credentials;
use aws_smithy_http::result::SdkError;
use aws_smithy_runtime::client::orchestrator::operation::Operation;
use aws_smithy_runtime::client::retries::classifiers::{
HttpStatusCodeClassifier, TransientErrorClassifier,
Expand All @@ -22,6 +21,7 @@ use aws_smithy_runtime_api::client::interceptors::context::{Error, InterceptorCo
use aws_smithy_runtime_api::client::orchestrator::{
HttpResponse, OrchestratorError, SensitiveOutput,
};
use aws_smithy_runtime_api::client::result::SdkError;
use aws_smithy_runtime_api::client::retries::classifiers::ClassifyRetry;
use aws_smithy_runtime_api::client::retries::classifiers::RetryAction;
use aws_smithy_runtime_api::client::runtime_plugin::StaticRuntimePlugin;
Expand Down
6 changes: 3 additions & 3 deletions aws/rust-runtime/aws-config/src/imds/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ use crate::provider_config::ProviderConfig;
use crate::PKG_VERSION;
use aws_http::user_agent::{ApiMetadata, AwsUserAgent};
use aws_runtime::user_agent::UserAgentInterceptor;
use aws_smithy_http::result::ConnectorError;
use aws_smithy_http::result::SdkError;
use aws_smithy_runtime::client::orchestrator::operation::Operation;
use aws_smithy_runtime::client::retries::strategy::StandardRetryStrategy;
use aws_smithy_runtime_api::client::auth::AuthSchemeOptionResolverParams;
Expand All @@ -25,6 +23,8 @@ use aws_smithy_runtime_api::client::interceptors::context::InterceptorContext;
use aws_smithy_runtime_api::client::orchestrator::{
HttpRequest, OrchestratorError, SensitiveOutput,
};
use aws_smithy_runtime_api::client::result::ConnectorError;
use aws_smithy_runtime_api::client::result::SdkError;
use aws_smithy_runtime_api::client::retries::classifiers::{
ClassifyRetry, RetryAction, SharedRetryClassifier,
};
Expand Down Expand Up @@ -582,7 +582,6 @@ pub(crate) mod test {
use crate::provider_config::ProviderConfig;
use aws_smithy_async::rt::sleep::TokioSleep;
use aws_smithy_async::test_util::{instant_time_and_sleep, InstantSleep};
use aws_smithy_http::result::ConnectorError;
use aws_smithy_runtime::client::http::test_util::{
capture_request, ReplayEvent, StaticReplayClient,
};
Expand All @@ -593,6 +592,7 @@ pub(crate) mod test {
use aws_smithy_runtime_api::client::orchestrator::{
HttpRequest, HttpResponse, OrchestratorError,
};
use aws_smithy_runtime_api::client::result::ConnectorError;
use aws_smithy_runtime_api::client::retries::classifiers::{ClassifyRetry, RetryAction};
use aws_smithy_types::body::SdkBody;
use aws_smithy_types::error::display::DisplayErrorContext;
Expand Down
2 changes: 1 addition & 1 deletion aws/rust-runtime/aws-config/src/imds/client/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//! Error types for [`ImdsClient`](crate::imds::client::Client)
use aws_smithy_http::endpoint::error::InvalidEndpointError;
use aws_smithy_http::result::SdkError;
use aws_smithy_runtime_api::client::orchestrator::HttpResponse;
use aws_smithy_runtime_api::client::result::SdkError;
use aws_smithy_types::body::SdkBody;
use std::error::Error;
use std::fmt;
Expand Down
2 changes: 1 addition & 1 deletion aws/rust-runtime/aws-config/src/sts/assume_role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use aws_sdk_sts::operation::assume_role::builders::AssumeRoleFluentBuilder;
use aws_sdk_sts::operation::assume_role::AssumeRoleError;
use aws_sdk_sts::types::PolicyDescriptorType;
use aws_sdk_sts::Client as StsClient;
use aws_smithy_http::result::SdkError;
use aws_smithy_runtime::client::identity::IdentityCache;
use aws_smithy_runtime_api::client::result::SdkError;
use aws_smithy_types::error::display::DisplayErrorContext;
use aws_types::region::Region;
use aws_types::SdkConfig;
Expand Down
1 change: 1 addition & 0 deletions aws/rust-runtime/aws-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ repository = "https://github.com/awslabs/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-types = { path = "../aws-types" }
bytes = "1.1"
Expand Down
2 changes: 1 addition & 1 deletion aws/rust-runtime/aws-http/src/request_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

use aws_smithy_http::http::HttpHeaders;
use aws_smithy_http::result::SdkError;
use aws_smithy_runtime_api::client::result::SdkError;
use aws_smithy_types::error::metadata::{
Builder as ErrorMetadataBuilder, ErrorMetadata, ProvideErrorMetadata,
};
Expand Down
4 changes: 2 additions & 2 deletions aws/rust-runtime/aws-inlineable/src/s3_request_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

use aws_smithy_http::http::HttpHeaders;
use aws_smithy_http::result::SdkError;
use aws_smithy_runtime_api::client::result::SdkError;
use aws_smithy_types::error::metadata::{
Builder as ErrorMetadataBuilder, ErrorMetadata, ProvideErrorMetadata,
};
Expand Down Expand Up @@ -94,7 +94,7 @@ fn extract_extended_request_id(headers: &HeaderMap<HeaderValue>) -> Option<&str>
#[cfg(test)]
mod test {
use super::*;
use aws_smithy_http::result::SdkError;
use aws_smithy_runtime_api::client::result::SdkError;
use aws_smithy_types::body::SdkBody;
use http::Response;

Expand Down
1 change: 0 additions & 1 deletion aws/rust-runtime/aws-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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-http = { path = "../../../rust-runtime/aws-smithy-http" }
tracing = "0.1"
http = "0.2.6"
# cargo does not support optional test dependencies, so to completely disable rustls
Expand Down
2 changes: 1 addition & 1 deletion aws/sdk/integration-tests/kms/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

use aws_sdk_kms as kms;
use aws_sdk_kms::operation::RequestId;
use aws_smithy_http::result::SdkError;
use aws_smithy_runtime::client::http::test_util::{ReplayEvent, StaticReplayClient};
use aws_smithy_runtime_api::client::result::SdkError;
use aws_smithy_types::body::SdkBody;
use http::header::AUTHORIZATION;
use http::Uri;
Expand Down
2 changes: 1 addition & 1 deletion aws/sdk/integration-tests/kms/tests/retryable_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
use aws_credential_types::Credentials;
use aws_runtime::retries::classifiers::AwsErrorCodeClassifier;
use aws_sdk_kms as kms;
use aws_smithy_http::result::SdkError;
use aws_smithy_runtime::client::http::test_util::infallible_client_fn;
use aws_smithy_runtime_api::client::interceptors::context::{Error, Input, InterceptorContext};
use aws_smithy_runtime_api::client::orchestrator::{HttpResponse, OrchestratorError};
use aws_smithy_runtime_api::client::result::SdkError;
use aws_smithy_runtime_api::client::retries::classifiers::{ClassifyRetry, RetryAction};
use bytes::Bytes;
use kms::operation::create_alias::CreateAliasError;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ use aws_sdk_s3::types::{
use aws_sdk_s3::{Client, Config};
use aws_smithy_async::assert_elapsed;
use aws_smithy_async::rt::sleep::{AsyncSleep, SharedAsyncSleep, Sleep};
use aws_smithy_http::result::SdkError;
use aws_smithy_runtime::client::http::test_util::NeverClient;
use aws_smithy_runtime::test_util::capture_test_logs::capture_test_logs;
use aws_smithy_runtime_api::client::result::SdkError;
use aws_smithy_types::error::display::DisplayErrorContext;
use aws_smithy_types::timeout::TimeoutConfig;
use std::fmt::Debug;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async fn test_s3_signer_query_string_with_all_valid_chars() {
#[ignore]
async fn test_query_strings_are_correctly_encoded() {
use aws_sdk_s3::operation::list_objects_v2::ListObjectsV2Error;
use aws_smithy_http::result::SdkError;
use aws_smithy_runtime_api::client::result::SdkError;

tracing_subscriber::fmt::init();
let config = aws_config::load_from_env().await;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use aws_credential_types::provider::SharedCredentialsProvider;
use aws_credential_types::Credentials;
use aws_smithy_async::rt::sleep::{SharedAsyncSleep, TokioSleep};
use aws_smithy_http::result::SdkError;
use aws_smithy_runtime_api::client::result::SdkError;
use aws_smithy_types::timeout::TimeoutConfig;
use aws_types::region::Region;
use aws_types::SdkConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,14 @@ class RequiredCustomizations : ClientCodegenDecorator {
rustTemplate(
"""
/// Error type returned by the client.
pub use #{SdkError};
pub type SdkError<E, R = #{R}> = #{SdkError}<E, R>;

pub use #{DisplayErrorContext};
pub use #{ProvideErrorMetadata};
""",
"DisplayErrorContext" to RuntimeType.smithyTypes(rc).resolve("error::display::DisplayErrorContext"),
"ProvideErrorMetadata" to RuntimeType.smithyTypes(rc).resolve("error::metadata::ProvideErrorMetadata"),
"R" to RuntimeType.smithyRuntimeApi(rc).resolve("client::orchestrator::HttpResponse"),
"SdkError" to RuntimeType.sdkError(rc),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ class FluentClientGenerator(
"OperationError" to errorType,
"OperationOutput" to outputType,
"SdkError" to RuntimeType.sdkError(runtimeConfig),
"SdkSuccess" to RuntimeType.sdkSuccess(runtimeConfig),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class OperationErrorGenerator(
private val runtimeConfig = symbolProvider.config.runtimeConfig
private val errorMetadata = errorMetadata(symbolProvider.config.runtimeConfig)
private val createUnhandledError =
RuntimeType.smithyHttp(runtimeConfig).resolve("result::CreateUnhandledError")
RuntimeType.smithyRuntimeApi(runtimeConfig).resolve("client::result::CreateUnhandledError")

private fun operationErrors(): List<StructureShape> =
(operationOrEventStream as OperationShape).operationErrors(model).map { it.asStructureShape().get() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ data class RuntimeType(val path: String, val dependency: RustDependency? = null)
fun boxError(runtimeConfig: RuntimeConfig): RuntimeType =
smithyRuntimeApi(runtimeConfig).resolve("box_error::BoxError")

fun sdkError(runtimeConfig: RuntimeConfig): RuntimeType =
smithyRuntimeApi(runtimeConfig).resolve("client::result::SdkError")

fun intercept(runtimeConfig: RuntimeConfig): RuntimeType =
smithyRuntimeApi(runtimeConfig).resolve("client::interceptors::Intercept")

Expand Down Expand Up @@ -436,9 +439,6 @@ data class RuntimeType(val path: String, val dependency: RustDependency? = null)

fun queryFormat(runtimeConfig: RuntimeConfig, func: String) = smithyHttp(runtimeConfig).resolve("query::$func")
fun sdkBody(runtimeConfig: RuntimeConfig): RuntimeType = smithyTypes(runtimeConfig).resolve("body::SdkBody")
fun sdkError(runtimeConfig: RuntimeConfig): RuntimeType = smithyHttp(runtimeConfig).resolve("result::SdkError")
fun sdkSuccess(runtimeConfig: RuntimeConfig): RuntimeType =
smithyHttp(runtimeConfig).resolve("result::SdkSuccess")

fun parseTimestampFormat(
codegenTarget: CodegenTarget,
Expand Down
1 change: 1 addition & 0 deletions rust-runtime/aws-smithy-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ rt-tokio = ["aws-smithy-types/rt-tokio"]

[dependencies]
aws-smithy-eventstream = { path = "../aws-smithy-eventstream", optional = true }
aws-smithy-runtime-api = { path = "../aws-smithy-runtime-api", features = ["client"] }
aws-smithy-types = { path = "../aws-smithy-types", features = ["byte-stream-poll-next", "http-body-0-4-x"] }
bytes = "1"
bytes-utils = "0.1"
Expand Down
1 change: 1 addition & 0 deletions rust-runtime/aws-smithy-http/external-types.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
allowed_external_types = [
"aws_smithy_runtime_api::*",
"aws_smithy_types::*",
"bytes::bytes::Bytes",
"http::error::Error",
Expand Down
4 changes: 2 additions & 2 deletions rust-runtime/aws-smithy-http/src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

//TODO(runtimeCratesVersioningCleanup): Re-point those who use the deprecated type aliases to
// directly depend on `aws_smithy_types` and remove this module.
//TODO(runtimeCratesVersioningCleanup): Keep the following deprecated type aliases for at least
// one release since 0.56.1 and then remove this module.

//! Types for representing the body of an HTTP request or response
Expand Down
4 changes: 2 additions & 2 deletions rust-runtime/aws-smithy-http/src/byte_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

//TODO(runtimeCratesVersioningCleanup): Re-point those who use the deprecated type aliases to
// directly depend on `aws_smithy_types` and remove this module.
//TODO(runtimeCratesVersioningCleanup): Keep the following deprecated type aliases for at least
// one release since 0.56.1 and then remove this module.

//! ByteStream Abstractions
Expand Down
50 changes: 5 additions & 45 deletions rust-runtime/aws-smithy-http/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,11 @@
* SPDX-License-Identifier: Apache-2.0
*/

//! Types related to connection monitoring and management.
//TODO(runtimeCratesVersioningCleanup): Keep the following deprecated type alias for at least
// one release since 0.56.1 and then remove this module.

use std::fmt::{Debug, Formatter};
use std::net::SocketAddr;
use std::sync::Arc;
//! Types related to connection monitoring and management.

/// Metadata that tracks the state of an active connection.
#[derive(Clone)]
pub struct ConnectionMetadata {
is_proxied: bool,
remote_addr: Option<SocketAddr>,
poison_fn: Arc<dyn Fn() + Send + Sync>,
}

impl ConnectionMetadata {
/// Poison this connection, ensuring that it won't be reused.
pub fn poison(&self) {
tracing::info!("smithy connection was poisoned");
(self.poison_fn)()
}

/// Create a new [`ConnectionMetadata`].
pub fn new(
is_proxied: bool,
remote_addr: Option<SocketAddr>,
poison: impl Fn() + Send + Sync + 'static,
) -> Self {
Self {
is_proxied,
remote_addr,
poison_fn: Arc::new(poison),
}
}

/// Get the remote address for this connection, if one is set.
pub fn remote_addr(&self) -> Option<SocketAddr> {
self.remote_addr
}
}

impl Debug for ConnectionMetadata {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("SmithyConnection")
.field("is_proxied", &self.is_proxied)
.field("remote_addr", &self.remote_addr)
.finish()
}
}
#[deprecated(note = "Moved to `aws_smithy_runtime_api::client::connection::ConnectionMetadata`.")]
pub type ConnectionMetadata = aws_smithy_runtime_api::client::connection::ConnectionMetadata;
4 changes: 2 additions & 2 deletions rust-runtime/aws-smithy-http/src/event_stream/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

use crate::result::{ConnectorError, SdkError};
use aws_smithy_eventstream::frame::{
DecodedFrame, Message, MessageFrameDecoder, UnmarshallMessage, UnmarshalledMessage,
};
use aws_smithy_runtime_api::client::result::{ConnectorError, SdkError};
use aws_smithy_types::body::SdkBody;
use bytes::Buf;
use bytes::Bytes;
Expand Down Expand Up @@ -276,9 +276,9 @@ impl<T, E> Receiver<T, E> {
#[cfg(test)]
mod tests {
use super::{Receiver, UnmarshallMessage};
use crate::result::SdkError;
use aws_smithy_eventstream::error::Error as EventStreamError;
use aws_smithy_eventstream::frame::{Header, HeaderValue, Message, UnmarshalledMessage};
use aws_smithy_runtime_api::client::result::SdkError;
use aws_smithy_types::body::SdkBody;
use bytes::Bytes;
use hyper::body::Body;
Expand Down
7 changes: 4 additions & 3 deletions rust-runtime/aws-smithy-http/src/event_stream/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

use crate::result::SdkError;
use aws_smithy_eventstream::frame::{MarshallMessage, SignMessage};
use aws_smithy_runtime_api::client::result::SdkError;
use bytes::Bytes;
use futures_core::Stream;
use std::error::Error as StdError;
Expand Down Expand Up @@ -140,7 +140,8 @@ impl<T, E: StdError + Send + Sync + 'static> MessageStreamAdapter<T, E> {
}

impl<T, E: StdError + Send + Sync + 'static> Stream for MessageStreamAdapter<T, E> {
type Item = Result<Bytes, SdkError<E>>;
type Item =
Result<Bytes, SdkError<E, aws_smithy_runtime_api::client::orchestrator::HttpResponse>>;

fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
match self.stream.as_mut().poll_next(cx) {
Expand Down Expand Up @@ -195,12 +196,12 @@ impl<T, E: StdError + Send + Sync + 'static> Stream for MessageStreamAdapter<T,
mod tests {
use super::MarshallMessage;
use crate::event_stream::{EventStreamSender, MessageStreamAdapter};
use crate::result::SdkError;
use async_stream::stream;
use aws_smithy_eventstream::error::Error as EventStreamError;
use aws_smithy_eventstream::frame::{
Header, HeaderValue, Message, NoOpSigner, SignMessage, SignMessageError,
};
use aws_smithy_runtime_api::client::result::SdkError;
use bytes::Bytes;
use futures_core::Stream;
use futures_util::stream::StreamExt;
Expand Down
Loading
Loading