Skip to content

Commit

Permalink
Add a special-case for CloudFront KVS
Browse files Browse the repository at this point in the history
  • Loading branch information
lauzadis committed Jan 23, 2024
1 parent fd3e47b commit 17a5bbc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package aws.sdk.kotlin.codegen.customization

import software.amazon.smithy.aws.traits.auth.SigV4ATrait
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.model.Model
import software.amazon.smithy.model.shapes.ServiceShape
import software.amazon.smithy.model.traits.AuthTrait
import software.amazon.smithy.model.transform.ModelTransformer

/**
* Modify the [AuthTrait] of the CloudFront KeyValueStore service, placing SigV4A before SigV4 in the
* prioritized list.
*/
class CloudFrontKeyValueStoreSigV4APrioritizationCustomization : KotlinIntegration {
// Runs after SigV4AsymmetricTraitCustomization (-60) and before `SigV4AsymmetricAuthSchemeIntegration`(-50) and `SigV4AuthSchemeIntegration` (-50)
override val order: Byte = -55

override fun enabledForService(model: Model, settings: KotlinSettings): Boolean = settings.sdkId.lowercase() == "cloudfront keyvaluestore"

override fun preprocessModel(model: Model, settings: KotlinSettings): Model =
ModelTransformer.create().mapShapes(model) { shape ->
when (shape.isServiceShape) {
true -> {
val builder = (shape as ServiceShape).toBuilder()
builder.removeTrait(AuthTrait.ID) // remove existing auth trait

// add a new auth trait with SigV4A in front
val authTrait = AuthTrait(mutableSetOf(SigV4ATrait.ID, SigV4Trait.ID))
builder.addTrait(authTrait)

builder.build()
}
false -> shape
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ aws.sdk.kotlin.codegen.customization.ec2.EC2MakePrimitivesOptional
aws.sdk.kotlin.codegen.customization.RemoveDefaults
aws.sdk.kotlin.codegen.customization.s3.UnsupportedSigningAlgorithmIntegration
aws.sdk.kotlin.codegen.customization.SigV4AsymmetricTraitCustomization
aws.sdk.kotlin.codegen.customization.CloudFrontKeyValueStoreSigV4APrioritizationCustomization

0 comments on commit 17a5bbc

Please sign in to comment.