From b6c6204af5a00903ca226fecd9e9c0337e5b392f Mon Sep 17 00:00:00 2001 From: 0marperez Date: Wed, 6 Mar 2024 12:40:38 -0500 Subject: [PATCH 1/3] Change activation to sigv4a trait instead of hardcoded list --- .../UnsupportedSigningAlgorithmIntegration.kt | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/UnsupportedSigningAlgorithmIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/UnsupportedSigningAlgorithmIntegration.kt index 2513b626e2a..96352dc680f 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/UnsupportedSigningAlgorithmIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/UnsupportedSigningAlgorithmIntegration.kt @@ -5,30 +5,35 @@ package aws.sdk.kotlin.codegen.customization.s3 import aws.sdk.kotlin.codegen.AwsRuntimeTypes +import software.amazon.smithy.aws.traits.auth.SigV4ATrait import software.amazon.smithy.kotlin.codegen.KotlinSettings import software.amazon.smithy.kotlin.codegen.core.KotlinWriter import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolMiddleware import software.amazon.smithy.model.Model +import software.amazon.smithy.model.knowledge.ServiceIndex import software.amazon.smithy.model.shapes.OperationShape // FIXME: Remove this once sigV4a is supported by default AWS signer /** - * Registers an interceptor for S3 to deal with the default signer not supporting sigV4a + * Registers an interceptor for sigV4a services to deal with the default signer not supporting sigV4a * See: [aws.sdk.kotlin.runtime.http.interceptors.UnsupportedSigningAlgorithmInterceptor] */ class UnsupportedSigningAlgorithmIntegration : KotlinIntegration { - override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = - when (settings.sdkId.lowercase()) { - "s3", "eventbridge", "cloudfront keyvaluestore" -> true - else -> false - } + + // Needs to happen after the SigV4AsymmetricTraitCustomization (-60), which adds the sigV4a trait to models missing it + override val order: Byte = -50 + + // Set to true rather than looking for sigV4a in the model because this integration would be filtered out + // before the application of the trait via SigV4AsymmetricTraitCustomization. + // See: CodegenVisitor + override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = true override fun customizeMiddleware( ctx: ProtocolGenerator.GenerationContext, resolved: List, - ): List = resolved + UnsupportedSigningAlgorithmMiddleware + ): List = if (modelHasSigV4aTrait(ctx)) resolved + UnsupportedSigningAlgorithmMiddleware else resolved } private val UnsupportedSigningAlgorithmMiddleware = object : ProtocolMiddleware { @@ -41,3 +46,10 @@ private val UnsupportedSigningAlgorithmMiddleware = object : ProtocolMiddleware ) } } + +private fun modelHasSigV4aTrait(ctx: ProtocolGenerator.GenerationContext): Boolean = + ServiceIndex + .of(ctx.model) + .getAuthSchemes(ctx.service) + .values + .any { it.javaClass == SigV4ATrait::class.java } From 2b7479ced2199e8cf4e39e8bde5ecd4a29b175c9 Mon Sep 17 00:00:00 2001 From: 0marperez Date: Wed, 6 Mar 2024 13:12:08 -0500 Subject: [PATCH 2/3] Update comment --- .../s3/UnsupportedSigningAlgorithmIntegration.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/UnsupportedSigningAlgorithmIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/UnsupportedSigningAlgorithmIntegration.kt index 96352dc680f..4e588e01a2f 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/UnsupportedSigningAlgorithmIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/UnsupportedSigningAlgorithmIntegration.kt @@ -25,8 +25,8 @@ class UnsupportedSigningAlgorithmIntegration : KotlinIntegration { // Needs to happen after the SigV4AsymmetricTraitCustomization (-60), which adds the sigV4a trait to models missing it override val order: Byte = -50 - // Set to true rather than looking for sigV4a in the model because this integration would be filtered out - // before the application of the trait via SigV4AsymmetricTraitCustomization. + // Set to true rather than looking for sigV4a in the model here because this integration would be filtered out + // before the application of the trait is done for some services via SigV4AsymmetricTraitCustomization. // See: CodegenVisitor override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = true From fc0fd0a53cf083ff42918ef0604a4522bd2bfd2a Mon Sep 17 00:00:00 2001 From: 0marperez Date: Thu, 7 Mar 2024 17:02:46 -0500 Subject: [PATCH 3/3] Use enabled for service and comment clean up --- .../SigV4AsymmetricTraitCustomization.kt | 2 +- .../UnsupportedSigningAlgorithmIntegration.kt | 23 ++++++------------- 2 files changed, 8 insertions(+), 17 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 6dad39c281b..7ec2e9cab60 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 @@ -22,7 +22,7 @@ import software.amazon.smithy.model.transform.ModelTransformer * NOTE: Won't add sigV4 trait (services that support sigV4A MUST support sigV4) */ class SigV4AsymmetricTraitCustomization : KotlinIntegration { - // Needs to happen before the `SigV4AsymmetricAuthSchemeIntegration` & `SigV4AuthSchemeIntegration` (-50 & -50) + // Needs to happen before the SigV4AsymmetricAuthSchemeIntegration & SigV4AuthSchemeIntegration override val order: Byte = -60 // services which support SigV4A but don't model it diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/UnsupportedSigningAlgorithmIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/UnsupportedSigningAlgorithmIntegration.kt index 4e588e01a2f..c862059f2d7 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/UnsupportedSigningAlgorithmIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/UnsupportedSigningAlgorithmIntegration.kt @@ -21,19 +21,17 @@ import software.amazon.smithy.model.shapes.OperationShape * See: [aws.sdk.kotlin.runtime.http.interceptors.UnsupportedSigningAlgorithmInterceptor] */ class UnsupportedSigningAlgorithmIntegration : KotlinIntegration { - - // Needs to happen after the SigV4AsymmetricTraitCustomization (-60), which adds the sigV4a trait to models missing it - override val order: Byte = -50 - - // Set to true rather than looking for sigV4a in the model here because this integration would be filtered out - // before the application of the trait is done for some services via SigV4AsymmetricTraitCustomization. - // See: CodegenVisitor - override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = true + override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = + ServiceIndex + .of(model) + .getAuthSchemes(settings.service) + .values + .any { it.javaClass == SigV4ATrait::class.java } override fun customizeMiddleware( ctx: ProtocolGenerator.GenerationContext, resolved: List, - ): List = if (modelHasSigV4aTrait(ctx)) resolved + UnsupportedSigningAlgorithmMiddleware else resolved + ): List = resolved + UnsupportedSigningAlgorithmMiddleware } private val UnsupportedSigningAlgorithmMiddleware = object : ProtocolMiddleware { @@ -46,10 +44,3 @@ private val UnsupportedSigningAlgorithmMiddleware = object : ProtocolMiddleware ) } } - -private fun modelHasSigV4aTrait(ctx: ProtocolGenerator.GenerationContext): Boolean = - ServiceIndex - .of(ctx.model) - .getAuthSchemes(ctx.service) - .values - .any { it.javaClass == SigV4ATrait::class.java }