Skip to content

Commit 4c66977

Browse files
committed
address feedback
1 parent 3b8c02d commit 4c66977

File tree

10 files changed

+216
-187
lines changed

10 files changed

+216
-187
lines changed

aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/profile/AwsProfile.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,10 @@ public inline fun <reified T : Enum<T>> AwsProfile.getEnumOrNull(key: String, su
228228
public inline fun <reified T : Enum<T>> AwsProfile.getEnumSetOrNull(key: String, subKey: String? = null): Set<T>? =
229229
getOrNull(key, subKey)?.let { rawValue ->
230230
rawValue.split(",")
231-
.map { it.trim() }
232-
.map { value ->
233-
enumValues<T>().firstOrNull {
234-
it.name.equals(value, ignoreCase = true)
231+
.map { it ->
232+
val value = it.trim()
233+
enumValues<T>().firstOrNull { enumValue ->
234+
enumValue.name.equals(value, ignoreCase = true)
235235
} ?: throw ConfigurationException(
236236
buildString {
237237
append(key)
@@ -242,7 +242,6 @@ public inline fun <reified T : Enum<T>> AwsProfile.getEnumSetOrNull(key: String,
242242
},
243243
)
244244
}.toSet()
245-
.takeIf { it.isNotEmpty() }
246245
}
247246

248247
internal fun AwsProfile.getUrlOrNull(key: String, subKey: String? = null): Url? =

codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/sqs/SqsMd5ChecksumValidationIntegration.kt

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package aws.sdk.kotlin.codegen.customization.sqs
66

77
import aws.sdk.kotlin.codegen.ServiceClientCompanionObjectWriter
8+
import aws.sdk.kotlin.codegen.sdkId
89
import software.amazon.smithy.kotlin.codegen.KotlinSettings
910
import software.amazon.smithy.kotlin.codegen.core.CodegenContext
1011
import software.amazon.smithy.kotlin.codegen.core.KotlinWriter
@@ -17,6 +18,7 @@ import software.amazon.smithy.kotlin.codegen.model.expectShape
1718
import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator
1819
import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolMiddleware
1920
import software.amazon.smithy.kotlin.codegen.rendering.util.ConfigProperty
21+
import software.amazon.smithy.kotlin.codegen.rendering.util.ConfigPropertyType
2022
import software.amazon.smithy.model.Model
2123
import software.amazon.smithy.model.shapes.OperationShape
2224
import software.amazon.smithy.model.shapes.ServiceShape
@@ -26,38 +28,61 @@ import software.amazon.smithy.model.shapes.ServiceShape
2628
*/
2729
class SqsMd5ChecksumValidationIntegration : KotlinIntegration {
2830
override fun enabledForService(model: Model, settings: KotlinSettings): Boolean =
29-
model.expectShape<ServiceShape>(settings.service).isSqs
31+
model.expectShape<ServiceShape>(settings.service).sdkId.lowercase() == "sqs"
3032

3133
companion object {
3234
val ValidationEnabledProp: ConfigProperty = ConfigProperty {
3335
name = "checksumValidationEnabled"
3436
symbol = buildSymbol {
3537
name = "ValidationEnabled"
3638
namespace = "aws.sdk.kotlin.services.sqs.internal"
39+
nullable = false
3740
}
41+
propertyType = ConfigPropertyType.Custom(
42+
render = { prop, writer ->
43+
writer.write("public val #1L: #2T = builder.#1L ?: #2T.NEVER", prop.propertyName, prop.symbol)
44+
},
45+
renderBuilder = { prop, writer ->
46+
prop.documentation?.let(writer::dokka)
47+
writer.write("public var #L: #T? = null", prop.propertyName, prop.symbol)
48+
writer.write("")
49+
},
50+
)
3851
documentation = """
3952
Specifies when MD5 checksum validation should be performed for SQS messages. This controls the automatic
4053
calculation and validation of checksums during message operations.
4154
4255
Valid values:
43-
- `ALWAYS` (default) - Checksums are calculated and validated for both sending and receiving operations
56+
- `ALWAYS` - Checksums are calculated and validated for both sending and receiving operations
4457
(SendMessage, SendMessageBatch, and ReceiveMessage)
4558
- `WHEN_SENDING` - Checksums are only calculated and validated during send operations
4659
(SendMessage and SendMessageBatch)
4760
- `WHEN_RECEIVING` - Checksums are only calculated and validated during receive operations
4861
(ReceiveMessage)
49-
- `NEVER` - No checksum calculation or validation is performed
62+
- `NEVER` (default) - No checksum calculation or validation is performed
5063
""".trimIndent()
64+
// TODO: MD5 checksum validation is temporarily disabled. Change default to ALWAYS in v1.5
5165
}
5266

5367
private val validationScope = buildSymbol {
5468
name = "ValidationScope"
5569
namespace = "aws.sdk.kotlin.services.sqs.internal"
70+
nullable = false
5671
}
5772

5873
val ValidationScopeProp: ConfigProperty = ConfigProperty {
5974
name = "checksumValidationScopes"
60-
symbol = KotlinTypes.Collections.set(validationScope, default = "emptySet()")
75+
symbol = KotlinTypes.Collections.set(validationScope)
76+
propertyType = ConfigPropertyType.Custom(
77+
render = { prop, writer ->
78+
writer.write("public val #1L: #2T = builder.#1L ?: #3T.entries.toSet()", prop.propertyName, prop.symbol, validationScope)
79+
},
80+
renderBuilder = { prop, writer ->
81+
prop.documentation?.let(writer::dokka)
82+
writer.write("public var #L: #T? = null", prop.propertyName, prop.symbol)
83+
writer.write("")
84+
},
85+
)
6186
documentation = """
6287
Specifies which parts of an SQS message should undergo MD5 checksum validation. This configuration
6388
accepts a set of validation scopes that determine which message components to validate.
@@ -69,7 +94,7 @@ class SqsMd5ChecksumValidationIntegration : KotlinIntegration {
6994
system attributes during message receipt)
7095
- `MESSAGE_BODY` - Validates checksums for the message body
7196
72-
Default: All three scopes (MESSAGE_ATTRIBUTES, MESSAGE_SYSTEM_ATTRIBUTES, MESSAGE_BODY)
97+
Default: All three scopes (`MESSAGE_ATTRIBUTES`, `MESSAGE_SYSTEM_ATTRIBUTES`, `MESSAGE_BODY`)
7398
""".trimIndent()
7499
}
75100
}

codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/sqs/SqsModelUtils.kt

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

codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/sqs/SqsMd5ChecksumValidationIntegrationTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ import kotlin.test.assertTrue
1818
import kotlin.test.fail
1919

2020
class SqsMd5ChecksumValidationIntegrationTest {
21+
object FooMiddleware : ProtocolMiddleware {
22+
override val name: String = "FooMiddleware"
23+
override fun render(ctx: ProtocolGenerator.GenerationContext, op: OperationShape, writer: KotlinWriter) =
24+
fail("Unexpected call to `FooMiddleware.render`")
25+
}
26+
2127
@Test
2228
fun testNotExpectedForNonSqsModel() {
2329
val model = model("NotSqs")
@@ -44,9 +50,3 @@ class SqsMd5ChecksumValidationIntegrationTest {
4450
assertEquals(listOf(FooMiddleware, SqsMd5ChecksumValidationMiddleware), actual)
4551
}
4652
}
47-
48-
object FooMiddleware : ProtocolMiddleware {
49-
override val name: String = "FooMiddleware"
50-
override fun render(ctx: ProtocolGenerator.GenerationContext, op: OperationShape, writer: KotlinWriter) =
51-
fail("Unexpected call to `FooMiddleware.render`")
52-
}

0 commit comments

Comments
 (0)