Skip to content

Commit

Permalink
PR feedback and fix breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
0marperez committed Dec 3, 2024
1 parent fb3a52a commit 40bb298
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 15 deletions.
5 changes: 5 additions & 0 deletions runtime/protocol/http-client/api/http-client.api
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,19 @@ public final class aws/smithy/kotlin/runtime/http/interceptors/DiscoveredEndpoin
}

public final class aws/smithy/kotlin/runtime/http/interceptors/FlexibleChecksumsRequestInterceptor : aws/smithy/kotlin/runtime/http/interceptors/AbstractChecksumInterceptor {
public fun <init> ()V
public fun <init> (Lkotlin/jvm/functions/Function1;)V
public synthetic fun <init> (Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (ZLaws/smithy/kotlin/runtime/client/config/HttpChecksumConfigOption;Ljava/lang/String;)V
public fun applyChecksum (Laws/smithy/kotlin/runtime/client/ProtocolRequestInterceptorContext;Ljava/lang/String;)Laws/smithy/kotlin/runtime/http/request/HttpRequest;
public fun calculateChecksum (Laws/smithy/kotlin/runtime/client/ProtocolRequestInterceptorContext;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun modifyBeforeSigning (Laws/smithy/kotlin/runtime/client/ProtocolRequestInterceptorContext;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun readAfterSerialization (Laws/smithy/kotlin/runtime/client/ProtocolRequestInterceptorContext;)V
}

public final class aws/smithy/kotlin/runtime/http/interceptors/FlexibleChecksumsResponseInterceptor : aws/smithy/kotlin/runtime/client/Interceptor {
public static final field Companion Laws/smithy/kotlin/runtime/http/interceptors/FlexibleChecksumsResponseInterceptor$Companion;
public fun <init> (Lkotlin/jvm/functions/Function1;)V
public fun <init> (ZLaws/smithy/kotlin/runtime/client/config/HttpChecksumConfigOption;Z)V
public fun modifyBeforeAttemptCompletion-gIAlu-s (Laws/smithy/kotlin/runtime/client/ResponseInterceptorContext;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun modifyBeforeCompletion-gIAlu-s (Laws/smithy/kotlin/runtime/client/ResponseInterceptorContext;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,30 @@ import kotlin.coroutines.coroutineContext
* @param requestChecksumAlgorithm The checksum algorithm that the user selected for the request, may be null.
*/
@InternalApi
public class FlexibleChecksumsRequestInterceptor(
public class FlexibleChecksumsRequestInterceptor<I>(
requestChecksumRequired: Boolean,
requestChecksumCalculation: HttpChecksumConfigOption?,
requestChecksumAlgorithm: String?,
) : AbstractChecksumInterceptor() {

// FIXME: Remove in next minor version bump
@Deprecated("Old constructor is no longer used but it's kept for backwards compatibility")
public constructor() : this(
false,
HttpChecksumConfigOption.WHEN_REQUIRED,
null,
)

// FIXME: Remove in next minor version bump
@Deprecated("Old constructor is no longer used but it's kept for backwards compatibility")
public constructor(
checksumAlgorithmNameInitializer: ((I) -> String?)? = null,
) : this(
false,
HttpChecksumConfigOption.WHEN_REQUIRED,
null,
)

private val checksumHeader = buildString {
append("x-amz-checksum-")
append(requestChecksumAlgorithm?.lowercase() ?: "crc32")
Expand All @@ -71,8 +90,12 @@ public class FlexibleChecksumsRequestInterceptor(
null
}

// TODO: Remove in next minor version bump
@Deprecated("readAfterSerialization is no longer used but can't be removed due to backwards incompatibility")
override fun readAfterSerialization(context: ProtocolRequestInterceptorContext<Any, HttpRequest>) { }

override suspend fun modifyBeforeSigning(context: ProtocolRequestInterceptorContext<Any, HttpRequest>): HttpRequest {
val logger = coroutineContext.logger<FlexibleChecksumsRequestInterceptor>()
val logger = coroutineContext.logger<FlexibleChecksumsRequestInterceptor<I>>()

context.protocolRequest.userProvidedChecksumHeader(logger)?.let {
logger.debug { "Checksum was supplied via header, skipping checksum calculation" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,30 @@ internal val CHECKSUM_HEADER_VALIDATION_PRIORITY_LIST: List<String> = listOf(
* @param responseChecksumValidation Configuration option that determines when checksum validation should be done.
*/
@InternalApi
public class FlexibleChecksumsResponseInterceptor(
public class FlexibleChecksumsResponseInterceptor<I>(
private val responseValidationRequired: Boolean,
private val responseChecksumValidation: HttpChecksumConfigOption?,
private val serviceUsesCompositeChecksums: Boolean,
) : HttpInterceptor {

// FIXME: Remove in next minor version bump
@Deprecated("Old constructor is no longer used but it's kept for backwards compatibility")
public constructor(
shouldValidateResponseChecksumInitializer: (input: I) -> Boolean,
) : this(
false,
HttpChecksumConfigOption.WHEN_REQUIRED,
false,
)

@InternalApi
public companion object {
// The name of the checksum header which was validated. If `null`, validation was not performed.
public val ChecksumHeaderValidated: AttributeKey<String> = AttributeKey("ChecksumHeaderValidated")
}

override suspend fun modifyBeforeDeserialization(context: ProtocolResponseInterceptorContext<Any, HttpRequest, HttpResponse>): HttpResponse {
val logger = coroutineContext.logger<FlexibleChecksumsResponseInterceptor>()
val logger = coroutineContext.logger<FlexibleChecksumsResponseInterceptor<I>>()

val forcedToVerifyChecksum = responseValidationRequired || responseChecksumValidation == HttpChecksumConfigOption.WHEN_SUPPORTED
if (!forcedToVerifyChecksum) return context.protocolResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class FlexibleChecksumsRequestInterceptorTest {
val op = newTestOperation<Unit, Unit>(req, Unit)

op.interceptors.add(
FlexibleChecksumsRequestInterceptor(
FlexibleChecksumsRequestInterceptor<Unit>(
requestChecksumAlgorithm = checksumAlgorithmName,
requestChecksumRequired = true,
requestChecksumCalculation = HttpChecksumConfigOption.WHEN_SUPPORTED,
Expand All @@ -69,7 +69,7 @@ class FlexibleChecksumsRequestInterceptorTest {
val op = newTestOperation<Unit, Unit>(req, Unit)

op.interceptors.add(
FlexibleChecksumsRequestInterceptor(
FlexibleChecksumsRequestInterceptor<Unit>(
requestChecksumAlgorithm = checksumAlgorithmName,
requestChecksumRequired = true,
requestChecksumCalculation = HttpChecksumConfigOption.WHEN_SUPPORTED,
Expand All @@ -94,7 +94,7 @@ class FlexibleChecksumsRequestInterceptorTest {

assertFailsWith<ClientException> {
op.interceptors.add(
FlexibleChecksumsRequestInterceptor(
FlexibleChecksumsRequestInterceptor<Unit>(
requestChecksumAlgorithm = unsupportedChecksumAlgorithmName,
requestChecksumRequired = true,
requestChecksumCalculation = HttpChecksumConfigOption.WHEN_SUPPORTED,
Expand All @@ -120,7 +120,7 @@ class FlexibleChecksumsRequestInterceptorTest {
val op = newTestOperation<Unit, Unit>(req, Unit)

op.interceptors.add(
FlexibleChecksumsRequestInterceptor(
FlexibleChecksumsRequestInterceptor<Unit>(
requestChecksumAlgorithm = checksumAlgorithmName,
requestChecksumRequired = true,
requestChecksumCalculation = HttpChecksumConfigOption.WHEN_SUPPORTED,
Expand Down Expand Up @@ -188,7 +188,7 @@ class FlexibleChecksumsRequestInterceptorTest {
val op = newTestOperation<Unit, Unit>(req, Unit)

op.interceptors.add(
FlexibleChecksumsRequestInterceptor(
FlexibleChecksumsRequestInterceptor<Unit>(
requestChecksumAlgorithm = checksumAlgorithmName,
requestChecksumRequired = true,
requestChecksumCalculation = HttpChecksumConfigOption.WHEN_SUPPORTED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class FlexibleChecksumsResponseInterceptorTest {
val op = newTestOperation<TestInput>(req)

op.interceptors.add(
FlexibleChecksumsResponseInterceptor(
FlexibleChecksumsResponseInterceptor<TestInput>(
responseValidationRequired = true,
responseChecksumValidation = HttpChecksumConfigOption.WHEN_SUPPORTED,
serviceUsesCompositeChecksums = false,
Expand Down Expand Up @@ -102,7 +102,7 @@ class FlexibleChecksumsResponseInterceptorTest {
val op = newTestOperation<TestInput>(req)

op.interceptors.add(
FlexibleChecksumsResponseInterceptor(
FlexibleChecksumsResponseInterceptor<TestInput>(
responseValidationRequired = true,
responseChecksumValidation = HttpChecksumConfigOption.WHEN_SUPPORTED,
serviceUsesCompositeChecksums = false,
Expand Down Expand Up @@ -131,7 +131,7 @@ class FlexibleChecksumsResponseInterceptorTest {
val op = newTestOperation<TestInput>(req)

op.interceptors.add(
FlexibleChecksumsResponseInterceptor(
FlexibleChecksumsResponseInterceptor<TestInput>(
responseValidationRequired = true,
responseChecksumValidation = HttpChecksumConfigOption.WHEN_SUPPORTED,
serviceUsesCompositeChecksums = false,
Expand All @@ -157,7 +157,7 @@ class FlexibleChecksumsResponseInterceptorTest {
val op = newTestOperation<TestInput>(req)

op.interceptors.add(
FlexibleChecksumsResponseInterceptor(
FlexibleChecksumsResponseInterceptor<TestInput>(
responseValidationRequired = true,
responseChecksumValidation = HttpChecksumConfigOption.WHEN_SUPPORTED,
serviceUsesCompositeChecksums = false,
Expand All @@ -179,11 +179,11 @@ class FlexibleChecksumsResponseInterceptorTest {
val op = newTestOperation<TestInput>(req)

op.interceptors.add(
FlexibleChecksumsResponseInterceptor (
FlexibleChecksumsResponseInterceptor<TestInput>(
responseValidationRequired = false,
responseChecksumValidation = HttpChecksumConfigOption.WHEN_REQUIRED,
serviceUsesCompositeChecksums = false,
)
),
)

val responseChecksumHeaderName = "x-amz-checksum-crc32"
Expand Down
1 change: 1 addition & 0 deletions runtime/runtime-core/api/runtime-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public final class aws/smithy/kotlin/runtime/businessmetrics/SmithyBusinessMetri
public static final field WAITER Laws/smithy/kotlin/runtime/businessmetrics/SmithyBusinessMetric;
public static fun getEntries ()Lkotlin/enums/EnumEntries;
public fun getIdentifier ()Ljava/lang/String;
public fun toString ()Ljava/lang/String;
public static fun valueOf (Ljava/lang/String;)Laws/smithy/kotlin/runtime/businessmetrics/SmithyBusinessMetric;
public static fun values ()[Laws/smithy/kotlin/runtime/businessmetrics/SmithyBusinessMetric;
}
Expand Down

0 comments on commit 40bb298

Please sign in to comment.