@@ -2,7 +2,6 @@ package aws.sdk.kotlin.codegen
22
33import aws.sdk.kotlin.codegen.model.traits.Presignable
44import aws.sdk.kotlin.codegen.protocols.core.AwsEndpointResolverGenerator
5- import aws.sdk.kotlin.codegen.protocols.core.QueryBindingResolver
65import aws.sdk.kotlin.codegen.protocols.middleware.AwsSignatureVersion4
76import software.amazon.smithy.aws.traits.auth.SigV4Trait
87import software.amazon.smithy.aws.traits.protocols.AwsQueryTrait
@@ -31,8 +30,6 @@ import software.amazon.smithy.kotlin.codegen.rendering.ClientConfigProperty
3130import software.amazon.smithy.kotlin.codegen.rendering.ClientConfigPropertyType
3231import software.amazon.smithy.kotlin.codegen.rendering.protocol.HttpBindingProtocolGenerator
3332import software.amazon.smithy.kotlin.codegen.rendering.protocol.HttpBindingResolver
34- import software.amazon.smithy.kotlin.codegen.rendering.protocol.HttpTraitResolver
35- import software.amazon.smithy.kotlin.codegen.rendering.protocol.hasHttpBody
3633import software.amazon.smithy.kotlin.codegen.rendering.serde.serializerName
3734import software.amazon.smithy.kotlin.codegen.utils.dq
3835import software.amazon.smithy.model.shapes.OperationShape
@@ -46,16 +43,13 @@ import software.amazon.smithy.model.traits.TimestampFormatTrait
4643 *
4744 * @property serviceId ID of service presigning applies to
4845 * @property operationId Operation capable of presigning
49- * @property presignedParameterId (Optional) parameter in which presigned URL should be passed in the request
50- * @property hasBody true if operation will pass an unsigned body with the request
46+ * @property signBody true if the body is to be read and signed, otherwise body specified as unsigned.
5147 *
5248 */
5349data class PresignableOperation (
5450 val serviceId : String ,
5551 val operationId : String ,
56- // TODO ~ Implementation of embedded presigned URLs is TBD
57- val presignedParameterId : String? ,
58- val hasBody : Boolean ,
52+ val signBody : Boolean ,
5953)
6054
6155/* *
@@ -103,9 +97,10 @@ class PresignerGenerator : KotlinIntegration {
10397 .filter { operationShape -> operationShape.hasTrait(Presignable .ID ) }
10498 .map { operationShape ->
10599 check(AwsSignatureVersion4 .hasSigV4AuthScheme(ctx.model, service, operationShape)) { " Operation does not have valid auth trait" }
106- val resolver: HttpBindingResolver = getProtocolHttpBindingResolver(ctx, service)
107- val hasBody = resolver.hasHttpBody(operationShape)
108- PresignableOperation (service.id.toString(), operationShape.id.toString(), null , hasBody)
100+ val protocol = requireNotNull(ctx.protocolGenerator).protocol.name
101+ val shouldSignBody = signBody(protocol)
102+
103+ PresignableOperation (service.id.toString(), operationShape.id.toString(), shouldSignBody)
109104 }
110105
111106 // If presignable operations found for this service, generate a Presigner file
@@ -116,6 +111,16 @@ class PresignerGenerator : KotlinIntegration {
116111 }
117112 }
118113
114+ // Determine if body should be read and signed by CRT. If body is to be signed by CRT, null is passed to signer
115+ // for signedBodyValue parameter. This causes CRT to read the body and compute the signature.
116+ // Otherwise, AwsSignedBodyValue.UNSIGNED_PAYLOAD is passed specifying that the body will be ignored and CRT
117+ // will not take the body into account when signing the request.
118+ private fun signBody (protocol : String ) =
119+ when (protocol) {
120+ " awsQuery" -> true // Query protocol always contains a body
121+ else -> false
122+ }
123+
119124 private fun renderPresigner (
120125 writer : KotlinWriter ,
121126 ctx : CodegenContext ,
@@ -302,7 +307,7 @@ class PresignerGenerator : KotlinIntegration {
302307 write(" httpRequestBuilder.url.path," )
303308 presignConfigFnVisitor.renderQueryParameters(writer)
304309 write(" durationSeconds.toLong()," )
305- write(" ${presignableOp.hasBody } ," )
310+ write(" ${presignableOp.signBody } ," )
306311 write(" SigningLocation.HEADER" )
307312 }
308313 }
@@ -345,12 +350,4 @@ class PresignerGenerator : KotlinIntegration {
345350 write(" return createPresignedRequest(presignConfig, $requestConfigFnName (this, durationSeconds))" )
346351 }
347352 }
348-
349- private fun getProtocolHttpBindingResolver (ctx : CodegenContext , service : ServiceShape ): HttpBindingResolver =
350- when (requireNotNull(ctx.protocolGenerator).protocol) {
351- AwsQueryTrait .ID -> QueryBindingResolver (ctx.model, service)
352- RestJson1Trait .ID -> HttpTraitResolver (ctx.model, service, " application/json" )
353- RestXmlTrait .ID -> HttpTraitResolver (ctx.model, service, " application/xml" )
354- else -> throw CodegenException (" Unable to create HttpBindingResolver for unhandled protocol ${ctx.protocolGenerator?.protocol} " )
355- }
356353}
0 commit comments