Skip to content

Commit

Permalink
Orchestrator ResponseDeserializer codegen and auth (smithy-lang#2494)
Browse files Browse the repository at this point in the history
* Convert interceptor fns to macro invocations

Co-authored-by: John DiSanti <[email protected]>

* Add unmodeled error to ServiceError and bring in EventLog

Co-authored-by: John DiSanti <[email protected]>

* Simplify and test `EventLog`

* Attempt to integrate the event log with the orchestrator

* fix: error type in integration test
update: retry handling in orchestrator

* update: set the runtime plugins to do nothing instead of panic when called on

* Introduce a construct for type erasure

* Eliminate several generics and add phased error handling

* Code generate the `ResponseDeserializer` trait impls

* CI fixes

* Reorganize the new runtime crates

* Create the `Identity` type

* Reorganize orchestrator traits and accessors

* Set up code generated test environment for the new runtime

* Add initial auth orchestration implementation

* Fix clippy lint

* Incorporate feedback

* Fix external types lint

---------

Co-authored-by: Zelda Hessler <[email protected]>
  • Loading branch information
jdisanti and Zelda Hessler authored Mar 27, 2023
1 parent b65a645 commit 6b21e46
Show file tree
Hide file tree
Showing 56 changed files with 2,245 additions and 1,889 deletions.
6 changes: 6 additions & 0 deletions aws/rust-runtime/aws-http/src/request_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ impl<B> RequestId for http::Response<B> {
}
}

impl RequestId for HeaderMap {
fn request_id(&self) -> Option<&str> {
extract_request_id(self)
}
}

impl<O, E> RequestId for Result<O, E>
where
O: RequestId,
Expand Down
6 changes: 6 additions & 0 deletions aws/rust-runtime/aws-inlineable/src/s3_request_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ impl<B> RequestIdExt for http::Response<B> {
}
}

impl RequestIdExt for HeaderMap {
fn extended_request_id(&self) -> Option<&str> {
extract_extended_request_id(self)
}
}

impl<O, E> RequestIdExt for Result<O, E>
where
O: RequestIdExt,
Expand Down
4 changes: 2 additions & 2 deletions aws/sdk-adhoc-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

extra["displayName"] = "Smithy :: Rust :: Codegen :: Test"
extra["moduleName"] = "software.amazon.smithy.kotlin.codegen.test"
extra["displayName"] = "Smithy :: Rust :: AWS-SDK :: Ad-hoc Test"
extra["moduleName"] = "software.amazon.smithy.rust.awssdk.adhoc.test"

