From c97cad3b3e37c77ca48e736762c73e4610cbd3dc Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 18 Oct 2022 15:50:44 -0500 Subject: [PATCH 1/9] Pass client config's httpClientEngine to CredentialsProvider --- .../aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt index dc9ef4b347f..5b3a61f07d4 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt @@ -38,7 +38,7 @@ class AwsServiceConfigIntegration : KotlinIntegration { propertyType = ClientConfigPropertyType.Custom(render = { prop, writer -> writer.write( - "public val #1L: #2T = builder.#1L?.borrow() ?: #3T()", + "public val #1L: #2T = builder.#1L?.borrow() ?: #3T(httpClientEngine = httpClientEngine)", prop.propertyName, prop.symbol, AwsRuntimeTypes.Config.Credentials.DefaultChainCredentialsProvider, From 84b50ed7d8f022e216cac67ed8cd0df62c3e1367 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 18 Oct 2022 15:54:28 -0500 Subject: [PATCH 2/9] Add changelog --- .changes/c307c127-15ec-4c36-b559-5bbf17465197.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/c307c127-15ec-4c36-b559-5bbf17465197.json diff --git a/.changes/c307c127-15ec-4c36-b559-5bbf17465197.json b/.changes/c307c127-15ec-4c36-b559-5bbf17465197.json new file mode 100644 index 00000000000..5d3964107df --- /dev/null +++ b/.changes/c307c127-15ec-4c36-b559-5bbf17465197.json @@ -0,0 +1,6 @@ +{ + "id": "c307c127-15ec-4c36-b559-5bbf17465197", + "type": "bugfix", + "description": "Pass client configuration's httpClientEngine to the CredentialsProvider", + "issues": ["#711"] +} \ No newline at end of file From 3a6e9865e3dd7f117f86002b8dea204aa3e85387 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 18 Oct 2022 16:40:22 -0500 Subject: [PATCH 3/9] pass region to ProfileCredentialsProvider --- .../auth/credentials/DefaultChainCredentialsProvider.kt | 3 ++- .../aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/DefaultChainCredentialsProvider.kt b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/DefaultChainCredentialsProvider.kt index 7f79d53fd02..23d3c4729e0 100644 --- a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/DefaultChainCredentialsProvider.kt +++ b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/DefaultChainCredentialsProvider.kt @@ -41,6 +41,7 @@ public class DefaultChainCredentialsProvider constructor( private val profileName: String? = null, private val platformProvider: PlatformProvider = Platform, httpClientEngine: HttpClientEngine? = null, + region: String? = null ) : CredentialsProvider, Closeable { private val manageEngine = httpClientEngine == null @@ -48,7 +49,7 @@ public class DefaultChainCredentialsProvider constructor( private val chain = CredentialsProviderChain( EnvironmentCredentialsProvider(platformProvider::getenv), - ProfileCredentialsProvider(profileName = profileName, platformProvider = platformProvider, httpClientEngine = httpClientEngine), + ProfileCredentialsProvider(profileName = profileName, platformProvider = platformProvider, httpClientEngine = httpClientEngine, region = region), // STS web identity provider can be constructed from either the profile OR 100% from the environment StsWebIdentityProvider(platformProvider = platformProvider, httpClientEngine = httpClientEngine), EcsCredentialsProvider(platformProvider, httpClientEngine), diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt index 5b3a61f07d4..6c647ae9796 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt @@ -25,6 +25,7 @@ class AwsServiceConfigIntegration : KotlinIntegration { AWS region to make requests to """.trimIndent() propertyType = ClientConfigPropertyType.Required() + order = -1 } val CredentialsProviderProp: ClientConfigProperty = ClientConfigProperty { @@ -38,7 +39,7 @@ class AwsServiceConfigIntegration : KotlinIntegration { propertyType = ClientConfigPropertyType.Custom(render = { prop, writer -> writer.write( - "public val #1L: #2T = builder.#1L?.borrow() ?: #3T(httpClientEngine = httpClientEngine)", + "public val #1L: #2T = builder.#1L?.borrow() ?: #3T(httpClientEngine = httpClientEngine, region = region)", prop.propertyName, prop.symbol, AwsRuntimeTypes.Config.Credentials.DefaultChainCredentialsProvider, From 15e92a9efff17bdf664bbcfb343cd54e9ea312a9 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 18 Oct 2022 16:41:21 -0500 Subject: [PATCH 4/9] Update changelog --- .changes/c307c127-15ec-4c36-b559-5bbf17465197.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changes/c307c127-15ec-4c36-b559-5bbf17465197.json b/.changes/c307c127-15ec-4c36-b559-5bbf17465197.json index 5d3964107df..9fef78d2a36 100644 --- a/.changes/c307c127-15ec-4c36-b559-5bbf17465197.json +++ b/.changes/c307c127-15ec-4c36-b559-5bbf17465197.json @@ -1,6 +1,6 @@ { "id": "c307c127-15ec-4c36-b559-5bbf17465197", "type": "bugfix", - "description": "Pass client configuration's httpClientEngine to the CredentialsProvider", + "description": "Pass client configuration's httpClientEngine to the CredentialsProvider and region to ProfileCredentialsProvider", "issues": ["#711"] } \ No newline at end of file From 61bcbc0cf30c477c55857840a7af41019a7bb5aa Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 18 Oct 2022 17:05:55 -0500 Subject: [PATCH 5/9] ktlint --- .../runtime/auth/credentials/DefaultChainCredentialsProvider.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/DefaultChainCredentialsProvider.kt b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/DefaultChainCredentialsProvider.kt index 23d3c4729e0..e35bfa8fb64 100644 --- a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/DefaultChainCredentialsProvider.kt +++ b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/DefaultChainCredentialsProvider.kt @@ -41,7 +41,7 @@ public class DefaultChainCredentialsProvider constructor( private val profileName: String? = null, private val platformProvider: PlatformProvider = Platform, httpClientEngine: HttpClientEngine? = null, - region: String? = null + region: String? = null, ) : CredentialsProvider, Closeable { private val manageEngine = httpClientEngine == null From 91b81b3f33a5e598c18666ceedf4a6484292dfb3 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Wed, 19 Oct 2022 12:06:34 -0500 Subject: [PATCH 6/9] update test case with new behavior --- .../codegen/AwsServiceConfigIntegrationTest.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegrationTest.kt b/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegrationTest.kt index d63ca656c5d..1ea206903b3 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegrationTest.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegrationTest.kt @@ -43,13 +43,17 @@ class AwsServiceConfigIntegrationTest { val contents = writer.toString() val expectedProps = """ - public val credentialsProvider: CredentialsProvider = builder.credentialsProvider?.borrow() ?: DefaultChainCredentialsProvider() - public val endpointResolver: AwsEndpointResolver = builder.endpointResolver ?: DefaultEndpointResolver() public val region: String = requireNotNull(builder.region) { "region is a required configuration property" } + public val credentialsProvider: CredentialsProvider = builder.credentialsProvider?.borrow() ?: DefaultChainCredentialsProvider(httpClientEngine = httpClientEngine, region = region) + public val endpointResolver: AwsEndpointResolver = builder.endpointResolver ?: DefaultEndpointResolver() """ contents.shouldContainOnlyOnceWithDiff(expectedProps) val expectedImpl = """ + /** + * AWS region to make requests to + */ + public var region: String? = 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. @@ -62,10 +66,6 @@ class AwsServiceConfigIntegrationTest { * resolver is configured automatically. This is an advanced client option. */ public var endpointResolver: AwsEndpointResolver? = null - /** - * AWS region to make requests to - */ - public var region: String? = null """ contents.shouldContainOnlyOnceWithDiff(expectedImpl) } From 15076cdbf32d116d13318d6ad253b466036ec5b3 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Wed, 19 Oct 2022 13:34:12 -0500 Subject: [PATCH 7/9] tickle CI From fc9ca58630ddf2ed91326259f13468dfe9c1a1d1 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 21 Oct 2022 11:55:48 -0500 Subject: [PATCH 8/9] add kdocs for region parameter --- .../runtime/auth/credentials/DefaultChainCredentialsProvider.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/DefaultChainCredentialsProvider.kt b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/DefaultChainCredentialsProvider.kt index e35bfa8fb64..eba237bcd1a 100644 --- a/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/DefaultChainCredentialsProvider.kt +++ b/aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/DefaultChainCredentialsProvider.kt @@ -35,6 +35,7 @@ import aws.smithy.kotlin.runtime.util.PlatformProvider * @param platformProvider The platform API provider * @param httpClientEngine the [HttpClientEngine] instance to use to make requests. NOTE: This engine's resources and lifetime * are NOT managed by the provider. Caller is responsible for closing. + * @param region the region to make credentials requests to. * @return the newly-constructed credentials provider */ public class DefaultChainCredentialsProvider constructor( From 6b08e2838e285c82f6913cb939b5761ef4ea063e Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Fri, 21 Oct 2022 11:56:11 -0500 Subject: [PATCH 9/9] bump `order` to -100 --- .../aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt index 6c647ae9796..e5c575490fd 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt @@ -25,7 +25,7 @@ class AwsServiceConfigIntegration : KotlinIntegration { AWS region to make requests to """.trimIndent() propertyType = ClientConfigPropertyType.Required() - order = -1 + order = -100 } val CredentialsProviderProp: ClientConfigProperty = ClientConfigProperty {