Skip to content

Commit

Permalink
Add: runtime plugin placeholder code to Smithy Orchestrator (#2465)
Browse files Browse the repository at this point in the history
* update: add placeholder impl of runtime plugins
update: separate client and operation interceptors

* add: stub endpoint orchestrator to integration test

* add: endpoints runtime plugin to integration test

* fix: compilation issues

* format: run cargo fmt
  • Loading branch information
Velfi authored Mar 17, 2023
1 parent 48eda40 commit b4a9698
Show file tree
Hide file tree
Showing 14 changed files with 465 additions and 216 deletions.
66 changes: 35 additions & 31 deletions aws/sdk/integration-tests/aws-smithy-runtime-test/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,56 @@
*/

use aws_smithy_http::body::SdkBody;
use aws_smithy_runtime::{AuthOrchestrator, BoxError, ConfigBag};
use aws_smithy_runtime::{AuthOrchestrator, BoxError};
use aws_smithy_runtime_api::config_bag::ConfigBag;
use aws_smithy_runtime_api::runtime_plugin::RuntimePlugin;

#[derive(Debug)]
pub struct GetObjectAuthOrc {}

impl GetObjectAuthOrc {
pub fn _new() -> Self {
pub fn new() -> Self {
Self {}
}
}

impl RuntimePlugin for GetObjectAuthOrc {
fn configure(&self, _cfg: &mut ConfigBag) -> Result<(), BoxError> {
todo!()
}
}

impl AuthOrchestrator<http::Request<SdkBody>> for GetObjectAuthOrc {
fn auth_request(
&self,
_req: &mut http::Request<SdkBody>,
_cfg: &ConfigBag,
) -> Result<(), BoxError> {
todo!()

// let signer = SigV4Signer::new();
// let operation_config = props
// .get::<OperationSigningConfig>()
// .ok_or("missing signing config".to_string())?;
//
// let (operation_config, request_config, creds) = match &operation_config.signing_requirements
// {
// SigningRequirements::Disabled => return Ok(()),
// SigningRequirements::Optional => {
// match aws_sig_auth::middleware::signing_config(props) {
// Ok(parts) => parts,
// Err(_) => return Ok(()),
// }
// }
// SigningRequirements::Required => {
// aws_sig_auth::middleware::signing_config(props).map_err(Box::new)?
// }
// };
//
// let _signature = signer
// .sign(&operation_config, &request_config, &creds, req)
// .expect("signing goes just fine");
//
// Ok(())
}
}

// signer: Arc::new(|req: &mut http::Request<SdkBody>, props: &PropertyBag| {
// use aws_smithy_orchestrator::auth::error::Error;
//
// let signer = SigV4Signer::new();
// let operation_config = props
// .get::<OperationSigningConfig>()
// .ok_or(Error::SignRequest("missing signing config".into()))?;
//
// let (operation_config, request_config, creds) = match &operation_config
// .signing_requirements
// {
// SigningRequirements::Disabled => return Ok(()),
// SigningRequirements::Optional => {
// match aws_sig_auth::middleware::signing_config(props) {
// Ok(parts) => parts,
// Err(_) => return Ok(()),
// }
// }
// SigningRequirements::Required => aws_sig_auth::middleware::signing_config(props)
// .map_err(|err| Error::SignRequest(Box::new(err)))?,
// };
//
// let _signature = signer
// .sign(&operation_config, &request_config, &creds, req)
// .expect("signing goes just fine");
//
// Ok(())
// }),
12 changes: 10 additions & 2 deletions aws/sdk/integration-tests/aws-smithy-runtime-test/src/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@
use aws_smithy_client::conns::Https;
use aws_smithy_client::hyper_ext::Adapter;
use aws_smithy_http::body::SdkBody;
use aws_smithy_runtime::{BoxFallibleFut, ConfigBag, Connection};
use aws_smithy_runtime::{BoxError, BoxFallibleFut, Connection};
use aws_smithy_runtime_api::config_bag::ConfigBag;
use aws_smithy_runtime_api::runtime_plugin::RuntimePlugin;

#[derive(Debug)]
pub struct HyperConnection {
_adapter: Adapter<Https>,
}

impl RuntimePlugin for HyperConnection {
fn configure(&self, _cfg: &mut ConfigBag) -> Result<(), BoxError> {
todo!()
}
}

impl HyperConnection {
pub fn _new() -> Self {
pub fn new() -> Self {
Self {
_adapter: Adapter::builder().build(aws_smithy_client::conns::https()),
}
Expand Down
12 changes: 10 additions & 2 deletions aws/sdk/integration-tests/aws-smithy-runtime-test/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,25 @@

use aws_sdk_s3::operation::get_object::GetObjectOutput;
use aws_smithy_http::body::SdkBody;
use aws_smithy_runtime::{BoxError, ConfigBag, ResponseDeserializer};
use aws_smithy_runtime::{BoxError, ResponseDeserializer};
use aws_smithy_runtime_api::config_bag::ConfigBag;
use aws_smithy_runtime_api::runtime_plugin::RuntimePlugin;

#[derive(Debug)]
pub struct GetObjectResponseDeserializer {}

impl GetObjectResponseDeserializer {
pub fn _new() -> Self {
pub fn new() -> Self {
Self {}
}
}

impl RuntimePlugin for GetObjectResponseDeserializer {
fn configure(&self, _cfg: &mut ConfigBag) -> Result<(), BoxError> {
todo!()
}
}

impl ResponseDeserializer<http::Response<SdkBody>, GetObjectOutput>
for GetObjectResponseDeserializer
{
Expand Down
104 changes: 104 additions & 0 deletions aws/sdk/integration-tests/aws-smithy-runtime-test/src/endpoints.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

use aws_smithy_http::body::SdkBody;
use aws_smithy_runtime::{BoxError, EndpointOrchestrator};
use aws_smithy_runtime_api::config_bag::ConfigBag;
use aws_smithy_runtime_api::runtime_plugin::RuntimePlugin;

#[derive(Debug)]
pub struct GetObjectEndpointOrc {}

impl GetObjectEndpointOrc {
pub fn new() -> Self {
Self {}
}
}

impl RuntimePlugin for GetObjectEndpointOrc {
fn configure(&self, _cfg: &mut ConfigBag) -> Result<(), BoxError> {
todo!()
}
}

impl EndpointOrchestrator<http::Request<SdkBody>> for GetObjectEndpointOrc {
fn resolve_and_apply_endpoint(
&self,
_req: &mut http::Request<SdkBody>,
_cfg: &ConfigBag,
) -> Result<(), BoxError> {
todo!()
// let endpoint = endpoint_resolver.resolve_endpoint(&endpoint_parameters)?;
// let (tx_req, props) = ctx
// .tx_request_mut()
// .expect("We call this after setting the tx request");
//
// // Apply the endpoint
// let uri: Uri = endpoint.url().parse().map_err(|err| {
// ResolveEndpointError::from_source("endpoint did not have a valid uri", err)
// })?;
// apply_endpoint(tx_req.uri_mut(), &uri, props.get::<EndpointPrefix>()).map_err(|err| {
// ResolveEndpointError::message(format!(
// "failed to apply endpoint `{:?}` to request `{:?}`",
// uri, tx_req
// ))
// .with_source(Some(err.into()))
// })?;
// for (header_name, header_values) in endpoint.headers() {
// tx_req.headers_mut().remove(header_name);
// for value in header_values {
// tx_req.headers_mut().insert(
// HeaderName::from_str(header_name).map_err(|err| {
// ResolveEndpointError::message("invalid header name")
// .with_source(Some(err.into()))
// })?,
// HeaderValue::from_str(value).map_err(|err| {
// ResolveEndpointError::message("invalid header value")
// .with_source(Some(err.into()))
// })?,
// );
// }
// }
}

fn resolve_auth_schemes(&self) -> Result<Vec<String>, BoxError> {
todo!()

// let endpoint = endpoint_resolver
// .resolve_endpoint(params)
// .map_err(SdkError::construction_failure)?;
// let auth_schemes = match endpoint.properties().get("authSchemes") {
// Some(Document::Array(schemes)) => schemes,
// None => {
// return Ok(vec![]);
// }
// _other => {
// return Err(SdkError::construction_failure(
// "expected bad things".to_string(),
// ));
// }
// };
// let auth_schemes = auth_schemes
// .iter()
// .flat_map(|doc| match doc {
// Document::Object(map) => Some(map),
// _ => None,
// })
// .map(|it| {
// let name = match it.get("name") {
// Some(Document::String(s)) => Some(s.as_str()),
// _ => None,
// };
// AuthSchemeOptions::new(
// name.unwrap().to_string(),
// /* there are no identity properties yet */
// None,
// Some(Document::Object(it.clone())),
// )
// })
// .collect::<Vec<_>>();
// Ok(auth_schemes)
}
}
26 changes: 17 additions & 9 deletions aws/sdk/integration-tests/aws-smithy-runtime-test/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
mod auth;
mod conn;
mod de;
mod endpoints;
mod interceptors;
mod retry;
mod ser;

use aws_sdk_s3::operation::get_object::{GetObjectInput, GetObjectOutput};
use aws_sdk_s3::types::ChecksumMode;
use aws_smithy_http::body::SdkBody;
use aws_smithy_runtime::{invoke, BoxError, ConfigBag};
use aws_smithy_runtime::{invoke, BoxError};
use aws_smithy_runtime_api::config_bag::ConfigBag;
use aws_smithy_runtime_api::interceptors::Interceptors;
use aws_smithy_runtime_api::runtime_plugin::RuntimePlugins;
use std::str::from_utf8;
use tracing::info;

Expand All @@ -25,28 +28,33 @@ async fn main() -> Result<(), BoxError> {
// Create the config we'll need to send the request + the request itself
let sdk_config = aws_config::load_from_env().await;
let _service_config = aws_sdk_s3::Config::from(&sdk_config);
// TODO(smithy-orchestrator-codegen) Make it so these are added by default for S3
// .with_runtime_plugin(auth::GetObjectAuthOrc::new())
// .with_runtime_plugin(conn::HyperConnection::new());

let input = GetObjectInput::builder()
.bucket("zhessler-test-bucket")
.key("1000-lines.txt")
.checksum_mode(ChecksumMode::Enabled)
// TODO(smithy-orchestrator-codegen) Make it so these are added by default for this S3 operation
// .with_runtime_plugin(retry::GetObjectRetryStrategy::new())
// .with_runtime_plugin(de::GetObjectResponseDeserializer::new())
// .with_runtime_plugin(ser::GetObjectInputSerializer::new())
.build()?;

let mut runtime_plugins = RuntimePlugins::new();

// TODO(smithy-orchestrator-codegen) Make it so these are added by default for S3
runtime_plugins
.with_client_plugin(auth::GetObjectAuthOrc::new())
.with_client_plugin(conn::HyperConnection::new())
// TODO(smithy-orchestrator-codegen) Make it so these are added by default for this S3 operation
.with_operation_plugin(endpoints::GetObjectEndpointOrc::new())
.with_operation_plugin(retry::GetObjectRetryStrategy::new())
.with_operation_plugin(de::GetObjectResponseDeserializer::new())
.with_operation_plugin(ser::GetObjectInputSerializer::new());

let mut cfg = ConfigBag::base();
let mut interceptors: Interceptors<
GetObjectInput,
http::Request<SdkBody>,
http::Response<SdkBody>,
Result<GetObjectOutput, BoxError>,
> = Interceptors::new();
let res = invoke(input, &mut interceptors, &mut cfg).await?;
let res = invoke(input, &mut interceptors, &runtime_plugins, &mut cfg).await?;

let body = res.body.collect().await?.to_vec();
let body_string = from_utf8(&body)?;
Expand Down
26 changes: 17 additions & 9 deletions aws/sdk/integration-tests/aws-smithy-runtime-test/src/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@
*/

use aws_sdk_s3::operation::get_object::{GetObjectError, GetObjectOutput};
use aws_smithy_runtime::{BoxError, ConfigBag, RetryStrategy};

// retry_classifier: Arc::new(
// |res: Result<&SdkSuccess<GetObjectOutput>, &SdkError<GetObjectError>>| -> RetryKind {
// let classifier = AwsResponseRetryClassifier::new();
// classifier.classify_retry(res)
// },
// ),
use aws_smithy_runtime::{BoxError, RetryStrategy};
use aws_smithy_runtime_api::config_bag::ConfigBag;
use aws_smithy_runtime_api::runtime_plugin::RuntimePlugin;

#[derive(Debug)]
pub struct GetObjectRetryStrategy {}

impl GetObjectRetryStrategy {
pub fn _new() -> Self {
pub fn new() -> Self {
Self {}
}
}

impl RuntimePlugin for GetObjectRetryStrategy {
fn configure(&self, _cfg: &mut ConfigBag) -> Result<(), BoxError> {
todo!()
}
}

impl RetryStrategy<Result<GetObjectOutput, GetObjectError>> for GetObjectRetryStrategy {
fn should_retry(
&self,
Expand All @@ -31,3 +32,10 @@ impl RetryStrategy<Result<GetObjectOutput, GetObjectError>> for GetObjectRetrySt
todo!()
}
}

// retry_classifier: Arc::new(
// |res: Result<&SdkSuccess<GetObjectOutput>, &SdkError<GetObjectError>>| -> RetryKind {
// let classifier = AwsResponseRetryClassifier::new();
// classifier.classify_retry(res)
// },
// ),
12 changes: 10 additions & 2 deletions aws/sdk/integration-tests/aws-smithy-runtime-test/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,25 @@

use aws_sdk_s3::operation::get_object::GetObjectInput;
use aws_smithy_http::body::SdkBody;
use aws_smithy_runtime::{BoxError, ConfigBag, RequestSerializer};
use aws_smithy_runtime::{BoxError, RequestSerializer};
use aws_smithy_runtime_api::config_bag::ConfigBag;
use aws_smithy_runtime_api::runtime_plugin::RuntimePlugin;

#[derive(Debug)]
pub struct GetObjectInputSerializer {}

impl GetObjectInputSerializer {
pub fn _new() -> Self {
pub fn new() -> Self {
Self {}
}
}

impl RuntimePlugin for GetObjectInputSerializer {
fn configure(&self, _cfg: &mut ConfigBag) -> Result<(), BoxError> {
todo!()
}
}

impl RequestSerializer<GetObjectInput, http::Request<SdkBody>> for GetObjectInputSerializer {
fn serialize_request(
&self,
Expand Down
1 change: 1 addition & 0 deletions rust-runtime/aws-smithy-runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ publish = false

[dependencies]
aws-smithy-types = { path = "../aws-smithy-types" }
aws-smithy-http = { path = "../aws-smithy-http" }
tokio = { version = "1.25", features = ["sync"] }

[package.metadata.docs.rs]
Expand Down
Loading

0 comments on commit b4a9698

Please sign in to comment.