tasks["jar"].enabled = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ abstract class BaseRequestIdDecorator : ClientCodegenDecorator {
when (section) {
is OperationSection.PopulateErrorMetadataExtras -> {
rustTemplate(
"${section.builderName} = #{apply_to_error}(${section.builderName}, ${section.responseName}.headers());",
"${section.builderName} = #{apply_to_error}(${section.builderName}, ${section.responseHeadersName});",
"apply_to_error" to applyToError(codegenContext),
)
}
is OperationSection.MutateOutput -> {
rust(
"output._set_$fieldName(#T::$accessorFunctionName(response).map(str::to_string));",
"output._set_$fieldName(#T::$accessorFunctionName(${section.responseHeadersName}).map(str::to_string));",
accessorTrait(codegenContext),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.generators.operationBuild
import software.amazon.smithy.rust.codegen.core.util.expectMember
import software.amazon.smithy.rust.codegen.core.util.getTrait
import software.amazon.smithy.rust.codegen.core.util.inputShape
import software.amazon.smithy.rust.codegen.core.util.letIf
import software.amazon.smithy.rust.codegen.core.util.orNull

fun RuntimeConfig.awsInlineableBodyWithChecksum() = RuntimeType.forInlineDependency(
Expand All @@ -41,12 +42,16 @@ class HttpRequestChecksumDecorator : ClientCodegenDecorator {
override val name: String = "HttpRequestChecksum"
override val order: Byte = 0

// TODO(enableNewSmithyRuntime): Implement checksumming via interceptor and delete this decorator
private fun applies(codegenContext: ClientCodegenContext): Boolean =
!codegenContext.settings.codegenConfig.enableNewSmithyRuntime

override fun operationCustomizations(
codegenContext: ClientCodegenContext,
operation: OperationShape,
baseCustomizations: List<OperationCustomization>,
): List<OperationCustomization> {
return baseCustomizations + HttpRequestChecksumCustomization(codegenContext, operation)
): List<OperationCustomization> = baseCustomizations.letIf(applies(codegenContext)) {
it + HttpRequestChecksumCustomization(codegenContext, operation)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSectio
import software.amazon.smithy.rust.codegen.core.util.expectMember
import software.amazon.smithy.rust.codegen.core.util.getTrait
import software.amazon.smithy.rust.codegen.core.util.inputShape
import software.amazon.smithy.rust.codegen.core.util.letIf
import software.amazon.smithy.rust.codegen.core.util.orNull

private fun HttpChecksumTrait.requestValidationModeMember(
Expand All @@ -31,12 +32,16 @@ class HttpResponseChecksumDecorator : ClientCodegenDecorator {
override val name: String = "HttpResponseChecksum"
override val order: Byte = 0

// TODO(enableNewSmithyRuntime): Implement checksumming via interceptor and delete this decorator
private fun applies(codegenContext: ClientCodegenContext): Boolean =
!codegenContext.settings.codegenConfig.enableNewSmithyRuntime

override fun operationCustomizations(
codegenContext: ClientCodegenContext,
operation: OperationShape,
baseCustomizations: List<OperationCustomization>,
): List<OperationCustomization> {
return baseCustomizations + HttpResponseChecksumCustomization(codegenContext, operation)
): List<OperationCustomization> = baseCustomizations.letIf(applies(codegenContext)) {
it + HttpResponseChecksumCustomization(codegenContext, operation)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,21 @@ class S3ProtocolOverride(codegenContext: CodegenContext) : RestXml(codegenContex
override fun parseHttpErrorMetadata(operationShape: OperationShape): RuntimeType {
return ProtocolFunctions.crossOperationFn("parse_http_error_metadata") { fnName ->
rustBlockTemplate(
"pub fn $fnName(response: &#{Response}<#{Bytes}>) -> Result<#{ErrorBuilder}, #{XmlDecodeError}>",
"pub fn $fnName(response_status: u16, _response_headers: &#{HeaderMap}, response_body: &[u8]) -> Result<#{ErrorBuilder}, #{XmlDecodeError}>",
*errorScope,
) {
rustTemplate(
"""
// S3 HEAD responses have no response body to for an error code. Therefore,
// check the HTTP response status and populate an error code for 404s.
if response.body().is_empty() {
if response_body.is_empty() {
let mut builder = #{ErrorMetadata}::builder();
if response.status().as_u16() == 404 {
if response_status == 404 {
builder = builder.code("NotFound");
}
Ok(builder)
} else {
#{base_errors}::parse_error_metadata(response.body().as_ref())
#{base_errors}::parse_error_metadata(response_body)
}
""",
*errorScope,
Expand Down
3 changes: 2 additions & 1 deletion aws/sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ fun generateSmithyBuild(services: AwsServices): String {
"includeFluentClient": false,
"renameErrors": false,
"eventStreamAllowList": [$eventStreamAllowListMembers],
"enableNewCrateOrganizationScheme": true
"enableNewCrateOrganizationScheme": true,
"enableNewSmithyRuntime": false
},
"service": "${service.service}",
"module": "$moduleName",
Expand Down
43 changes: 4 additions & 39 deletions aws/sdk/integration-tests/aws-smithy-runtime-test/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
* SPDX-License-Identifier: Apache-2.0
*/

use aws_smithy_http::body::SdkBody;
use aws_smithy_runtime::{AuthOrchestrator, BoxError};
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;
use aws_smithy_runtime_api::runtime_plugin::RuntimePlugin;

#[derive(Debug)]
pub struct GetObjectAuthOrc {}
Expand All @@ -19,41 +18,7 @@ impl GetObjectAuthOrc {

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(())
// TODO(orchestrator) put an auth orchestrator in the bag
Ok(())
}
}
13 changes: 8 additions & 5 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,9 +6,11 @@
use aws_smithy_client::conns::Https;
use aws_smithy_client::hyper_ext::Adapter;
use aws_smithy_http::body::SdkBody;
use aws_smithy_runtime::{BoxError, BoxFallibleFut, Connection};
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;
use aws_smithy_runtime_api::runtime_plugin::RuntimePlugin;

#[derive(Debug)]
pub struct HyperConnection {
Expand All @@ -17,7 +19,8 @@ pub struct HyperConnection {

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

Expand All @@ -29,10 +32,10 @@ impl HyperConnection {
}
}

impl Connection<http::Request<SdkBody>, http::Response<SdkBody>> for HyperConnection {
impl Connection for HyperConnection {
fn call(
&self,
_req: &mut http::Request<SdkBody>,
_req: &mut HttpRequest,
_cfg: &ConfigBag,
) -> BoxFallibleFut<http::Response<SdkBody>> {
todo!("hyper's connector wants to take ownership of req");
Expand Down
Loading

0 comments on commit 6b21e46

Please sign in to comment.