diff --git a/.changes/f164451a-1adc-4220-9a7d-1765959c23d3.json b/.changes/f164451a-1adc-4220-9a7d-1765959c23d3.json new file mode 100644 index 00000000000..3fa22df23d7 --- /dev/null +++ b/.changes/f164451a-1adc-4220-9a7d-1765959c23d3.json @@ -0,0 +1,9 @@ +{ + "id": "f164451a-1adc-4220-9a7d-1765959c23d3", + "type": "bugfix", + "description": "⚠️ **IMPORTANT**: Apply clock skew interceptor to clients created via `invoke`", + "issues": [ + "awslabs/aws-sdk-kotlin#1211" + ], + "requiresMinorVersionBump": true +} diff --git a/aws-runtime/aws-config/api/aws-config.api b/aws-runtime/aws-config/api/aws-config.api index dd458dfb8cf..05589280306 100644 --- a/aws-runtime/aws-config/api/aws-config.api +++ b/aws-runtime/aws-config/api/aws-config.api @@ -215,12 +215,11 @@ public final class aws/sdk/kotlin/runtime/auth/credentials/internal/ManagedCrede public static final fun manage (Laws/smithy/kotlin/runtime/auth/awscredentials/CloseableCredentialsProvider;)Laws/smithy/kotlin/runtime/auth/awscredentials/CredentialsProvider; } -public abstract class aws/sdk/kotlin/runtime/config/AbstractAwsSdkClientFactory : aws/smithy/kotlin/runtime/client/SdkClientFactory { +public abstract class aws/sdk/kotlin/runtime/config/AbstractAwsSdkClientFactory : aws/smithy/kotlin/runtime/client/AbstractSdkClientFactory { public fun ()V - protected fun finalizeConfig (Laws/smithy/kotlin/runtime/client/SdkClient$Builder;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + protected fun finalizeEnvironmentalConfig (Laws/smithy/kotlin/runtime/client/SdkClient$Builder;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun fromEnvironment (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun fromEnvironment$default (Laws/sdk/kotlin/runtime/config/AbstractAwsSdkClientFactory;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; - public fun invoke (Lkotlin/jvm/functions/Function1;)Laws/smithy/kotlin/runtime/client/SdkClient; } public final class aws/sdk/kotlin/runtime/config/AwsSdkSetting { diff --git a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/AbstractAwsSdkClientFactory.kt b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/AbstractAwsSdkClientFactory.kt index b4c1fccea6b..ed5f4b0cd99 100644 --- a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/AbstractAwsSdkClientFactory.kt +++ b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/AbstractAwsSdkClientFactory.kt @@ -19,10 +19,7 @@ import aws.sdk.kotlin.runtime.region.resolveRegion import aws.sdk.kotlin.runtime.region.resolveSigV4aSigningRegionSet import aws.smithy.kotlin.runtime.ExperimentalApi import aws.smithy.kotlin.runtime.auth.awscredentials.SigV4aClientConfig -import aws.smithy.kotlin.runtime.client.RetryStrategyClientConfig -import aws.smithy.kotlin.runtime.client.SdkClient -import aws.smithy.kotlin.runtime.client.SdkClientConfig -import aws.smithy.kotlin.runtime.client.SdkClientFactory +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.config.resolve @@ -46,7 +43,7 @@ public abstract class AbstractAwsSdkClientFactory< TConfigBuilder, TClient : SdkClient, TClientBuilder : SdkClient.Builder, - > : SdkClientFactory + > : AbstractSdkClientFactory() where TConfig : SdkClientConfig, TConfig : AwsSdkClientConfig, TConfigBuilder : SdkClientConfig.Builder, @@ -97,7 +94,8 @@ public abstract class AbstractAwsSdkClientFactory< config.sigV4aSigningRegionSet ?: resolveSigV4aSigningRegionSet(platform, profile) } - finalizeConfig(builder, sharedConfig, profile) + finalizeConfig(builder) + finalizeEnvironmentalConfig(builder, sharedConfig, profile) } return builder.build() } @@ -105,7 +103,7 @@ public abstract class AbstractAwsSdkClientFactory< /** * Inject any client-specific config. */ - protected open suspend fun finalizeConfig( + protected open suspend fun finalizeEnvironmentalConfig( builder: TClientBuilder, sharedConfig: LazyAsyncValue, activeProfile: LazyAsyncValue, diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt index 766ee91ebbc..044fd39bb71 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt @@ -121,6 +121,13 @@ class AwsServiceConfigIntegration : KotlinIntegration { override val sectionWriters: List = listOf( SectionWriterBinding(ServiceClientGenerator.Sections.CompanionObject, ServiceClientCompanionObjectWriter()), + SectionWriterBinding(ServiceClientGenerator.Sections.CompanionObject.SuperTypes) { writer, _ -> + writer.write( + "#T()", + AwsRuntimeTypes.Config.AbstractAwsSdkClientFactory, + writer.getContextValue(ServiceClientGenerator.Sections.CompanionObject.ServiceSymbol), + ) + }, ) override fun additionalServiceConfigProps(ctx: CodegenContext): List = buildList { diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/ServiceClientCompanionObjectWriter.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/ServiceClientCompanionObjectWriter.kt index 918d0bb5c05..4f015735231 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/ServiceClientCompanionObjectWriter.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/ServiceClientCompanionObjectWriter.kt @@ -5,8 +5,8 @@ package aws.sdk.kotlin.codegen import software.amazon.smithy.kotlin.codegen.core.* -import software.amazon.smithy.kotlin.codegen.integration.SectionWriter -import software.amazon.smithy.kotlin.codegen.lang.KotlinTypes +import software.amazon.smithy.kotlin.codegen.integration.AppendingSectionWriter +import software.amazon.smithy.kotlin.codegen.integration.SectionId import software.amazon.smithy.kotlin.codegen.rendering.ServiceClientGenerator import software.amazon.smithy.kotlin.codegen.utils.toPascalCase @@ -15,38 +15,27 @@ import software.amazon.smithy.kotlin.codegen.utils.toPascalCase * * Includes the ability to extend the config finalizer, which by default handles resolution of endpoint url config. */ -class ServiceClientCompanionObjectWriter : SectionWriter { - override fun write(writer: KotlinWriter, previousValue: String?) { - val serviceSymbol = writer.getContextValue(ServiceClientGenerator.Sections.CompanionObject.ServiceSymbol) +class ServiceClientCompanionObjectWriter : AppendingSectionWriter { + /** + * The [SectionId] used for rendering the `finalizeEnvironmentalConfig` method body. + */ + object FinalizeEnvironmentalConfig : SectionId + override fun append(writer: KotlinWriter) { + val funName = "finalizeEnvironmentalConfig" + writer.write("") writer.withBlock( - "public companion object : #T() {", - "}", - AwsRuntimeTypes.Config.AbstractAwsSdkClientFactory, - serviceSymbol, - ) { - writeBuilder() - write("") - - writeFinalizeConfig() - } - } - - private fun KotlinWriter.writeBuilder() { - write("@#T", KotlinTypes.Jvm.JvmStatic) - write("override fun builder(): Builder = Builder()") - } - - private fun KotlinWriter.writeFinalizeConfig() { - withBlock( - "override suspend fun finalizeConfig(builder: Builder, sharedConfig: #1T<#2T>, activeProfile: #1T<#3T>) {", + "override suspend fun #1L(builder: Builder, sharedConfig: #2T<#3T>, activeProfile: #2T<#4T>) {", "}", + funName, RuntimeTypes.Core.Utils.LazyAsyncValue, AwsRuntimeTypes.Config.Profile.AwsSharedConfig, AwsRuntimeTypes.Config.Profile.AwsProfile, ) { - writeResolveEndpointUrl() - declareSection(ServiceClientGenerator.Sections.FinalizeConfig) + declareSection(FinalizeEnvironmentalConfig) { + write("super.#L(builder, sharedConfig, activeProfile)", funName) + writeResolveEndpointUrl() + } } } diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/AccountIdEndpointBuiltinCustomization.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/AccountIdEndpointBuiltinCustomization.kt index 89f72199399..104e19d863e 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/AccountIdEndpointBuiltinCustomization.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/AccountIdEndpointBuiltinCustomization.kt @@ -5,6 +5,7 @@ package aws.sdk.kotlin.codegen.customization import aws.sdk.kotlin.codegen.AwsRuntimeTypes +import aws.sdk.kotlin.codegen.ServiceClientCompanionObjectWriter import aws.sdk.kotlin.codegen.endpoints.AwsBuiltins import software.amazon.smithy.kotlin.codegen.KotlinSettings import software.amazon.smithy.kotlin.codegen.core.CodegenContext @@ -13,7 +14,6 @@ import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding import software.amazon.smithy.kotlin.codegen.model.expectShape import software.amazon.smithy.kotlin.codegen.model.getEndpointRules -import software.amazon.smithy.kotlin.codegen.rendering.ServiceClientGenerator import software.amazon.smithy.kotlin.codegen.rendering.util.ConfigProperty import software.amazon.smithy.kotlin.codegen.rendering.util.ConfigPropertyType import software.amazon.smithy.model.Model @@ -42,7 +42,12 @@ class AccountIdEndpointBuiltinCustomization : KotlinIntegration { } override val sectionWriters: List - get() = listOf(SectionWriterBinding(ServiceClientGenerator.Sections.FinalizeConfig, resolveAccountIdEndpointModeSectionWriter)) + get() = listOf( + SectionWriterBinding( + ServiceClientCompanionObjectWriter.FinalizeEnvironmentalConfig, + resolveAccountIdEndpointModeSectionWriter, + ), + ) private val resolveAccountIdEndpointModeSectionWriter = AppendingSectionWriter { writer -> writer.write( diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/ClientConfigIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/ClientConfigIntegration.kt index 82fd6388ac1..1019d976ee0 100644 --- a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/ClientConfigIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/ClientConfigIntegration.kt @@ -4,6 +4,7 @@ */ package aws.sdk.kotlin.codegen.customization.s3 +import aws.sdk.kotlin.codegen.ServiceClientCompanionObjectWriter import software.amazon.smithy.kotlin.codegen.KotlinSettings import software.amazon.smithy.kotlin.codegen.core.CodegenContext import software.amazon.smithy.kotlin.codegen.integration.AppendingSectionWriter @@ -12,7 +13,6 @@ import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding import software.amazon.smithy.kotlin.codegen.lang.KotlinTypes import software.amazon.smithy.kotlin.codegen.model.buildSymbol import software.amazon.smithy.kotlin.codegen.model.expectShape -import software.amazon.smithy.kotlin.codegen.rendering.ServiceClientGenerator import software.amazon.smithy.kotlin.codegen.rendering.util.ConfigProperty import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape @@ -96,7 +96,12 @@ class ClientConfigIntegration : KotlinIntegration { ) override val sectionWriters: List - get() = listOf(SectionWriterBinding(ServiceClientGenerator.Sections.FinalizeConfig, finalizeS3ConfigWriter)) + get() = listOf( + SectionWriterBinding( + ServiceClientCompanionObjectWriter.FinalizeEnvironmentalConfig, + finalizeS3ConfigWriter, + ), + ) // add S3-specific config finalization private val finalizeS3ConfigWriter = AppendingSectionWriter { writer -> diff --git a/codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/ServiceClientCompanionObjectWriterTest.kt b/codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/ServiceClientCompanionObjectWriterTest.kt index 9a5d4c0fe59..e8c8346afa6 100644 --- a/codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/ServiceClientCompanionObjectWriterTest.kt +++ b/codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/ServiceClientCompanionObjectWriterTest.kt @@ -23,18 +23,14 @@ class ServiceClientCompanionObjectWriterTest { ServiceClientCompanionObjectWriter().write(writer, null) val expected = """ - public companion object : AbstractAwsSdkClientFactory() { - @JvmStatic - override fun builder(): Builder = Builder() - - override suspend fun finalizeConfig(builder: Builder, sharedConfig: LazyAsyncValue, activeProfile: LazyAsyncValue) { - builder.config.endpointUrl = builder.config.endpointUrl ?: resolveEndpointUrl( - sharedConfig, - "TestGenerator", - "TEST_GENERATOR", - "test_generator", - ) - } + override suspend fun finalizeEnvironmentalConfig(builder: Builder, sharedConfig: LazyAsyncValue, activeProfile: LazyAsyncValue) { + super.finalizeEnvironmentalConfig(builder, sharedConfig, activeProfile) + builder.config.endpointUrl = builder.config.endpointUrl ?: resolveEndpointUrl( + sharedConfig, + "TestGenerator", + "TEST_GENERATOR", + "test_generator", + ) } """.trimIndent() diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 28d6a59a159..a42f43d4d8b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -9,8 +9,8 @@ coroutines-version = "1.7.3" atomicfu-version = "0.23.1" # smithy-kotlin codegen and runtime are versioned separately -smithy-kotlin-runtime-version = "1.1.3" -smithy-kotlin-codegen-version = "0.31.3" +smithy-kotlin-runtime-version = "1.1.4-SNAPSHOT" +smithy-kotlin-codegen-version = "0.31.4-SNAPSHOT" # codegen smithy-version = "1.47.0"