55package aws.sdk.kotlin.codegen
66
77import aws.sdk.kotlin.codegen.model.traits.Presignable
8- import software.amazon.smithy.aws.traits.HttpChecksumTrait
98import software.amazon.smithy.aws.traits.auth.SigV4Trait
109import software.amazon.smithy.aws.traits.protocols.AwsQueryTrait
1110import software.amazon.smithy.codegen.core.Symbol
1211import 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
2112import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration
2213import software.amazon.smithy.kotlin.codegen.integration.SectionId
2314import software.amazon.smithy.kotlin.codegen.integration.SectionKey
@@ -28,7 +19,6 @@ import software.amazon.smithy.kotlin.codegen.rendering.endpoints.EndpointResolve
2819import software.amazon.smithy.kotlin.codegen.rendering.protocol.HttpBindingProtocolGenerator
2920import software.amazon.smithy.kotlin.codegen.rendering.protocol.HttpBindingResolver
3021import software.amazon.smithy.kotlin.codegen.rendering.serde.serializerName
31- import software.amazon.smithy.kotlin.codegen.utils.getOrNull
3222import software.amazon.smithy.model.knowledge.TopDownIndex
3323import software.amazon.smithy.model.shapes.OperationShape
3424import 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}
0 commit comments