Skip to content

Commit 3e4fced

Browse files
authored
fix(rt): plumb client configuration properties (#730)
1 parent 1fc8459 commit 3e4fced

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"id": "c307c127-15ec-4c36-b559-5bbf17465197",
3+
"type": "bugfix",
4+
"description": "Pass client configuration's httpClientEngine to the CredentialsProvider and region to ProfileCredentialsProvider",
5+
"issues": ["#711"]
6+
}

aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/DefaultChainCredentialsProvider.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,22 @@ import aws.smithy.kotlin.runtime.util.PlatformProvider
3535
* @param platformProvider The platform API provider
3636
* @param httpClientEngine the [HttpClientEngine] instance to use to make requests. NOTE: This engine's resources and lifetime
3737
* are NOT managed by the provider. Caller is responsible for closing.
38+
* @param region the region to make credentials requests to.
3839
* @return the newly-constructed credentials provider
3940
*/
4041
public class DefaultChainCredentialsProvider constructor(
4142
private val profileName: String? = null,
4243
private val platformProvider: PlatformProvider = Platform,
4344
httpClientEngine: HttpClientEngine? = null,
45+
region: String? = null,
4446
) : CredentialsProvider, Closeable {
4547

4648
private val manageEngine = httpClientEngine == null
4749
private val httpClientEngine = httpClientEngine ?: DefaultHttpEngine()
4850

4951
private val chain = CredentialsProviderChain(
5052
EnvironmentCredentialsProvider(platformProvider::getenv),
51-
ProfileCredentialsProvider(profileName = profileName, platformProvider = platformProvider, httpClientEngine = httpClientEngine),
53+
ProfileCredentialsProvider(profileName = profileName, platformProvider = platformProvider, httpClientEngine = httpClientEngine, region = region),
5254
// STS web identity provider can be constructed from either the profile OR 100% from the environment
5355
StsWebIdentityProvider(platformProvider = platformProvider, httpClientEngine = httpClientEngine),
5456
EcsCredentialsProvider(platformProvider, httpClientEngine),

codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class AwsServiceConfigIntegration : KotlinIntegration {
2525
AWS region to make requests to
2626
""".trimIndent()
2727
propertyType = ClientConfigPropertyType.Required()
28+
order = -100
2829
}
2930

3031
val CredentialsProviderProp: ClientConfigProperty = ClientConfigProperty {
@@ -38,7 +39,7 @@ class AwsServiceConfigIntegration : KotlinIntegration {
3839

3940
propertyType = ClientConfigPropertyType.Custom(render = { prop, writer ->
4041
writer.write(
41-
"public val #1L: #2T = builder.#1L?.borrow() ?: #3T()",
42+
"public val #1L: #2T = builder.#1L?.borrow() ?: #3T(httpClientEngine = httpClientEngine, region = region)",
4243
prop.propertyName,
4344
prop.symbol,
4445
AwsRuntimeTypes.Config.Credentials.DefaultChainCredentialsProvider,

codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegrationTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,17 @@ class AwsServiceConfigIntegrationTest {
4343
val contents = writer.toString()
4444

4545
val expectedProps = """
46-
public val credentialsProvider: CredentialsProvider = builder.credentialsProvider?.borrow() ?: DefaultChainCredentialsProvider()
47-
public val endpointResolver: AwsEndpointResolver = builder.endpointResolver ?: DefaultEndpointResolver()
4846
public val region: String = requireNotNull(builder.region) { "region is a required configuration property" }
47+
public val credentialsProvider: CredentialsProvider = builder.credentialsProvider?.borrow() ?: DefaultChainCredentialsProvider(httpClientEngine = httpClientEngine, region = region)
48+
public val endpointResolver: AwsEndpointResolver = builder.endpointResolver ?: DefaultEndpointResolver()
4949
"""
5050
contents.shouldContainOnlyOnceWithDiff(expectedProps)
5151

5252
val expectedImpl = """
53+
/**
54+
* AWS region to make requests to
55+
*/
56+
public var region: String? = null
5357
/**
5458
* The AWS credentials provider to use for authenticating requests. If not provided a
5559
* [aws.sdk.kotlin.runtime.auth.credentials.DefaultChainCredentialsProvider] instance will be used.
@@ -62,10 +66,6 @@ class AwsServiceConfigIntegrationTest {
6266
* resolver is configured automatically. This is an advanced client option.
6367
*/
6468
public var endpointResolver: AwsEndpointResolver? = null
65-
/**
66-
* AWS region to make requests to
67-
*/
68-
public var region: String? = null
6969
"""
7070
contents.shouldContainOnlyOnceWithDiff(expectedImpl)
7171
}

0 commit comments

Comments
 (0)