Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support default checksums #1475

Open
wants to merge 70 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
4729584
misc: add rules engine codegen tests
0marperez Nov 6, 2024
7b73088
Use snapshot version of smithy kotlin
0marperez Nov 6, 2024
dbfb973
debugging: throw exception to see what metrics are strings
0marperez Nov 6, 2024
b15358b
debugging: remove exception
0marperez Nov 6, 2024
dacc345
Don't depend on snapshot version of smithy kotlin
0marperez Nov 6, 2024
bbafc3f
Use released version
0marperez Nov 6, 2024
a79aa1e
PR feedback
0marperez Nov 6, 2024
e61efbb
Checkpoint
0marperez Nov 7, 2024
285c08b
Merge branch 'main' of https://github.com/awslabs/aws-sdk-kotlin into…
0marperez Nov 8, 2024
fbb3dd5
Checkoint 2
0marperez Nov 8, 2024
136c9db
It works now
0marperez Nov 8, 2024
cb4ab12
Clean up build scripts
0marperez Nov 9, 2024
41ad1b4
Commonize some more
0marperez Nov 9, 2024
1a2d989
Checkpoint 3
0marperez Nov 9, 2024
11c733f
Merge branch 'main' of https://github.com/awslabs/aws-sdk-kotlin into…
0marperez Nov 11, 2024
4d24a24
Remove rules engine codegen tests
0marperez Nov 11, 2024
c514cba
Setup checksums codegen tests
0marperez Nov 11, 2024
2796317
Update smithy IDL version, codegen tests pass now
0marperez Nov 11, 2024
6d53243
Setup dummy unit tests
0marperez Nov 11, 2024
40cfb17
Basic setup for client config tests
0marperez Nov 11, 2024
410c085
Added requestChecksumCalculation config option
0marperez Nov 11, 2024
472fae9
RequestChecksum not required client config tests
0marperez Nov 11, 2024
e9bf8e5
RequestChecksum required client config tests
0marperez Nov 11, 2024
5133a60
Added responseChecksumValidation
0marperez Nov 11, 2024
4ce5da7
TODO ResponseChecksumValidation tests
0marperez Nov 11, 2024
da31deb
Added ResponseChecksumValidation codegen tests
0marperez Nov 12, 2024
6037580
Quick self review
0marperez Nov 12, 2024
2f6e10b
Self review V2
0marperez Nov 12, 2024
d085dec
Add todos for business metrics
0marperez Nov 12, 2024
0bafdcc
Unit tests pass
0marperez Nov 25, 2024
fc84b61
E2E tests pass
0marperez Nov 26, 2024
0f6fa65
Self review
0marperez Nov 27, 2024
c76aefe
trigger ci
0marperez Nov 27, 2024
3476242
Fix smoke tests
0marperez Dec 1, 2024
b21ec41
Don't specify gradle version in smoke tests
0marperez Dec 1, 2024
dd2792f
Correctly print enum entries in error message
0marperez Dec 1, 2024
779cd3a
Remove test ordering from S3ChecksumTest
0marperez Dec 1, 2024
6674dc7
Merge branch 'main' of https://github.com/awslabs/aws-sdk-kotlin into…
0marperez Dec 1, 2024
a3a2e09
Add copyright headers to checksum codegen tests
0marperez Dec 1, 2024
c80b55c
Update buildSrc package setup
0marperez Dec 1, 2024
5e2855c
Fix codegen tests not having packages
0marperez Dec 1, 2024
0405b20
Fix event stream codegen test templates
0marperez Dec 1, 2024
eb338f4
Save test reports for failing JVM CI checks
0marperez Dec 1, 2024
a2fb7fb
Track smithy kotlin changes
0marperez Dec 3, 2024
093ed72
Merge branch 'main' of https://github.com/awslabs/aws-sdk-kotlin into…
0marperez Dec 4, 2024
d498e30
Fix jvmTest JVM compatibility
0marperez Dec 4, 2024
b534927
Drop support for http body dot bytes response checksums
0marperez Dec 4, 2024
2761bf9
Left FIXME to use random buckets in motorcade E2E tests
0marperez Dec 4, 2024
5328641
Refactor/fix S3 express integrations
0marperez Dec 6, 2024
ad30f70
Clean up S3 integrations and e2e tests
0marperez Dec 9, 2024
4a162de
s3 express no checksums in upload part test
0marperez Dec 9, 2024
d665873
PR feedback
0marperez Dec 11, 2024
1aefe66
Use head bucket
0marperez Dec 11, 2024
55bdcb8
Presigned URL checksums
0marperez Dec 13, 2024
44894e6
Ktlint
0marperez Dec 13, 2024
ad8d1ad
Trigger CI
0marperez Dec 13, 2024
d398801
Merge branch 'main' of https://github.com/awslabs/aws-sdk-kotlin into…
0marperez Dec 13, 2024
3c259ef
PR feeback checkpoint
0marperez Dec 13, 2024
0029768
Trigger CI
0marperez Dec 13, 2024
427daf3
Refactor checksum interceptors
0marperez Dec 18, 2024
41ad742
Fix composite checksums
0marperez Dec 19, 2024
5c6c0bf
Make it compile
0marperez Dec 19, 2024
4d915c6
Fix smithy model template
0marperez Dec 19, 2024
609226c
Fix model smithy template again?
0marperez Dec 19, 2024
80ba070
Fix model again
0marperez Dec 19, 2024
94dfc93
Merge branch 'main' of https://github.com/awslabs/aws-sdk-kotlin into…
0marperez Dec 19, 2024
77f6ea5
Refactor rules engine codegen tests
0marperez Dec 19, 2024
4b61347
Run CI (empty commit)
0marperez Dec 19, 2024
756f66d
PR feedback
0marperez Dec 23, 2024
3ed4d91
Change JVM version
0marperez Dec 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ jobs:
pwd
ls -lsa
./gradlew -Ptest.java.version=${{ matrix.java-version }} jvmTest --stacktrace
- name: Save Test Reports
if: failure()
uses: actions/upload-artifact@v3
with:
name: test-reports
path: '**/build/reports'
Comment on lines +43 to +48
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment: Good catch!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these test reports used for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% sure why but sometimes the logs from failed CI tests are not very useful. In those cases you can just get a test report from the build and see which test cases failed and exception messages. Other CI checks have this as well


