Skip to content

Commit 14b2f3e

Browse files
authored
fix: backfill optional auth trait for cognito and cognito-idp (#555)
1 parent 26ae193 commit 14b2f3e

File tree

3 files changed

+69
-44
lines changed

3 files changed

+69
-44
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
6+
package aws.sdk.kotlin.codegen.customization
7+
8+
import software.amazon.smithy.codegen.core.CodegenException
9+
import software.amazon.smithy.kotlin.codegen.KotlinSettings
10+
import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration
11+
import software.amazon.smithy.model.Model
12+
import software.amazon.smithy.model.shapes.OperationShape
13+
import software.amazon.smithy.model.traits.OptionalAuthTrait
14+
import software.amazon.smithy.model.transform.ModelTransformer
15+
16+
/**
17+
* Several services have operations that do not/should not be signed and need
18+
* to have the auth trait manually set to `[]`.
19+
*
20+
* See https://github.com/awslabs/aws-sdk-kotlin/issues/280 and https://github.com/awslabs/aws-sdk-kotlin/issues/553
21+
*/
22+
class BackfillOptionalAuth : KotlinIntegration {
23+
24+
// service shape id -> operations that should have optional auth trait applied
25+
private val disabledAuthOperationsByService = mapOf(
26+
"com.amazonaws.sts#AWSSecurityTokenServiceV20110615" to setOf(
27+
"com.amazonaws.sts#AssumeRoleWithSAML",
28+
"com.amazonaws.sts#AssumeRoleWithWebIdentity"
29+
),
30+
"com.amazonaws.cognitoidentity#AWSCognitoIdentityService" to setOf(
31+
"com.amazonaws.cognitoidentity#GetId",
32+
"com.amazonaws.cognitoidentity#GetOpenIdToken",
33+
"com.amazonaws.cognitoidentity#UnlinkIdentity",
34+
"com.amazonaws.cognitoidentity#GetCredentialsForIdentity"
35+
),
36+
// https://docs.aws.amazon.com/cognito/latest/developerguide/security_iam_service-with-iam.html
37+
"com.amazonaws.cognitoidentityprovider#AWSCognitoIdentityProviderService" to setOf(
38+
"com.amazonaws.cognitoidentityprovider#ConfirmDevice",
39+
"com.amazonaws.cognitoidentityprovider#ForgetDevice",
40+
"com.amazonaws.cognitoidentityprovider#GetDevice",
41+
"com.amazonaws.cognitoidentityprovider#GlobalSignOut",
42+
"com.amazonaws.cognitoidentityprovider#ListDevices",
43+
"com.amazonaws.cognitoidentityprovider#RevokeToken",
44+
"com.amazonaws.cognitoidentityprovider#UpdateDeviceStatus"
45+
)
46+
)
47+
48+
// this should happen prior to most other integrations that could rely on the presence of this trait
49+
override val order: Byte = -60
50+
51+
override fun enabledForService(model: Model, settings: KotlinSettings): Boolean {
52+
val serviceId = settings.service.toString()
53+
return serviceId in disabledAuthOperationsByService
54+
}
55+
56+
override fun preprocessModel(model: Model, settings: KotlinSettings): Model {
57+
val serviceId = settings.service.toString()
58+
val optionalAuthOperations = disabledAuthOperationsByService[serviceId] ?: throw CodegenException("expected $serviceId in disabled operations map")
59+
return ModelTransformer.create()
60+
.mapShapes(model) {
61+
if (optionalAuthOperations.contains(it.id.toString()) && it is OperationShape) {
62+
it.toBuilder().addTrait(OptionalAuthTrait()).build()
63+
} else {
64+
it
65+
}
66+
}
67+
}
68+
}

codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/sts/StsDisableAuthForOperations.kt

Lines changed: 0 additions & 43 deletions
This file was deleted.

codegen/smithy-aws-kotlin-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ aws.sdk.kotlin.codegen.customization.polly.PollyPresigner
1515
aws.sdk.kotlin.codegen.customization.BoxServices
1616
aws.sdk.kotlin.codegen.customization.glacier.GlacierBodyChecksum
1717
aws.sdk.kotlin.codegen.customization.machinelearning.MachineLearningEndpointCustomization
18-
aws.sdk.kotlin.codegen.customization.sts.StsDisableAuthForOperations
18+
aws.sdk.kotlin.codegen.customization.BackfillOptionalAuth
1919
aws.sdk.kotlin.codegen.customization.RemoveEventStreamOperations

0 commit comments

Comments
 (0)