Skip to content

Commit

Permalink
Use enabled for service and comment clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
0marperez committed Mar 7, 2024
1 parent 2b7479c commit fc0fd0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProtocolMiddleware>,
): List<ProtocolMiddleware> = if (modelHasSigV4aTrait(ctx)) resolved + UnsupportedSigningAlgorithmMiddleware else resolved
): List<ProtocolMiddleware> = resolved + UnsupportedSigningAlgorithmMiddleware
}

private val UnsupportedSigningAlgorithmMiddleware = object : ProtocolMiddleware {
Expand All @@ -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 }

0 comments on commit fc0fd0a

Please sign in to comment.