Unverified Commit b4a96983 authored by Zelda Hessler's avatar Zelda Hessler Committed by GitHub
Browse files

Add: runtime plugin placeholder code to Smithy Orchestrator (#2465)

* 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
parent 48eda404
Loading
Loading
Loading
Loading
+35 −31
Original line number Diff line number Diff line
@@ -4,17 +4,25 @@
 */

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,
@@ -22,19 +30,13 @@ impl AuthOrchestrator<http::Request<SdkBody>> for GetObjectAuthOrc {
        _cfg: &ConfigBag,
    ) -> Result<(), BoxError> {
        todo!()
    }
}

//     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()))?;
        //     .ok_or("missing signing config".to_string())?;
        //
//         let (operation_config, request_config, creds) = match &operation_config
//             .signing_requirements
        // let (operation_config, request_config, creds) = match &operation_config.signing_requirements
        // {
        //     SigningRequirements::Disabled => return Ok(()),
        //     SigningRequirements::Optional => {
@@ -43,8 +45,9 @@ impl AuthOrchestrator<http::Request<SdkBody>> for GetObjectAuthOrc {
        //             Err(_) => return Ok(()),
        //         }
        //     }
//             SigningRequirements::Required => aws_sig_auth::middleware::signing_config(props)
//                 .map_err(|err| Error::SignRequest(Box::new(err)))?,
        //     SigningRequirements::Required => {
        //         aws_sig_auth::middleware::signing_config(props).map_err(Box::new)?
        //     }
        // };
        //
        // let _signature = signer
@@ -52,4 +55,5 @@ impl AuthOrchestrator<http::Request<SdkBody>> for GetObjectAuthOrc {
        //     .expect("signing goes just fine");
        //
        // Ok(())
//     }),
    }
}
+10 −2
Original line number Diff line number Diff line
@@ -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()),
        }
+10 −2
Original line number Diff line number Diff line
@@ -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
{
+104 −0
Original line number Diff line number Diff line
/*
 * 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)
    }
}
+17 −9
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
mod auth;
mod conn;
mod de;
mod endpoints;
mod interceptors;
mod retry;
mod ser;
@@ -13,8 +14,10 @@ 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;

@@ -25,20 +28,25 @@ 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,
@@ -46,7 +54,7 @@ async fn main() -> Result<(), BoxError> {
        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)?;
Loading