Skip to content

Commit

Permalink
address pr reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
xinsong-cui committed Jan 10, 2025
1 parent 82dfc9d commit c2eebae
Show file tree
Hide file tree
Showing 18 changed files with 53 additions and 75 deletions.
26 changes: 11 additions & 15 deletions aws-runtime/aws-config/api/aws-config.api
Original file line number Diff line number Diff line change
Expand Up @@ -225,20 +225,20 @@ public abstract class aws/sdk/kotlin/runtime/config/AbstractAwsSdkClientFactory
public abstract interface class aws/sdk/kotlin/runtime/config/AwsSdkClientConfig : aws/smithy/kotlin/runtime/client/SdkClientConfig {
public abstract fun getApplicationId ()Ljava/lang/String;
public abstract fun getRegion ()Ljava/lang/String;
public abstract fun getRegionProvider ()Laws/sdk/kotlin/runtime/region/RegionProvider;
public abstract fun getRegionProvider ()Laws/smithy/kotlin/runtime/client/region/RegionProvider;
public abstract fun getUseDualStack ()Z
public abstract fun getUseFips ()Z
}

public abstract interface class aws/sdk/kotlin/runtime/config/AwsSdkClientConfig$Builder {
public abstract fun getApplicationId ()Ljava/lang/String;
public abstract fun getRegion ()Ljava/lang/String;
public abstract fun getRegionProvider ()Laws/sdk/kotlin/runtime/region/RegionProvider;
public abstract fun getRegionProvider ()Laws/smithy/kotlin/runtime/client/region/RegionProvider;
public abstract fun getUseDualStack ()Ljava/lang/Boolean;
public abstract fun getUseFips ()Ljava/lang/Boolean;
public abstract fun setApplicationId (Ljava/lang/String;)V
public abstract fun setRegion (Ljava/lang/String;)V
public abstract fun setRegionProvider (Laws/sdk/kotlin/runtime/region/RegionProvider;)V
public abstract fun setRegionProvider (Laws/smithy/kotlin/runtime/client/region/RegionProvider;)V
public abstract fun setUseDualStack (Ljava/lang/Boolean;)V
public abstract fun setUseFips (Ljava/lang/Boolean;)V
}
Expand Down Expand Up @@ -533,51 +533,47 @@ public final class aws/sdk/kotlin/runtime/config/useragent/ResolveUserAgentKt {
public static synthetic fun resolveUserAgentAppId$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/region/DefaultRegionProviderChain : aws/sdk/kotlin/runtime/region/RegionProviderChain, aws/sdk/kotlin/runtime/region/RegionProvider, java/io/Closeable {
public final class aws/sdk/kotlin/runtime/region/DefaultRegionProviderChain : aws/sdk/kotlin/runtime/region/RegionProviderChain, aws/smithy/kotlin/runtime/client/region/RegionProvider, java/io/Closeable {
public fun <init> ()V
public fun <init> (Laws/smithy/kotlin/runtime/util/PlatformProvider;Lkotlin/Lazy;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;)V
public synthetic fun <init> (Laws/smithy/kotlin/runtime/util/PlatformProvider;Lkotlin/Lazy;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun close ()V
}

public final class aws/sdk/kotlin/runtime/region/EnvironmentRegionProvider : aws/sdk/kotlin/runtime/region/RegionProvider {
public final class aws/sdk/kotlin/runtime/region/EnvironmentRegionProvider : aws/smithy/kotlin/runtime/client/region/RegionProvider {
public fun <init> ()V
public fun <init> (Laws/smithy/kotlin/runtime/util/EnvironmentProvider;)V
public synthetic fun <init> (Laws/smithy/kotlin/runtime/util/EnvironmentProvider;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun getRegion (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public final class aws/sdk/kotlin/runtime/region/ImdsRegionProvider : aws/sdk/kotlin/runtime/region/RegionProvider, java/io/Closeable {
public final class aws/sdk/kotlin/runtime/region/ImdsRegionProvider : aws/smithy/kotlin/runtime/client/region/RegionProvider, java/io/Closeable {
public fun <init> ()V
public fun <init> (Lkotlin/Lazy;Laws/smithy/kotlin/runtime/util/PlatformEnvironProvider;)V
public synthetic fun <init> (Lkotlin/Lazy;Laws/smithy/kotlin/runtime/util/PlatformEnvironProvider;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun close ()V
public fun getRegion (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public final class aws/sdk/kotlin/runtime/region/JvmSystemPropRegionProvider : aws/sdk/kotlin/runtime/region/RegionProvider {
public final class aws/sdk/kotlin/runtime/region/JvmSystemPropRegionProvider : aws/smithy/kotlin/runtime/client/region/RegionProvider {
public fun <init> ()V
public fun <init> (Laws/smithy/kotlin/runtime/util/PropertyProvider;)V
public synthetic fun <init> (Laws/smithy/kotlin/runtime/util/PropertyProvider;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun getRegion (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public final class aws/sdk/kotlin/runtime/region/ProfileRegionProvider : aws/sdk/kotlin/runtime/region/RegionProvider {
public final class aws/sdk/kotlin/runtime/region/ProfileRegionProvider : aws/smithy/kotlin/runtime/client/region/RegionProvider {
public fun <init> ()V
public fun <init> (Laws/smithy/kotlin/runtime/util/LazyAsyncValue;)V
public synthetic fun <init> (Laws/smithy/kotlin/runtime/util/LazyAsyncValue;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;)V
public fun getRegion (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public abstract interface class aws/sdk/kotlin/runtime/region/RegionProvider {
public abstract fun getRegion (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public class aws/sdk/kotlin/runtime/region/RegionProviderChain : aws/sdk/kotlin/runtime/region/RegionProvider {
public class aws/sdk/kotlin/runtime/region/RegionProviderChain : aws/smithy/kotlin/runtime/client/region/RegionProvider {
public fun <init> (Ljava/util/List;)V
public fun <init> ([Laws/sdk/kotlin/runtime/region/RegionProvider;)V
protected final fun getProviders ()[Laws/sdk/kotlin/runtime/region/RegionProvider;
public fun <init> ([Laws/smithy/kotlin/runtime/client/region/RegionProvider;)V
protected final fun getProviders ()[Laws/smithy/kotlin/runtime/client/region/RegionProvider;
public fun getRegion (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun toString ()Ljava/lang/String;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

package aws.sdk.kotlin.runtime.config

import aws.sdk.kotlin.runtime.region.RegionProvider
import aws.smithy.kotlin.runtime.client.SdkClientConfig
import aws.smithy.kotlin.runtime.client.region.RegionProvider

/**
* Base interface all generated AWS SDK Kotlin clients implement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import aws.sdk.kotlin.runtime.config.imds.ImdsClient
import aws.sdk.kotlin.runtime.config.imds.InstanceMetadataProvider
import aws.sdk.kotlin.runtime.config.profile.AwsProfile
import aws.sdk.kotlin.runtime.config.profile.loadAwsSharedConfig
import aws.smithy.kotlin.runtime.client.region.RegionProvider
import aws.smithy.kotlin.runtime.io.Closeable
import aws.smithy.kotlin.runtime.util.LazyAsyncValue
import aws.smithy.kotlin.runtime.util.PlatformProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package aws.sdk.kotlin.runtime.region

import aws.sdk.kotlin.runtime.config.AwsSdkSetting
import aws.smithy.kotlin.runtime.client.region.RegionProvider
import aws.smithy.kotlin.runtime.util.EnvironmentProvider
import aws.smithy.kotlin.runtime.util.PlatformProvider

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package aws.sdk.kotlin.runtime.region
import aws.sdk.kotlin.runtime.config.AwsSdkSetting
import aws.sdk.kotlin.runtime.config.imds.ImdsClient
import aws.sdk.kotlin.runtime.config.imds.InstanceMetadataProvider
import aws.smithy.kotlin.runtime.client.region.RegionProvider
import aws.smithy.kotlin.runtime.config.resolve
import aws.smithy.kotlin.runtime.io.Closeable
import aws.smithy.kotlin.runtime.util.PlatformEnvironProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package aws.sdk.kotlin.runtime.region
import aws.sdk.kotlin.runtime.config.profile.AwsProfile
import aws.sdk.kotlin.runtime.config.profile.loadAwsSharedConfig
import aws.sdk.kotlin.runtime.config.profile.region
import aws.smithy.kotlin.runtime.client.region.RegionProvider
import aws.smithy.kotlin.runtime.util.LazyAsyncValue
import aws.smithy.kotlin.runtime.util.PlatformProvider
import aws.smithy.kotlin.runtime.util.asyncLazy
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package aws.sdk.kotlin.runtime.region

import aws.smithy.kotlin.runtime.client.region.RegionProvider
import aws.smithy.kotlin.runtime.telemetry.logging.logger
import aws.smithy.kotlin.runtime.util.asyncLazy
import kotlin.coroutines.coroutineContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package aws.sdk.kotlin.runtime.region

import aws.smithy.kotlin.runtime.client.region.RegionProvider
import kotlinx.coroutines.test.runTest
import kotlin.test.Test
import kotlin.test.assertEquals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package aws.sdk.kotlin.runtime.region

import aws.sdk.kotlin.runtime.config.imds.InstanceMetadataProvider
import aws.sdk.kotlin.runtime.config.profile.AwsProfile
import aws.smithy.kotlin.runtime.client.region.RegionProvider
import aws.smithy.kotlin.runtime.io.Closeable
import aws.smithy.kotlin.runtime.util.LazyAsyncValue
import aws.smithy.kotlin.runtime.util.PlatformProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package aws.sdk.kotlin.runtime.region

import aws.sdk.kotlin.runtime.config.AwsSdkSetting
import aws.smithy.kotlin.runtime.client.region.RegionProvider
import aws.smithy.kotlin.runtime.util.PlatformProvider
import aws.smithy.kotlin.runtime.util.PropertyProvider

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ package aws.sdk.kotlin.runtime.config
import aws.sdk.kotlin.runtime.config.profile.loadAwsSharedConfig
import aws.sdk.kotlin.runtime.config.useragent.resolveUserAgentAppId
import aws.sdk.kotlin.runtime.config.utils.mockPlatform
import aws.sdk.kotlin.runtime.region.RegionProvider
import aws.smithy.kotlin.runtime.client.*
import aws.smithy.kotlin.runtime.client.region.RegionProvider
import aws.smithy.kotlin.runtime.retries.StandardRetryStrategy
import aws.smithy.kotlin.runtime.util.PlatformProvider
import aws.smithy.kotlin.runtime.util.asyncLazy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ object AwsRuntimeTypes {
}

object Region : RuntimeTypePackage(AwsKotlinDependency.AWS_CONFIG, "region") {
val RegionProvider = symbol("RegionProvider")
val resolveRegion = symbol("resolveRegion")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class AwsServiceConfigIntegration : KotlinIntegration {
propertyType = ConfigPropertyType.Custom(
render = { prop, writer ->
writer.write(
"override val #1L: #2T? = builder.#1L ?: #3T { builder.regionProvider?.getRegion() ?: #4T() }",
"override val #1L: #2T? = builder.#1L ?: #3T { builder.regionProvider ?.getRegion() ?: #4T() }",
prop.propertyName,
prop.symbol,
KotlinTypes.Coroutines.runBlocking,
RuntimeTypes.KotlinxCoroutines.runBlocking,
AwsRuntimeTypes.Config.Region.resolveRegion,
)
},
Expand All @@ -47,6 +47,23 @@ class AwsServiceConfigIntegration : KotlinIntegration {
order = -100
}

val RegionProviderProp: ConfigProperty = ConfigProperty {
name = "regionProvider"
symbol = RuntimeTypes.SmithyClient.Region.RegionProvider.asNullable()
baseClass = AwsRuntimeTypes.Config.AwsSdkClientConfig
useNestedBuilderBaseClass()
documentation = """
An optional region provider that determines the AWS region for client operations. When specified, this provider
takes precedence over the default region provider chain, unless a static region is explicitly configured.
The region resolution order is:
1. Static region (if specified)
2. Custom region provider (if configured)
3. Default region provider chain
""".trimIndent()

order = -100
}

val UserAgentAppId: ConfigProperty = ConfigProperty {
name = "applicationId"
symbol = KotlinTypes.String.asNullable()
Expand Down Expand Up @@ -145,6 +162,7 @@ class AwsServiceConfigIntegration : KotlinIntegration {

override fun additionalServiceConfigProps(ctx: CodegenContext): List<ConfigProperty> = buildList {
add(RegionProp)
add(RegionProviderProp)
if (AwsSignatureVersion4.isSupportedAuthentication(ctx.model, ctx.settings.getService(ctx.model))) {
add(CredentialsProviderProp)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ aws.sdk.kotlin.codegen.AddUserAgentMetadataIntegration
aws.sdk.kotlin.codegen.AwsServiceConfigIntegration
aws.sdk.kotlin.codegen.GradleGenerator
aws.sdk.kotlin.codegen.AwsRetryHeaderIntegration
aws.sdk.kotlin.codegen.RegionProviderIntegration
aws.sdk.kotlin.codegen.customization.ReplaceServiceExceptionBase
aws.sdk.kotlin.codegen.customization.DefaultMiddleware
aws.sdk.kotlin.codegen.customization.AccountIdEndpointBuiltinCustomization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class AwsServiceConfigIntegrationTest {
val contents = writer.toString()

val expectedProps = """
override val region: String? = builder.region ?: runBlocking { builder.regionProvider?.getRegion() ?: resolveRegion() }
override val region: String? = builder.region ?: runBlocking { builder.regionProvider ?.getRegion() ?: resolveRegion() }
override val regionProvider: RegionProvider? = builder.regionProvider
override val credentialsProvider: CredentialsProvider = builder.credentialsProvider ?: DefaultChainCredentialsProvider(httpClient = httpClient, region = region).manage()
"""
contents.shouldContainOnlyOnceWithDiff(expectedProps)
Expand All @@ -58,6 +59,16 @@ class AwsServiceConfigIntegrationTest {
*/
override var region: String? = null
/**
* An optional region provider that determines the AWS region for client operations. When specified, this provider
* takes precedence over the default region provider chain, unless a static region is explicitly configured.
* The region resolution order is:
* 1. Static region (if specified)
* 2. Custom region provider (if configured)
* 3. Default region provider chain
*/
override var regionProvider: RegionProvider? = null
/**
* The AWS credentials provider to use for authenticating requests. If not provided a
* [aws.sdk.kotlin.runtime.auth.credentials.DefaultChainCredentialsProvider] instance will be used.
Expand Down
3 changes: 0 additions & 3 deletions tests/codegen/event-stream/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ tasks.generateSmithyProjections {
// ensure the generated tests use the same version of the runtime as the aws aws-runtime
val smithyKotlinRuntimeVersion = libs.versions.smithy.kotlin.runtime.version.get()
System.setProperty("smithy.kotlin.codegen.clientRuntimeVersion", smithyKotlinRuntimeVersion)

val smithyKotlinCoroutinesVersion = libs.versions.coroutines.version.get()
System.setProperty("smithy.kotlin.codegen.kotlinCoroutinesVersion", smithyKotlinCoroutinesVersion)
}
}

Expand Down

0 comments on commit c2eebae

Please sign in to comment.