From 68d98c93293f6d4e08bdd1b0419991f4d9c570f5 Mon Sep 17 00:00:00 2001 From: Aaron J Todd Date: Mon, 20 Nov 2023 11:06:50 -0500 Subject: [PATCH 1/2] refactor(rt): make region providers public --- .../3c7d640f-a734-4b7a-9939-1f3cb67f8cbb.json | 9 +++++ aws-runtime/aws-config/api/aws-config.api | 37 +++++++++++++++++++ .../region/DefaultRegionProviderChain.kt | 2 +- .../region/EnvironmentRegionProvider.kt | 2 +- .../runtime/region/ImdsRegionProvider.kt | 2 +- .../runtime/region/ProfileRegionProvider.kt | 7 +++- .../region/DefaultRegionProviderChainJVM.kt | 2 +- .../region/JvmSystemPropRegionProvider.kt | 5 ++- 8 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 .changes/3c7d640f-a734-4b7a-9939-1f3cb67f8cbb.json diff --git a/.changes/3c7d640f-a734-4b7a-9939-1f3cb67f8cbb.json b/.changes/3c7d640f-a734-4b7a-9939-1f3cb67f8cbb.json new file mode 100644 index 00000000000..1e220abc5c7 --- /dev/null +++ b/.changes/3c7d640f-a734-4b7a-9939-1f3cb67f8cbb.json @@ -0,0 +1,9 @@ +{ + "id": "3c7d640f-a734-4b7a-9939-1f3cb67f8cbb", + "type": "feature", + "description": "Make region providers public and allow profile name override", + "issues": [ + "awslabs/aws-sdk-kotlin#1002", + "awslabs/aws-sdk-kotlin#1003" + ] +} \ No newline at end of file diff --git a/aws-runtime/aws-config/api/aws-config.api b/aws-runtime/aws-config/api/aws-config.api index 0921c5f2c96..216ec7017b4 100644 --- a/aws-runtime/aws-config/api/aws-config.api +++ b/aws-runtime/aws-config/api/aws-config.api @@ -327,6 +327,43 @@ public final class aws/sdk/kotlin/runtime/config/retries/ResolveRetryStrategyKt public final class aws/sdk/kotlin/runtime/config/useragent/ResolveUserAgentKt { } +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 fun ()V + public fun (Laws/smithy/kotlin/runtime/util/PlatformProvider;Lkotlin/Lazy;Laws/smithy/kotlin/runtime/util/LazyAsyncValue;)V + public synthetic fun (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 fun ()V + public fun (Laws/smithy/kotlin/runtime/util/EnvironmentProvider;)V + public synthetic fun (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 fun ()V + public fun (Lkotlin/Lazy;Laws/smithy/kotlin/runtime/util/PlatformEnvironProvider;)V + public synthetic fun (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 fun ()V + public fun (Laws/smithy/kotlin/runtime/util/PropertyProvider;)V + public synthetic fun (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 fun ()V + public fun (Laws/smithy/kotlin/runtime/util/LazyAsyncValue;)V + public synthetic fun (Laws/smithy/kotlin/runtime/util/LazyAsyncValue;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public fun (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; } diff --git a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/DefaultRegionProviderChain.kt b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/DefaultRegionProviderChain.kt index 65e90e58314..92385e6ba39 100644 --- a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/DefaultRegionProviderChain.kt +++ b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/DefaultRegionProviderChain.kt @@ -21,7 +21,7 @@ import aws.smithy.kotlin.runtime.util.asyncLazy * 3. Check the AWS config files/profile for region information * 4. If running on EC2, check the EC2 metadata service for region */ -internal expect class DefaultRegionProviderChain constructor( +public expect class DefaultRegionProviderChain constructor( platformProvider: PlatformProvider = PlatformProvider.System, imdsClient: Lazy = lazy { ImdsClient() }, profile: LazyAsyncValue = asyncLazy { loadAwsSharedConfig(platformProvider).activeProfile }, diff --git a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/EnvironmentRegionProvider.kt b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/EnvironmentRegionProvider.kt index 954bb10bb29..c1058296510 100644 --- a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/EnvironmentRegionProvider.kt +++ b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/EnvironmentRegionProvider.kt @@ -13,7 +13,7 @@ import aws.smithy.kotlin.runtime.util.PlatformProvider * [RegionProvider] that checks `AWS_REGION` region environment variable * @param environ the environment mapping to lookup keys in (defaults to the system environment) */ -internal class EnvironmentRegionProvider( +public class EnvironmentRegionProvider( private val environ: EnvironmentProvider = PlatformProvider.System, ) : RegionProvider { override suspend fun getRegion(): String? = environ.getenv(AwsSdkSetting.AwsRegion.envVar) diff --git a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/ImdsRegionProvider.kt b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/ImdsRegionProvider.kt index edbdeec5f44..22bb84a0b3a 100644 --- a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/ImdsRegionProvider.kt +++ b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/ImdsRegionProvider.kt @@ -22,7 +22,7 @@ private const val REGION_PATH: String = "/latest/meta-data/placement/region" * @param client the IMDS client to use to resolve region information with * @param platformProvider the [PlatformEnvironProvider] instance */ -internal class ImdsRegionProvider( +public class ImdsRegionProvider( private val client: Lazy = lazy { ImdsClient() }, private val platformProvider: PlatformEnvironProvider = PlatformProvider.System, ) : RegionProvider, Closeable { diff --git a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/ProfileRegionProvider.kt b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/ProfileRegionProvider.kt index aab32e4b087..9e50d845d7b 100644 --- a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/ProfileRegionProvider.kt +++ b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/region/ProfileRegionProvider.kt @@ -15,8 +15,13 @@ import aws.smithy.kotlin.runtime.util.asyncLazy /** * [RegionProvider] that sources region information from the active profile */ -internal class ProfileRegionProvider( +public class ProfileRegionProvider( private val profile: LazyAsyncValue = asyncLazy { loadAwsSharedConfig(PlatformProvider.System).activeProfile }, ) : RegionProvider { + + /** + * Create a new [ProfileRegionProvider] that sources region from the given [profileName] + */ + public constructor(profileName: String) : this(asyncLazy { loadAwsSharedConfig(PlatformProvider.System, profileName).activeProfile }) override suspend fun getRegion(): String? = profile.get().region } diff --git a/aws-runtime/aws-config/jvm/src/aws/sdk/kotlin/runtime/region/DefaultRegionProviderChainJVM.kt b/aws-runtime/aws-config/jvm/src/aws/sdk/kotlin/runtime/region/DefaultRegionProviderChainJVM.kt index 6c0dbad60f1..237c089a9e4 100644 --- a/aws-runtime/aws-config/jvm/src/aws/sdk/kotlin/runtime/region/DefaultRegionProviderChainJVM.kt +++ b/aws-runtime/aws-config/jvm/src/aws/sdk/kotlin/runtime/region/DefaultRegionProviderChainJVM.kt @@ -11,7 +11,7 @@ import aws.smithy.kotlin.runtime.io.Closeable import aws.smithy.kotlin.runtime.util.LazyAsyncValue import aws.smithy.kotlin.runtime.util.PlatformProvider -internal actual class DefaultRegionProviderChain actual constructor( +public actual class DefaultRegionProviderChain actual constructor( platformProvider: PlatformProvider, imdsClient: Lazy, profile: LazyAsyncValue, diff --git a/aws-runtime/aws-config/jvm/src/aws/sdk/kotlin/runtime/region/JvmSystemPropRegionProvider.kt b/aws-runtime/aws-config/jvm/src/aws/sdk/kotlin/runtime/region/JvmSystemPropRegionProvider.kt index a28eb9839ba..e2be63a151a 100644 --- a/aws-runtime/aws-config/jvm/src/aws/sdk/kotlin/runtime/region/JvmSystemPropRegionProvider.kt +++ b/aws-runtime/aws-config/jvm/src/aws/sdk/kotlin/runtime/region/JvmSystemPropRegionProvider.kt @@ -6,13 +6,14 @@ package aws.sdk.kotlin.runtime.region import aws.sdk.kotlin.runtime.config.AwsSdkSetting +import aws.smithy.kotlin.runtime.util.PlatformProvider import aws.smithy.kotlin.runtime.util.PropertyProvider /** * [RegionProvider] that checks `aws.region` system property */ -internal class JvmSystemPropRegionProvider( - private val propertyProvider: PropertyProvider, +public class JvmSystemPropRegionProvider( + private val propertyProvider: PropertyProvider = PlatformProvider.System, ) : RegionProvider { override suspend fun getRegion(): String? = propertyProvider.getProperty(AwsSdkSetting.AwsRegion.sysProp) } From 0a2885e1bb24146e14f5f61f4e76f2a1a64124c5 Mon Sep 17 00:00:00 2001 From: Aaron J Todd Date: Mon, 20 Nov 2023 14:43:38 -0500 Subject: [PATCH 2/2] fix native --- .../kotlin/runtime/region/DefaultRegionProviderChainNative.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws-runtime/aws-config/native/src/aws/sdk/kotlin/runtime/region/DefaultRegionProviderChainNative.kt b/aws-runtime/aws-config/native/src/aws/sdk/kotlin/runtime/region/DefaultRegionProviderChainNative.kt index 699ce5304b5..777cd69903a 100644 --- a/aws-runtime/aws-config/native/src/aws/sdk/kotlin/runtime/region/DefaultRegionProviderChainNative.kt +++ b/aws-runtime/aws-config/native/src/aws/sdk/kotlin/runtime/region/DefaultRegionProviderChainNative.kt @@ -11,7 +11,7 @@ import aws.smithy.kotlin.runtime.io.Closeable import aws.smithy.kotlin.runtime.util.LazyAsyncValue import aws.smithy.kotlin.runtime.util.PlatformProvider -internal actual class DefaultRegionProviderChain actual constructor( +public actual class DefaultRegionProviderChain actual constructor( platformProvider: PlatformProvider, imdsClient: Lazy, profile: LazyAsyncValue,