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

feat: provide client config property for region provider #1210

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ class RegionSupport : KotlinIntegration {
The region to sign with and make requests to.
""".trimIndent()
}

val RegionProviderProp: ConfigProperty = ConfigProperty {
name = "regionProvider"
symbol = RuntimeTypes.SmithyClient.Region.RegionProvider.asNullable()
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()
}
}

// Allow other integrations to customize the service config props, later integrations take precedence.
Expand All @@ -57,8 +70,10 @@ class RegionSupport : KotlinIntegration {
return supportsSigv4 || hasRegionBuiltin || isAwsSdk
}

override fun additionalServiceConfigProps(ctx: CodegenContext): List<ConfigProperty> = listOf(RegionProp)

override fun additionalServiceConfigProps(ctx: CodegenContext): List<ConfigProperty> = buildList {
add(RegionProp)
add(RegionProviderProp)
}
override fun customizeEndpointResolution(ctx: ProtocolGenerator.GenerationContext): EndpointCustomization =
object : EndpointCustomization {
override fun renderBindEndpointBuiltins(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ object RuntimeTypes {
val Url = symbol("Url")
}
}

object Region : RuntimeTypePackage(KotlinDependency.SMITHY_CLIENT, "region") {
val RegionProvider = symbol("RegionProvider")
}
}

object Serde : RuntimeTypePackage(KotlinDependency.SERDE) {
Expand Down Expand Up @@ -409,6 +413,7 @@ object RuntimeTypes {

val CompletableDeferred = "kotlinx.coroutines.CompletableDeferred".toSymbol()
val job = "kotlinx.coroutines.job".toSymbol()
val runBlocking = "kotlinx.coroutines.runBlocking".toSymbol()

object Flow {
// NOTE: smithy-kotlin core has an API dependency on this already
Expand Down
4 changes: 4 additions & 0 deletions runtime/smithy-client/api/smithy-client.api
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,7 @@ public final class aws/smithy/kotlin/runtime/client/endpoints/functions/Url {
public fun toString ()Ljava/lang/String;
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package aws.smithy.kotlin.runtime.client.region

/**
* Interface for providing AWS region information. Implementations are free to use any strategy for
* providing region information
*/
public interface RegionProvider {
/**
* Return the region name to use. If region information is not available, implementations should return null
*/
public suspend fun getRegion(): String?
}
Loading