-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add customization to retry STS
IDPCommunicationErrorException
(#1718)
- Loading branch information
Showing
5 changed files
with
93 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/sts/STSDecorator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package software.amazon.smithy.rustsdk.customize.sts | ||
|
||
import software.amazon.smithy.model.Model | ||
import software.amazon.smithy.model.shapes.ServiceShape | ||
import software.amazon.smithy.model.shapes.Shape | ||
import software.amazon.smithy.model.shapes.ShapeId | ||
import software.amazon.smithy.model.shapes.StructureShape | ||
import software.amazon.smithy.model.traits.ErrorTrait | ||
import software.amazon.smithy.model.traits.RetryableTrait | ||
import software.amazon.smithy.model.transform.ModelTransformer | ||
import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext | ||
import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext | ||
import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator | ||
import software.amazon.smithy.rust.codegen.client.smithy.letIf | ||
import software.amazon.smithy.rust.codegen.client.util.hasTrait | ||
import java.util.logging.Logger | ||
|
||
class STSDecorator : RustCodegenDecorator<ClientCodegenContext> { | ||
override val name: String = "STS" | ||
override val order: Byte = 0 | ||
private val logger: Logger = Logger.getLogger(javaClass.name) | ||
|
||
private fun applies(serviceId: ShapeId) = | ||
serviceId == ShapeId.from("com.amazonaws.sts#AWSSecurityTokenServiceV20110615") | ||
|
||
private fun isIdpCommunicationError(shape: Shape): Boolean = | ||
shape is StructureShape && shape.hasTrait<ErrorTrait>() && | ||
shape.id.namespace == "com.amazonaws.sts" && shape.id.name == "IDPCommunicationErrorException" | ||
|
||
override fun transformModel(service: ServiceShape, model: Model): Model { | ||
return model.letIf(applies(service.id)) { | ||
ModelTransformer.create().mapShapes(model) { shape -> | ||
shape.letIf(isIdpCommunicationError(shape)) { | ||
logger.info("Adding @retryable trait to $shape and setting its error type to 'server'") | ||
(shape as StructureShape).toBuilder() | ||
.removeTrait(ErrorTrait.ID) | ||
.addTrait(ErrorTrait("server")) | ||
.addTrait(RetryableTrait.builder().build()).build() | ||
} | ||
} | ||
} | ||
} | ||
|
||
override fun supportsCodegenContext(clazz: Class<out CoreCodegenContext>): Boolean = | ||
clazz.isAssignableFrom(ClientCodegenContext::class.java) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
aws/sdk/integration-tests/sts/tests/retry_idp_comms_err.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
use aws_sdk_sts as sts; | ||
use aws_smithy_types::error::Error as ErrorMeta; | ||
use aws_smithy_types::retry::{ErrorKind, ProvideErrorKind}; | ||
use sts::error::{ | ||
AssumeRoleWithWebIdentityError, AssumeRoleWithWebIdentityErrorKind, | ||
IdpCommunicationErrorException, | ||
}; | ||
|
||
#[tokio::test] | ||
async fn idp_comms_err_retryable() { | ||
let error = AssumeRoleWithWebIdentityError::new( | ||
AssumeRoleWithWebIdentityErrorKind::IdpCommunicationErrorException( | ||
IdpCommunicationErrorException::builder() | ||
.message("test") | ||
.build(), | ||
), | ||
ErrorMeta::builder() | ||
.code("IDPCommunicationError") | ||
.message("test") | ||
.build(), | ||
); | ||
assert_eq!( | ||
Some(ErrorKind::ServerError), | ||
error.retryable_error_kind(), | ||
"IdpCommunicationErrorException should be a retryable server error" | ||
); | ||
} |