From 17ab7d90ca2f681a17be33b96aa7f904950cc52b Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 23 Jan 2024 16:38:56 -0500 Subject: [PATCH] Add a check when applying the SigV4A trait --- .../SigV4AsymmetricTraitCustomization.kt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/SigV4AsymmetricTraitCustomization.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/SigV4AsymmetricTraitCustomization.kt index aa12096172b..6dad39c281b 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/SigV4AsymmetricTraitCustomization.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/SigV4AsymmetricTraitCustomization.kt @@ -10,6 +10,7 @@ import software.amazon.smithy.aws.traits.auth.SigV4Trait import software.amazon.smithy.kotlin.codegen.KotlinSettings import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration import software.amazon.smithy.kotlin.codegen.model.getTrait +import software.amazon.smithy.kotlin.codegen.model.hasTrait import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.traits.AuthTrait @@ -35,11 +36,14 @@ class SigV4AsymmetricTraitCustomization : KotlinIntegration { when (shape.isServiceShape) { true -> { val builder = (shape as ServiceShape).toBuilder() - builder.addTrait( - SigV4ATrait.builder() - .name(shape.getTrait()?.name ?: shape.getTrait()?.arnNamespace) - .build(), - ) + + if (!shape.hasTrait()) { + builder.addTrait( + SigV4ATrait.builder() + .name(shape.getTrait()?.name ?: shape.getTrait()?.arnNamespace) + .build(), + ) + } // SigV4A is added at the end because these services model SigV4A through endpoint rules instead of the service shape. // Because of that, SigV4A can apply to any operation, and the safest thing to do is add it at the end