Unverified Commit d14357c2 authored by John DiSanti's avatar John DiSanti Committed by GitHub
Browse files

Generate `RequestSerializer` traits for client operations (#2510)

* Clean up client deserialization generation logic

* Generate `RequestSerializer` traits

* Fix property access issue for customizations

* Move `aws-smithy-runtime-test` into `aws/sra-test`

* Generate operation runtime plugins to register ser/de

* Add `send_v2` to fluent builders that uses the orchestrator

* Fixes
parent aae9ee1a
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Compani
import software.amazon.smithy.rust.codegen.core.rustlang.DependencyScope
import software.amazon.smithy.rust.codegen.core.rustlang.Writable
import software.amazon.smithy.rust.codegen.core.rustlang.writable
import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig
import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization
import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection
import software.amazon.smithy.rust.codegen.core.testutil.testDependenciesOnly
@@ -56,8 +55,8 @@ class IntegrationTestDecorator : ClientCodegenDecorator {
            val hasTests = Files.exists(testPackagePath.resolve("tests"))
            val hasBenches = Files.exists(testPackagePath.resolve("benches"))
            baseCustomizations + IntegrationTestDependencies(
                codegenContext,
                moduleName,
                codegenContext.runtimeConfig,
                hasTests,
                hasBenches,
            )
@@ -68,18 +67,18 @@ class IntegrationTestDecorator : ClientCodegenDecorator {
}

class IntegrationTestDependencies(
    private val codegenContext: ClientCodegenContext,
    private val moduleName: String,
    private val runtimeConfig: RuntimeConfig,
    private val hasTests: Boolean,
    private val hasBenches: Boolean,
) : LibRsCustomization() {
    override fun section(section: LibRsSection) = when (section) {
        is LibRsSection.Body -> testDependenciesOnly {
            if (hasTests) {
                val smithyClient = CargoDependency.smithyClient(runtimeConfig)
                val smithyClient = CargoDependency.smithyClient(codegenContext.runtimeConfig)
                    .copy(features = setOf("test-util"), scope = DependencyScope.Dev)
                addDependency(smithyClient)
                addDependency(CargoDependency.smithyProtocolTestHelpers(runtimeConfig))
                addDependency(CargoDependency.smithyProtocolTestHelpers(codegenContext.runtimeConfig))
                addDependency(SerdeJson)
                addDependency(Tokio)
                addDependency(FuturesUtil)
@@ -99,7 +98,7 @@ class IntegrationTestDependencies(

    private fun serviceSpecificCustomizations(): List<LibRsCustomization> = when (moduleName) {
        "transcribestreaming" -> listOf(TranscribeTestDependencies())
        "s3" -> listOf(S3TestDependencies())
        "s3" -> listOf(S3TestDependencies(codegenContext))
        else -> emptyList()
    }
}
@@ -113,7 +112,7 @@ class TranscribeTestDependencies : LibRsCustomization() {
        }
}

class S3TestDependencies : LibRsCustomization() {
class S3TestDependencies(private val codegenContext: ClientCodegenContext) : LibRsCustomization() {
    override fun section(section: LibRsSection): Writable =
        writable {
            addDependency(AsyncStd)
@@ -124,5 +123,12 @@ class S3TestDependencies : LibRsCustomization() {
            addDependency(TempFile)
            addDependency(TracingAppender)
            addDependency(TracingTest)

            // TODO(enableNewSmithyRuntime): These additional dependencies may not be needed anymore when removing this flag
            // depending on if the sra-test is kept around or not.
            if (codegenContext.settings.codegenConfig.enableNewSmithyRuntime) {
                addDependency(CargoDependency.smithyRuntime(codegenContext.runtimeConfig).toDevDependency())
                addDependency(CargoDependency.smithyRuntimeApi(codegenContext.runtimeConfig).toDevDependency())
            }
        }
}
+0 −1
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@
# `./gradlew -Paws.fullsdk=true :aws:sdk:assemble` these tests are copied into their respective Service crates.
[workspace]
members = [
    "aws-smithy-runtime-test",
    "dynamodb",
    "ec2",
    "glacier",
+0 −24
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_runtime_api::client::orchestrator::BoxError;
use aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
use aws_smithy_runtime_api::config_bag::ConfigBag;

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

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

impl RuntimePlugin for GetObjectAuthOrc {
    fn configure(&self, _cfg: &mut ConfigBag) -> Result<(), BoxError> {
        // TODO(orchestrator) put an auth orchestrator in the bag
        Ok(())
    }
}
+0 −44
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_client::conns::Https;
use aws_smithy_client::hyper_ext::Adapter;
use aws_smithy_http::body::SdkBody;
use aws_smithy_runtime_api::client::orchestrator::{
    BoxError, BoxFallibleFut, Connection, HttpRequest,
};
use aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
use aws_smithy_runtime_api::config_bag::ConfigBag;

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

impl RuntimePlugin for HyperConnection {
    fn configure(&self, _cfg: &mut ConfigBag) -> Result<(), BoxError> {
        // TODO(orchestrator) put a connection in the bag
        Ok(())
    }
}

impl HyperConnection {
    pub fn new() -> Self {
        Self {
            _adapter: Adapter::builder().build(aws_smithy_client::conns::https()),
        }
    }
}

impl Connection for HyperConnection {
    fn call(
        &self,
        _req: &mut HttpRequest,
        _cfg: &ConfigBag,
    ) -> BoxFallibleFut<http::Response<SdkBody>> {
        todo!("hyper's connector wants to take ownership of req");
        // self.adapter.call(req)
    }
}
+0 −35
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_runtime_api::client::interceptors::context::OutputOrError;
use aws_smithy_runtime_api::client::orchestrator::{BoxError, HttpResponse, ResponseDeserializer};
use aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
use aws_smithy_runtime_api::config_bag::ConfigBag;

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

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

impl RuntimePlugin for GetObjectResponseDeserializer {
    fn configure(&self, _cfg: &mut ConfigBag) -> Result<(), BoxError> {
        // TODO(orchestrator) put a deserializer in the bag
        Ok(())
    }
}

impl ResponseDeserializer for GetObjectResponseDeserializer {
    fn deserialize_streaming(&self, _response: &mut HttpResponse) -> Option<OutputOrError> {
        todo!()
    }

    fn deserialize_nonstreaming(&self, _response: &HttpResponse) -> OutputOrError {
        todo!()
    }
}
Loading