Skip to content

Commit

Permalink
fix(codegen): disable signing for sts operations AssumeRoleWithSaml a…
Browse files Browse the repository at this point in the history
…nd AssumeRoleWithWebIdentity (#407)
  • Loading branch information
aajtodd authored Nov 5, 2021
1 parent 7425b65 commit 3949e45
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

package aws.sdk.kotlin.codegen.customization.sts

import aws.sdk.kotlin.codegen.sdkId
import software.amazon.smithy.kotlin.codegen.KotlinSettings
import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration
import software.amazon.smithy.kotlin.codegen.model.expectShape
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.model.shapes.ServiceShape
import software.amazon.smithy.model.shapes.ShapeId
import software.amazon.smithy.model.traits.AuthTrait
import software.amazon.smithy.model.transform.ModelTransformer

/**
* STS needs to have the auth trait manually set to []
*
* See https://github.com/awslabs/aws-sdk-kotlin/issues/280
*/
class StsDisableAuthForOperations : KotlinIntegration {

private val optionalAuthOperations = setOf(
ShapeId.from("com.amazonaws.sts#AssumeRoleWithSAML"),
ShapeId.from("com.amazonaws.sts#AssumeRoleWithWebIdentity")
)

override fun enabledForService(model: Model, settings: KotlinSettings): Boolean =
model.expectShape<ServiceShape>(settings.service).sdkId == "STS"

override fun preprocessModel(model: Model, settings: KotlinSettings): Model =
ModelTransformer.create()
.mapShapes(model) {
if (optionalAuthOperations.contains(it.id) && it is OperationShape) {
it.toBuilder().addTrait(AuthTrait(emptySet())).build()
} else {
it
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ aws.sdk.kotlin.codegen.customization.polly.PollyPresigner
aws.sdk.kotlin.codegen.customization.BoxServices
aws.sdk.kotlin.codegen.customization.glacier.GlacierBodyChecksum
aws.sdk.kotlin.codegen.customization.machinelearning.MachineLearningEndpointCustomization
aws.sdk.kotlin.codegen.customization.sts.StsDisableAuthForOperations

0 comments on commit 3949e45

Please sign in to comment.