in codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/PresignerGenerator.kt [84:111]
override fun writeAdditionalFiles(ctx: CodegenContext, delegator: KotlinDelegator) {
val service = ctx.model.expectShape<ServiceShape>(ctx.settings.service)
val protocolGenerator: HttpBindingProtocolGenerator = ctx.protocolGenerator as HttpBindingProtocolGenerator
val httpBindingResolver = protocolGenerator.getProtocolHttpBindingResolver(ctx.model, service)
val defaultTimestampFormat = protocolGenerator.defaultTimestampFormat
// Only services with SigV4 are currently presignable
if (!AwsSignatureVersion4.isSupportedAuthentication(ctx.model, service)) return
// Scan model for operations decorated with PresignTrait
val presignOperations = service.allOperations
.map { ctx.model.expectShape<OperationShape>(it) }
.filter { operationShape -> operationShape.hasTrait(Presignable.ID) }
.map { operationShape ->
check(AwsSignatureVersion4.hasSigV4AuthScheme(ctx.model, service, operationShape)) { "Operation does not have valid auth trait" }
val protocol = requireNotNull(ctx.protocolGenerator).protocol.name
val shouldSignBody = signBody(protocol)
PresignableOperation(service.id.toString(), operationShape.id.toString(), shouldSignBody)
}
// If presignable operations found for this service, generate a Presigner file
if (presignOperations.isNotEmpty()) {
delegator.useFileWriter("Presigners.kt", "${ctx.settings.pkg.name}.presigners") { writer ->
renderPresigner(writer, ctx, httpBindingResolver, service.expectTrait<SigV4Trait>().name, presignOperations, defaultTimestampFormat)
}
}
}