all-platforms:
runs-on: ${{ matrix.os }}
Expand Down
14 changes: 14 additions & 0 deletions aws-runtime/aws-config/api/aws-config.api
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ public final class aws/sdk/kotlin/runtime/config/AwsSdkSetting {
public final fun getAwsMaxAttempts ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
public final fun getAwsProfile ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
public final fun getAwsRegion ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
public final fun getAwsRequestChecksumCalculation ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
public final fun getAwsRequestMinCompressionSizeBytes ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
public final fun getAwsResponseChecksumValidation ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
public final fun getAwsRetryMode ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
public final fun getAwsRoleArn ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
public final fun getAwsRoleSessionName ()Laws/smithy/kotlin/runtime/config/EnvironmentSetting;
Expand All @@ -260,6 +262,16 @@ public final class aws/sdk/kotlin/runtime/config/AwsSdkSettingKt {
public static final fun resolveEndpointUrl (Laws/sdk/kotlin/runtime/config/AwsSdkSetting;Laws/smithy/kotlin/runtime/util/PlatformProvider;Ljava/lang/String;Ljava/lang/String;)Laws/smithy/kotlin/runtime/net/url/Url;
}

public final class aws/sdk/kotlin/runtime/config/checksums/ResolveRequestChecksumCalculationKt {
public static final fun resolveRequestChecksumCalculation (Laws/smithy/kotlin/runtime/util/PlatformProvider;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun resolveRequestChecksumCalculation$default (Laws/smithy/kotlin/runtime/util/PlatformProvider;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
}

public final class aws/sdk/kotlin/runtime/config/checksums/ResolveResponseChecksumValidationKt {
public static final fun resolveResponseChecksumValidation (Laws/smithy/kotlin/runtime/util/PlatformProvider;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun resolveResponseChecksumValidation$default (Laws/smithy/kotlin/runtime/util/PlatformProvider;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
}

public final class aws/sdk/kotlin/runtime/config/compression/RequestCompressionResolversKt {
public static final fun resolveDisableRequestCompression (Laws/smithy/kotlin/runtime/util/PlatformProvider;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun resolveDisableRequestCompression$default (Laws/smithy/kotlin/runtime/util/PlatformProvider;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
Expand Down Expand Up @@ -467,7 +479,9 @@ public final class aws/sdk/kotlin/runtime/config/profile/AwsProfileKt {
public static synthetic fun getLongOrNull$default (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/Long;
public static final fun getMaxAttempts (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Ljava/lang/Integer;
public static final fun getRegion (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Ljava/lang/String;
public static final fun getRequestChecksumCalculation (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Ljava/lang/String;
public static final fun getRequestMinCompressionSizeBytes (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Ljava/lang/Long;
public static final fun getResponseChecksumValidation (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Ljava/lang/String;
public static final fun getRetryMode (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Laws/smithy/kotlin/runtime/client/config/RetryMode;
public static final fun getRoleArn (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Ljava/lang/String;
public static final fun getSdkUserAgentAppId (Laws/sdk/kotlin/runtime/config/profile/ConfigSection;)Ljava/lang/String;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
package aws.sdk.kotlin.runtime.config

import aws.sdk.kotlin.runtime.client.AwsSdkClientConfig
import aws.sdk.kotlin.runtime.config.checksums.resolveRequestChecksumCalculation
import aws.sdk.kotlin.runtime.config.checksums.resolveResponseChecksumValidation
import aws.sdk.kotlin.runtime.config.compression.resolveDisableRequestCompression
import aws.sdk.kotlin.runtime.config.compression.resolveRequestMinCompressionSizeBytes
import aws.sdk.kotlin.runtime.config.endpoints.resolveUseDualStack
Expand All @@ -22,6 +24,7 @@ import aws.smithy.kotlin.runtime.auth.awscredentials.SigV4aClientConfig
import aws.smithy.kotlin.runtime.client.*
import aws.smithy.kotlin.runtime.client.config.ClientSettings
import aws.smithy.kotlin.runtime.client.config.CompressionClientConfig
import aws.smithy.kotlin.runtime.client.config.HttpChecksumClientConfig
import aws.smithy.kotlin.runtime.config.resolve
import aws.smithy.kotlin.runtime.telemetry.TelemetryConfig
import aws.smithy.kotlin.runtime.telemetry.TelemetryProvider
Expand Down Expand Up @@ -94,6 +97,14 @@ public abstract class AbstractAwsSdkClientFactory<
config.sigV4aSigningRegionSet ?: resolveSigV4aSigningRegionSet(platform, profile)
}

if (config is HttpChecksumClientConfig.Builder) {
config.requestChecksumCalculation =
config.requestChecksumCalculation ?: resolveRequestChecksumCalculation(platform, profile)

config.responseChecksumValidation =
config.responseChecksumValidation ?: resolveResponseChecksumValidation(platform, profile)
}

finalizeConfig(builder)
finalizeEnvironmentalConfig(builder, sharedConfig, profile)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,18 @@ public object AwsSdkSetting {
*/
public val AwsSigV4aSigningRegionSet: EnvironmentSetting<String> =
strEnvSetting("aws.sigV4aSigningRegionSet", "AWS_SIGV4A_SIGNING_REGION_SET")

/**
* Configures request checksum calculation
*/
public val AwsRequestChecksumCalculation: EnvironmentSetting<String> =
strEnvSetting("aws.requestChecksumCalculation", "AWS_REQUEST_CHECKSUM_CALCULATION")

/**
* Configures response checksum validation
*/
public val AwsResponseChecksumValidation: EnvironmentSetting<String> =
strEnvSetting("aws.responseChecksumValidation", "AWS_RESPONSE_CHECKSUM_VALIDATION")
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package aws.sdk.kotlin.runtime.config.checksums

import aws.sdk.kotlin.runtime.ConfigurationException
import aws.sdk.kotlin.runtime.InternalSdkApi
import aws.sdk.kotlin.runtime.config.AwsSdkSetting
import aws.sdk.kotlin.runtime.config.profile.AwsProfile
import aws.sdk.kotlin.runtime.config.profile.requestChecksumCalculation
import aws.smithy.kotlin.runtime.client.config.HttpChecksumConfigOption
import aws.smithy.kotlin.runtime.config.resolve
import aws.smithy.kotlin.runtime.util.LazyAsyncValue
import aws.smithy.kotlin.runtime.util.PlatformProvider

/**
* Attempts to resolve requestChecksumCalculation from the specified sources.
* @return requestChecksumCalculation setting if found, the default value if not.
*/
@InternalSdkApi
public suspend fun resolveRequestChecksumCalculation(platform: PlatformProvider = PlatformProvider.System, profile: LazyAsyncValue<AwsProfile>): HttpChecksumConfigOption {
val unparsedString = AwsSdkSetting.AwsRequestChecksumCalculation.resolve(platform) ?: profile.get().requestChecksumCalculation
return unparsedString?.let {
when (unparsedString.uppercase()) {
"WHEN_SUPPORTED" -> HttpChecksumConfigOption.WHEN_SUPPORTED
"WHEN_REQUIRED" -> HttpChecksumConfigOption.WHEN_REQUIRED
else -> throw ConfigurationException(
"'$it' is not a valid value for request checksum calculation. Valid values are: ${HttpChecksumConfigOption.entries}",
)
}
} ?: HttpChecksumConfigOption.WHEN_SUPPORTED
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Could simplify:

return when (unparsedString?.uppercase()) {
    null -> HttpChecksumConfigOption.WHEN_SUPPORTED
    "WHEN_SUPPORTED" -> HttpChecksumConfigOption.WHEN_SUPPORTED
    "WHEN_REQUIRED" -> HttpChecksumConfigOption.WHEN_REQUIRED
    else -> throw ConfigurationException(
        "'$unparsedString' is not a valid value for request checksum calculation. Valid values are: ${HttpChecksumConfigOption.entries}",
    )
}

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This file seems very similar to ResolveRequestChecksumCalculation.kt. Seems like they could be combined into a single file and maybe even reuse some logic.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package aws.sdk.kotlin.runtime.config.checksums

import aws.sdk.kotlin.runtime.ConfigurationException
import aws.sdk.kotlin.runtime.InternalSdkApi
import aws.sdk.kotlin.runtime.config.AwsSdkSetting
import aws.sdk.kotlin.runtime.config.profile.AwsProfile
import aws.sdk.kotlin.runtime.config.profile.responseChecksumValidation
import aws.smithy.kotlin.runtime.client.config.HttpChecksumConfigOption
import aws.smithy.kotlin.runtime.config.resolve
import aws.smithy.kotlin.runtime.util.LazyAsyncValue
import aws.smithy.kotlin.runtime.util.PlatformProvider

/**
* Attempts to resolve responseChecksumValidation from the specified sources.
* @return responseChecksumValidation setting if found, the default value if not.
*/
@InternalSdkApi
public suspend fun resolveResponseChecksumValidation(platform: PlatformProvider = PlatformProvider.System, profile: LazyAsyncValue<AwsProfile>): HttpChecksumConfigOption {
val unparsedString = AwsSdkSetting.AwsResponseChecksumValidation.resolve(platform) ?: profile.get().responseChecksumValidation
return unparsedString?.let {
when (unparsedString.uppercase()) {
"WHEN_SUPPORTED" -> HttpChecksumConfigOption.WHEN_SUPPORTED
"WHEN_REQUIRED" -> HttpChecksumConfigOption.WHEN_REQUIRED
else -> throw ConfigurationException(
"'$it' is not a valid value for request checksum calculation. Valid values are: ${HttpChecksumConfigOption.entries}",
)
}
} ?: HttpChecksumConfigOption.WHEN_SUPPORTED
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,20 @@ public val AwsProfile.requestMinCompressionSizeBytes: Long?
public val AwsProfile.sigV4aSigningRegionSet: String?
get() = getOrNull("sigv4a_signing_region_set")

/**
* Configures request checksum calculation
*/
@InternalSdkApi
public val AwsProfile.requestChecksumCalculation: String?
get() = getOrNull("request_checksum_calculation")

/**
* Configures response checksum validation
*/
@InternalSdkApi
public val AwsProfile.responseChecksumValidation: String?
get() = getOrNull("response_checksum_validation")

/**
* Parse a config value as a boolean, ignoring case.
*/
Expand Down
7 changes: 7 additions & 0 deletions buildSrc/build.gradle.kts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to exist? buildSrc is treated as an included build which means every subproject will have these config options applied.

It seems odd to need this just for codegen tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the best way I could find to share a data class between subprojects, do you know of alternatives that would work better? I might've missed them

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make a new project that both of those subprojects depend on

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still a work in progress, I don't want to block the review because of this. I think worst case scenario we can come back and refactor this without it being a breaking change

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
alias(libs.plugins.kotlin.jvm)
}

repositories {
mavenCentral()
}
7 changes: 7 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
19 changes: 19 additions & 0 deletions buildSrc/src/main/kotlin/aws/sdk/kotlin/shared/CodegenTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package aws.sdk.kotlin.shared

/**
* An AWS SDK for Kotlin codegen test
*/
data class CodegenTest(
val name: String,
val model: Model,
val serviceShapeId: String,
val protocolName: String? = null,
)

/**
* A smithy model file
*/
data class Model(
val fileName: String,
val path: String = "src/commonTest/resources/",
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ package aws.sdk.kotlin.codegen.customization.flexiblechecksums

import software.amazon.smithy.aws.traits.HttpChecksumTrait
import software.amazon.smithy.kotlin.codegen.KotlinSettings
import software.amazon.smithy.kotlin.codegen.core.CodegenContext
import software.amazon.smithy.kotlin.codegen.core.KotlinWriter
import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes
import software.amazon.smithy.kotlin.codegen.core.withBlock
import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration
import software.amazon.smithy.kotlin.codegen.model.*
import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator
import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolMiddleware
import software.amazon.smithy.kotlin.codegen.rendering.util.ConfigProperty
import software.amazon.smithy.kotlin.codegen.rendering.util.ConfigPropertyType
import software.amazon.smithy.kotlin.codegen.utils.getOrNull
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.OperationShape
Expand All @@ -26,8 +29,44 @@ class FlexibleChecksumsRequest : KotlinIntegration {
.shapes<OperationShape>()
.any { it.hasTrait<HttpChecksumTrait>() }

override fun additionalServiceConfigProps(ctx: CodegenContext): List<ConfigProperty> =
listOf(
ConfigProperty {
name = "requestChecksumCalculation"
symbol = RuntimeTypes.SmithyClient.Config.HttpChecksumConfigOption
baseClass = RuntimeTypes.SmithyClient.Config.HttpChecksumClientConfig
useNestedBuilderBaseClass()
documentation = "Configures request checksum calculation"
propertyType = ConfigPropertyType.RequiredWithDefault("HttpChecksumConfigOption.WHEN_SUPPORTED")
},
)

override fun customizeMiddleware(ctx: ProtocolGenerator.GenerationContext, resolved: List<ProtocolMiddleware>) =
resolved + flexibleChecksumsRequestMiddleware
resolved + flexibleChecksumsRequestMiddleware + configBusinessMetrics

private val configBusinessMetrics = object : ProtocolMiddleware {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: middleware name and value's name should match

override val name: String = "requestChecksumCalculationBusinessMetric"

override fun isEnabledFor(ctx: ProtocolGenerator.GenerationContext, op: OperationShape): Boolean =
op.hasTrait<HttpChecksumTrait>()

override fun render(ctx: ProtocolGenerator.GenerationContext, op: OperationShape, writer: KotlinWriter) {
writer.withBlock("when(config.requestChecksumCalculation) {", "}") {
writer.write(
"#T.WHEN_SUPPORTED -> op.context.#T(#T.FLEXIBLE_CHECKSUMS_REQ_WHEN_SUPPORTED)",
RuntimeTypes.SmithyClient.Config.HttpChecksumConfigOption,
RuntimeTypes.Core.BusinessMetrics.emitBusinessMetric,
RuntimeTypes.Core.BusinessMetrics.SmithyBusinessMetric,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: refactor duplicate calls to emitBusinessMetric

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are two different runtime types, emitBusinessMetric & SmithyBusinessMetric. What do you mean?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was meaning your two separate calls to emitBusinessMetric but I'm failing to see/remember what style refactor I was trying to suggest. This should be fine as is

)
writer.write(
"#T.WHEN_REQUIRED -> op.context.#T(#T.FLEXIBLE_CHECKSUMS_REQ_WHEN_REQUIRED)",
RuntimeTypes.SmithyClient.Config.HttpChecksumConfigOption,
RuntimeTypes.Core.BusinessMetrics.emitBusinessMetric,
RuntimeTypes.Core.BusinessMetrics.SmithyBusinessMetric,
)
}
}
}

private val flexibleChecksumsRequestMiddleware = object : ProtocolMiddleware {
override val name: String = "FlexibleChecksumsRequest"
Expand All @@ -42,7 +81,6 @@ class FlexibleChecksumsRequest : KotlinIntegration {
}

override fun render(ctx: ProtocolGenerator.GenerationContext, op: OperationShape, writer: KotlinWriter) {
val interceptorSymbol = RuntimeTypes.HttpClient.Interceptors.FlexibleChecksumsRequestInterceptor
val inputSymbol = ctx.symbolProvider.toSymbol(ctx.model.expectShape(op.inputShape))

val httpChecksumTrait = op.getTrait<HttpChecksumTrait>()!!
Expand All @@ -52,12 +90,17 @@ class FlexibleChecksumsRequest : KotlinIntegration {
.first { it.memberName == httpChecksumTrait.requestAlgorithmMember.get() }

val requestAlgorithmMemberName = ctx.symbolProvider.toMemberName(requestAlgorithmMember)
val requestChecksumRequired = httpChecksumTrait.isRequestChecksumRequired

writer.withBlock("op.interceptors.add(#T<#T>() {", "})", interceptorSymbol, inputSymbol) {
writer.write("input.#L?.value", requestAlgorithmMemberName)
}
writer.withBlock("input.#L?.let {", "}", requestAlgorithmMemberName) {
writer.write("op.context[#T.ChecksumAlgorithm] = it.value", RuntimeTypes.HttpClient.Operation.HttpOperationContext)
writer.withBlock(
"op.interceptors.add(#T<#T>(",
"))",
RuntimeTypes.HttpClient.Interceptors.FlexibleChecksumsRequestInterceptor,
inputSymbol,
) {
writer.write("#L,", requestChecksumRequired)
writer.write("config.requestChecksumCalculation,")
writer.write("input.#L?.value,", requestAlgorithmMemberName)
}
}
}
Expand Down
Loading
Loading