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

refactor(rt): make region providers public #1123

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions .changes/3c7d640f-a734-4b7a-9939-1f3cb67f8cbb.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
37 changes: 37 additions & 0 deletions aws-runtime/aws-config/api/aws-config.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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 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 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 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 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<InstanceMetadataProvider> = lazy { ImdsClient() },
profile: LazyAsyncValue<AwsProfile> = asyncLazy { loadAwsSharedConfig(platformProvider).activeProfile },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<InstanceMetadataProvider> = lazy { ImdsClient() },
private val platformProvider: PlatformEnvironProvider = PlatformProvider.System,
) : RegionProvider, Closeable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AwsProfile> = 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<InstanceMetadataProvider>,
profile: LazyAsyncValue<AwsProfile>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<InstanceMetadataProvider>,
profile: LazyAsyncValue<AwsProfile>,
Expand Down
Loading