Skip to content

Commit 34a8153

Browse files
committed
Clean up
1 parent 3ed4d91 commit 34a8153

File tree

3 files changed

+7
-80
lines changed

3 files changed

+7
-80
lines changed

codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/PresignerGenerator.kt

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,10 @@
55
package aws.sdk.kotlin.codegen
66

77
import aws.sdk.kotlin.codegen.model.traits.Presignable
8-
import software.amazon.smithy.aws.traits.HttpChecksumTrait
98
import software.amazon.smithy.aws.traits.auth.SigV4Trait
109
import software.amazon.smithy.aws.traits.protocols.AwsQueryTrait
1110
import software.amazon.smithy.codegen.core.Symbol
1211
import software.amazon.smithy.kotlin.codegen.core.*
13-
import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes.Core.Hashing.isSupportedForFlexibleChecksums
14-
import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes.Core.Hashing.toHashFunctionOrThrow
15-
import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes.Core.Text.Encoding.encodeBase64String
16-
import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes.Http.HttpBody
17-
import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes.Http.readAll
18-
import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes.KotlinCoroutines.coroutineContext
19-
import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes.KotlinxCoroutines.runBlocking
20-
import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes.Observability.TelemetryApi.warn
2112
import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration
2213
import software.amazon.smithy.kotlin.codegen.integration.SectionId
2314
import software.amazon.smithy.kotlin.codegen.integration.SectionKey
@@ -28,7 +19,6 @@ import software.amazon.smithy.kotlin.codegen.rendering.endpoints.EndpointResolve
2819
import software.amazon.smithy.kotlin.codegen.rendering.protocol.HttpBindingProtocolGenerator
2920
import software.amazon.smithy.kotlin.codegen.rendering.protocol.HttpBindingResolver
3021
import software.amazon.smithy.kotlin.codegen.rendering.serde.serializerName
31-
import software.amazon.smithy.kotlin.codegen.utils.getOrNull
3222
import software.amazon.smithy.model.knowledge.TopDownIndex
3323
import software.amazon.smithy.model.shapes.OperationShape
3424
import software.amazon.smithy.model.shapes.ServiceShape
@@ -157,7 +147,6 @@ class PresignerGenerator : KotlinIntegration {
157147
requestSymbol,
158148
serializerSymbol,
159149
contextMap,
160-
op,
161150
)
162151
}
163152
}
@@ -202,7 +191,6 @@ class PresignerGenerator : KotlinIntegration {
202191
requestSymbol: Symbol,
203192
serializerSymbol: Symbol,
204193
contextMap: Map<SectionKey<*>, Any>,
205-
op: OperationShape,
206194
) = writer.apply {
207195
dokka {
208196
write("Presign a [#T] using the configuration of this [#T].", requestSymbol, serviceSymbol)
@@ -275,44 +263,6 @@ class PresignerGenerator : KotlinIntegration {
275263
)
276264
}
277265

278-
checksumAlgorithmMember(op, ctx)?.let { checksumAlgorithmMember ->
279-
withBlock("input.#L?.value?.let { checksumAlgorithmName ->", "}", checksumAlgorithmMember) {
280-
withBlock("when (unsignedRequest.body) {", "}") {
281-
withBlock("is #1T.Bytes, is #1T.Empty -> {", "}", HttpBody) {
282-
write("val checksumAlgorithm = checksumAlgorithmName.#T()", toHashFunctionOrThrow)
283-
withInlineBlock(
284-
"if (checksumAlgorithm.#T) {",
285-
"}",
286-
isSupportedForFlexibleChecksums,
287-
) {
288-
withBlock("#T {", "}", runBlocking) {
289-
withBlock("checksumAlgorithm.update(", ")") {
290-
write("unsignedRequest.body.#T() ?: byteArrayOf()", readAll)
291-
}
292-
}
293-
write(
294-
"checksum = #S.lowercase() to checksumAlgorithm.digest().#T()",
295-
"x-amz-checksum-\${checksumAlgorithmName}",
296-
encodeBase64String,
297-
)
298-
}
299-
withBlock(" else {", "}") {
300-
withBlock("#T {", "}", runBlocking) {
301-
write("class Presigner")
302-
write(
303-
"#T.#T<Presigner> { #S }",
304-
coroutineContext,
305-
warn,
306-
"The requested checksum algorithm (\${checksumAlgorithmName}) is not supported for pre-signed URL checksums, sending request without checksum.",
307-
)
308-
}
309-
}
310-
}
311-
write("else -> throw IllegalStateException(#S)", "HTTP body type unsupported for pre-signed URL checksums.")
312-
}
313-
}
314-
}
315-
316266
declareSection(SigningConfigCustomizationSection)
317267

318268
write("configBlock()")
@@ -335,24 +285,4 @@ class PresignerGenerator : KotlinIntegration {
335285
* > "my-object/example/photo.user". This is an incorrect path for that object.
336286
*/
337287
private fun normalizeUriPath(service: ServiceShape) = service.sdkId != "S3"
338-
339-
/**
340-
* Gets the checksum algorithm member if configured on a request, otherwise null
341-
*/
342-
private fun checksumAlgorithmMember(
343-
operationShape: OperationShape,
344-
ctx: CodegenContext,
345-
): String? {
346-
operationShape.getTrait<HttpChecksumTrait>()?.let { httpChecksumTrait ->
347-
httpChecksumTrait.requestAlgorithmMember.getOrNull()?.let { requestAlgorithmMember ->
348-
val memberShape = ctx.model
349-
.expectShape<StructureShape>(operationShape.input.get())
350-
.members()
351-
.first { it.memberName == requestAlgorithmMember }
352-
353-
return ctx.symbolProvider.toMemberName(memberShape)
354-
}
355-
}
356-
return null
357-
}
358288
}

services/s3/e2eTest/src/S3ChecksumTest.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import org.junit.jupiter.api.*
1616
import java.io.File
1717
import java.io.FileInputStream
1818
import java.util.*
19-
import kotlin.test.Ignore
2019
import kotlin.test.assertEquals
2120
import kotlin.test.assertFalse
2221
import kotlin.test.assertTrue
@@ -166,28 +165,28 @@ class S3ChecksumTest {
166165

167166
@Test
168167
fun testPresignedUrlNoDefault() = runBlocking {
168+
val contents = "presign-test"
169+
169170
val unsignedPutRequest = PutObjectRequest {
170171
bucket = testBucket
171172
key = testKey()
172173
}
173174
val presignedPutRequest = client.presignPutObject(unsignedPutRequest, 60.seconds)
174-
val contents = "presign-test"
175175

176176
assertFalse(presignedPutRequest.url.toString().contains("x-amz-checksum-crc32"))
177177
assertTrue(responseCodeFromPut(presignedPutRequest, contents) in 200..299)
178178
}
179179

180-
// FIXME: Sending checksum via query params should work
181180
@Test
182-
@Ignore
183-
fun testPresignedUrlContainsChecksum() = runBlocking {
181+
fun testPresignedUrlChecksumValue() = runBlocking {
182+
val contents = "presign-test"
183+
184184
val unsignedPutRequest = PutObjectRequest {
185185
bucket = testBucket
186186
key = testKey()
187-
checksumAlgorithm = ChecksumAlgorithm.Crc32
187+
checksumCrc32 = "dBBx+Q=="
188188
}
189189
val presignedPutRequest = client.presignPutObject(unsignedPutRequest, 60.seconds)
190-
val contents = "presign-test"
191190

192191
assertTrue(presignedPutRequest.url.toString().contains("x-amz-checksum-crc32"))
193192
assertTrue(responseCodeFromPut(presignedPutRequest, contents) in 200..299)

tests/codegen/checksums/src/commonTest/kotlin/aws/sdk/kotlin/tests/codegen/checksums/utils/ChecksumTestUtils.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,9 @@ internal fun runChecksumTest(
114114
// Test type
115115
requestChecksumRequired: Boolean = true,
116116
): Unit = runBlocking {
117-
val interceptorsList = listOfNotNull(headerReader, headerSetter, businessMetricsReader)
118-
119117
TestClient {
120118
httpClient = TestEngine()
121-
interceptors = interceptorsList.toMutableList()
119+
interceptors = listOfNotNull(headerReader, headerSetter, businessMetricsReader).toMutableList()
122120
requestChecksumCalculation = requestChecksumCalculationValue ?: requestChecksumCalculation
123121
responseChecksumValidation = responseChecksumValidationValue ?: responseChecksumValidation
124122
httpClient = TestEngine(

0 commit comments

Comments
 (0)