Loading codegen/src/aws_conv.rs +0 −1 Original line number Diff line number Diff line Loading @@ -24,7 +24,6 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes) { match name.as_str() { "SelectObjectContentRequest" => continue, "SelectObjectContentInput" => continue, "LifecycleExpiration" => continue, _ => {} } Loading crates/s3s-aws/Cargo.toml +6 −5 Original line number Diff line number Diff line Loading @@ -11,13 +11,14 @@ categories = ["web-programming", "web-programming::http-server"] [dependencies] async-trait = "0.1.73" aws-sdk-s3 = "0.34.0" aws-smithy-http = { version = "0.56.1", features = ["event-stream"] } aws-smithy-runtime-api = { version = "0.56.1", features = ["client"] } aws-smithy-types = "0.56.1" aws-smithy-types-convert = { version = "0.56.1", features = ["convert-time"] } aws-sdk-s3 = "1.12.0" aws-smithy-http = { version = "0.60.2", features = ["event-stream"] } aws-smithy-runtime-api = { version = "1.1.2", features = ["client", "http-02x"] } aws-smithy-types = { version = "1.1.2", features = ["http-body-0-4-x"] } aws-smithy-types-convert = { version = "0.60.2", features = ["convert-time"] } bytes = "1.4.0" futures = { version = "0.3.28", default-features = false, features = ["std"] } http-body = "0.4.5" hyper = "0.14.27" s3s = { version = "0.9.0-dev", path = "../s3s" } sync_wrapper = "0.1.2" Loading crates/s3s-aws/src/body.rs +2 −2 Original line number Diff line number Diff line Loading @@ -2,13 +2,13 @@ use std::pin::Pin; use std::task::Context; use std::task::Poll; use aws_smithy_http::body::SdkBody; use aws_smithy_types::body::SdkBody; use futures::Stream; use hyper::body::HttpBody; pub fn s3s_body_into_sdk_body(body: s3s::Body) -> SdkBody { SdkBody::from_dyn(body.boxed()) SdkBody::from_body_0_4(body.boxed()) } pub fn sdk_body_into_s3s_body(body: SdkBody) -> s3s::Body { Loading crates/s3s-aws/src/connector.rs +22 −30 Original line number Diff line number Diff line use crate::body::{s3s_body_into_sdk_body, sdk_body_into_s3s_body}; use s3s::service::SharedS3Service; use s3s::{S3Error, S3Result}; use s3s::S3Result; use std::ops::Not; use std::task::{Context, Poll}; use aws_smithy_http::body::SdkBody; use aws_smithy_http::byte_stream::ByteStream; use aws_smithy_http::result::ConnectorError; use aws_smithy_runtime_api::client::http::{HttpConnector, HttpConnectorFuture}; use aws_smithy_runtime_api::client::orchestrator::HttpRequest as AwsHttpRequest; use aws_smithy_runtime_api::client::orchestrator::HttpResponse as AwsHttpResponse; use aws_smithy_runtime_api::client::result::ConnectorError; use hyper::header::HOST; use hyper::http; use hyper::service::Service; use hyper::{Request, Response}; use futures::future::BoxFuture; #[derive(Clone)] #[derive(Debug, Clone)] pub struct Connector(SharedS3Service); impl From<SharedS3Service> for Connector { Loading @@ -24,42 +23,35 @@ impl From<SharedS3Service> for Connector { } } fn on_err(e: S3Error) -> ConnectorError { let kind = aws_smithy_types::retry::ErrorKind::ServerError; fn on_err<E>(e: E) -> ConnectorError where E: std::error::Error + Send + Sync + 'static, { let kind = aws_smithy_runtime_api::client::retries::ErrorKind::ServerError; ConnectorError::other(Box::new(e), Some(kind)) } // From <https://github.com/awslabs/aws-sdk-rust/discussions/253#discussioncomment-1478233> impl Service<Request<SdkBody>> for Connector { type Response = Response<SdkBody>; type Error = ConnectorError; type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>; fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { self.0.poll_ready(cx).map_err(on_err) } fn call(&mut self, req: Request<SdkBody>) -> Self::Future { let req = convert_input(req); impl HttpConnector for Connector { fn call(&self, req: AwsHttpRequest) -> HttpConnectorFuture { let service = self.0.clone(); Box::pin(async move { convert_output(service.as_ref().call(req).await) }) HttpConnectorFuture::new_boxed(Box::pin(async move { convert_output(service.as_ref().call(convert_input(req)?).await) })) } } fn convert_input(mut req: Request<SdkBody>) -> Request<s3s::Body> { fn convert_input(req: AwsHttpRequest) -> Result<Request<s3s::Body>, ConnectorError> { let mut req = req.try_into_http02x().map_err(on_err)?; if req.headers().contains_key(HOST).not() { let host = auto_host_header(req.uri()); req.headers_mut().insert(HOST, host); } req.map(|sdk_body| s3s::Body::from(hyper::Body::wrap_stream(ByteStream::from(sdk_body)))) Ok(req.map(sdk_body_into_s3s_body)) } fn convert_output(result: S3Result<Response<s3s::Body>>) -> Result<Response<SdkBody>, ConnectorError> { fn convert_output(result: S3Result<Response<s3s::Body>>) -> Result<AwsHttpResponse, ConnectorError> { match result { Ok(res) => Ok(res.map(|s3s_body| SdkBody::from(hyper::Body::from(s3s_body)))), Ok(res) => res.map(s3s_body_into_sdk_body).try_into().map_err(on_err), Err(e) => Err(on_err(e)), } } Loading crates/s3s-aws/src/conv/builtin.rs +1 −30 Original line number Diff line number Diff line use super::*; use crate::body::s3s_body_into_sdk_body; use crate::body::sdk_body_into_s3s_body; use crate::body::{s3s_body_into_sdk_body, sdk_body_into_s3s_body}; use std::collections::HashMap; use std::convert::Infallible; Loading Loading @@ -192,31 +191,3 @@ impl AwsConversion for s3s::dto::SelectObjectContentInput { .map_err(S3Error::internal_error) } } impl AwsConversion for s3s::dto::LifecycleExpiration { type Target = aws_sdk_s3::types::LifecycleExpiration; type Error = S3Error; fn try_from_aws(x: Self::Target) -> S3Result<Self> { Ok(Self { date: try_from_aws(x.date)?, days: ignore_default(x.days, 0), expired_object_delete_marker: ignore_default(x.expired_object_delete_marker, false), }) } fn try_into_aws(x: Self) -> S3Result<Self::Target> { let mut y = Self::Target::builder(); y = y.set_date(try_into_aws(x.date)?); y = y.set_days(x.days); y = y.set_expired_object_delete_marker(x.expired_object_delete_marker); Ok(y.build()) } } fn ignore_default<T: Eq + Copy>(val: T, default: T) -> Option<T> { if val == default { return None; } Some(val) } Loading
codegen/src/aws_conv.rs +0 −1 Original line number Diff line number Diff line Loading @@ -24,7 +24,6 @@ pub fn codegen(ops: &Operations, rust_types: &RustTypes) { match name.as_str() { "SelectObjectContentRequest" => continue, "SelectObjectContentInput" => continue, "LifecycleExpiration" => continue, _ => {} } Loading
crates/s3s-aws/Cargo.toml +6 −5 Original line number Diff line number Diff line Loading @@ -11,13 +11,14 @@ categories = ["web-programming", "web-programming::http-server"] [dependencies] async-trait = "0.1.73" aws-sdk-s3 = "0.34.0" aws-smithy-http = { version = "0.56.1", features = ["event-stream"] } aws-smithy-runtime-api = { version = "0.56.1", features = ["client"] } aws-smithy-types = "0.56.1" aws-smithy-types-convert = { version = "0.56.1", features = ["convert-time"] } aws-sdk-s3 = "1.12.0" aws-smithy-http = { version = "0.60.2", features = ["event-stream"] } aws-smithy-runtime-api = { version = "1.1.2", features = ["client", "http-02x"] } aws-smithy-types = { version = "1.1.2", features = ["http-body-0-4-x"] } aws-smithy-types-convert = { version = "0.60.2", features = ["convert-time"] } bytes = "1.4.0" futures = { version = "0.3.28", default-features = false, features = ["std"] } http-body = "0.4.5" hyper = "0.14.27" s3s = { version = "0.9.0-dev", path = "../s3s" } sync_wrapper = "0.1.2" Loading
crates/s3s-aws/src/body.rs +2 −2 Original line number Diff line number Diff line Loading @@ -2,13 +2,13 @@ use std::pin::Pin; use std::task::Context; use std::task::Poll; use aws_smithy_http::body::SdkBody; use aws_smithy_types::body::SdkBody; use futures::Stream; use hyper::body::HttpBody; pub fn s3s_body_into_sdk_body(body: s3s::Body) -> SdkBody { SdkBody::from_dyn(body.boxed()) SdkBody::from_body_0_4(body.boxed()) } pub fn sdk_body_into_s3s_body(body: SdkBody) -> s3s::Body { Loading
crates/s3s-aws/src/connector.rs +22 −30 Original line number Diff line number Diff line use crate::body::{s3s_body_into_sdk_body, sdk_body_into_s3s_body}; use s3s::service::SharedS3Service; use s3s::{S3Error, S3Result}; use s3s::S3Result; use std::ops::Not; use std::task::{Context, Poll}; use aws_smithy_http::body::SdkBody; use aws_smithy_http::byte_stream::ByteStream; use aws_smithy_http::result::ConnectorError; use aws_smithy_runtime_api::client::http::{HttpConnector, HttpConnectorFuture}; use aws_smithy_runtime_api::client::orchestrator::HttpRequest as AwsHttpRequest; use aws_smithy_runtime_api::client::orchestrator::HttpResponse as AwsHttpResponse; use aws_smithy_runtime_api::client::result::ConnectorError; use hyper::header::HOST; use hyper::http; use hyper::service::Service; use hyper::{Request, Response}; use futures::future::BoxFuture; #[derive(Clone)] #[derive(Debug, Clone)] pub struct Connector(SharedS3Service); impl From<SharedS3Service> for Connector { Loading @@ -24,42 +23,35 @@ impl From<SharedS3Service> for Connector { } } fn on_err(e: S3Error) -> ConnectorError { let kind = aws_smithy_types::retry::ErrorKind::ServerError; fn on_err<E>(e: E) -> ConnectorError where E: std::error::Error + Send + Sync + 'static, { let kind = aws_smithy_runtime_api::client::retries::ErrorKind::ServerError; ConnectorError::other(Box::new(e), Some(kind)) } // From <https://github.com/awslabs/aws-sdk-rust/discussions/253#discussioncomment-1478233> impl Service<Request<SdkBody>> for Connector { type Response = Response<SdkBody>; type Error = ConnectorError; type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>; fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { self.0.poll_ready(cx).map_err(on_err) } fn call(&mut self, req: Request<SdkBody>) -> Self::Future { let req = convert_input(req); impl HttpConnector for Connector { fn call(&self, req: AwsHttpRequest) -> HttpConnectorFuture { let service = self.0.clone(); Box::pin(async move { convert_output(service.as_ref().call(req).await) }) HttpConnectorFuture::new_boxed(Box::pin(async move { convert_output(service.as_ref().call(convert_input(req)?).await) })) } } fn convert_input(mut req: Request<SdkBody>) -> Request<s3s::Body> { fn convert_input(req: AwsHttpRequest) -> Result<Request<s3s::Body>, ConnectorError> { let mut req = req.try_into_http02x().map_err(on_err)?; if req.headers().contains_key(HOST).not() { let host = auto_host_header(req.uri()); req.headers_mut().insert(HOST, host); } req.map(|sdk_body| s3s::Body::from(hyper::Body::wrap_stream(ByteStream::from(sdk_body)))) Ok(req.map(sdk_body_into_s3s_body)) } fn convert_output(result: S3Result<Response<s3s::Body>>) -> Result<Response<SdkBody>, ConnectorError> { fn convert_output(result: S3Result<Response<s3s::Body>>) -> Result<AwsHttpResponse, ConnectorError> { match result { Ok(res) => Ok(res.map(|s3s_body| SdkBody::from(hyper::Body::from(s3s_body)))), Ok(res) => res.map(s3s_body_into_sdk_body).try_into().map_err(on_err), Err(e) => Err(on_err(e)), } } Loading
crates/s3s-aws/src/conv/builtin.rs +1 −30 Original line number Diff line number Diff line use super::*; use crate::body::s3s_body_into_sdk_body; use crate::body::sdk_body_into_s3s_body; use crate::body::{s3s_body_into_sdk_body, sdk_body_into_s3s_body}; use std::collections::HashMap; use std::convert::Infallible; Loading Loading @@ -192,31 +191,3 @@ impl AwsConversion for s3s::dto::SelectObjectContentInput { .map_err(S3Error::internal_error) } } impl AwsConversion for s3s::dto::LifecycleExpiration { type Target = aws_sdk_s3::types::LifecycleExpiration; type Error = S3Error; fn try_from_aws(x: Self::Target) -> S3Result<Self> { Ok(Self { date: try_from_aws(x.date)?, days: ignore_default(x.days, 0), expired_object_delete_marker: ignore_default(x.expired_object_delete_marker, false), }) } fn try_into_aws(x: Self) -> S3Result<Self::Target> { let mut y = Self::Target::builder(); y = y.set_date(try_into_aws(x.date)?); y = y.set_days(x.days); y = y.set_expired_object_delete_marker(x.expired_object_delete_marker); Ok(y.build()) } } fn ignore_default<T: Eq + Copy>(val: T, default: T) -> Option<T> { if val == default { return None; } Some(val) }