Skip to content

Commit

Permalink
fix: Add optional configurationSource parameter to `ProfileCredenti…
Browse files Browse the repository at this point in the history
…alsProvider` (#1140)
  • Loading branch information
lauzadis authored Dec 1, 2023
1 parent f09c714 commit 8dfa5af
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changes/d7c1e490-7fc3-48fe-8faf-914a5f09c671.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "d7c1e490-7fc3-48fe-8faf-914a5f09c671",
"type": "misc",
"description": "Add optional `configurationSource` parameter to `ProfileCredentialsProvider`"
}
4 changes: 2 additions & 2 deletions aws-runtime/aws-config/api/aws-config.api
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public final class aws/sdk/kotlin/runtime/auth/credentials/ProcessCredentialsPro

public final class aws/sdk/kotlin/runtime/auth/credentials/ProfileCredentialsProvider : aws/smithy/kotlin/runtime/auth/awscredentials/CloseableCredentialsProvider {
public fun <init> ()V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Laws/smithy/kotlin/runtime/util/PlatformProvider;Laws/smithy/kotlin/runtime/http/engine/HttpClientEngine;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Laws/smithy/kotlin/runtime/util/PlatformProvider;Laws/smithy/kotlin/runtime/http/engine/HttpClientEngine;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Laws/smithy/kotlin/runtime/util/PlatformProvider;Laws/smithy/kotlin/runtime/http/engine/HttpClientEngine;Laws/sdk/kotlin/runtime/config/profile/AwsConfigurationSource;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Laws/smithy/kotlin/runtime/util/PlatformProvider;Laws/smithy/kotlin/runtime/http/engine/HttpClientEngine;Laws/sdk/kotlin/runtime/config/profile/AwsConfigurationSource;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun close ()V
public final fun getHttpClient ()Laws/smithy/kotlin/runtime/http/engine/HttpClientEngine;
public final fun getPlatformProvider ()Laws/smithy/kotlin/runtime/util/PlatformProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import aws.sdk.kotlin.runtime.auth.credentials.profile.RoleArn
import aws.sdk.kotlin.runtime.client.AwsClientOption
import aws.sdk.kotlin.runtime.config.AwsSdkSetting
import aws.sdk.kotlin.runtime.config.imds.ImdsClient
import aws.sdk.kotlin.runtime.config.profile.AwsConfigurationSource
import aws.sdk.kotlin.runtime.config.profile.loadAwsSharedConfig
import aws.sdk.kotlin.runtime.region.resolveRegion
import aws.smithy.kotlin.runtime.auth.awscredentials.CloseableCredentialsProvider
Expand Down Expand Up @@ -73,12 +74,15 @@ import kotlin.coroutines.coroutineContext
* @param platformProvider The platform API provider
* @param httpClient 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 configurationSource An optional configuration source to use for loading shared config. If not provided,
* it will be resolved from the environment.
*/
public class ProfileCredentialsProvider(
public val profileName: String? = null,
public val region: String? = null,
public val platformProvider: PlatformProvider = PlatformProvider.System,
public val httpClient: HttpClientEngine? = null,
private val configurationSource: AwsConfigurationSource? = null,
) : CloseableCredentialsProvider {
private val namedProviders = mapOf(
"Environment" to EnvironmentCredentialsProvider(platformProvider::getenv),
Expand All @@ -97,7 +101,7 @@ public class ProfileCredentialsProvider(

override suspend fun resolve(attributes: Attributes): Credentials {
val logger = coroutineContext.logger<ProfileCredentialsProvider>()
val sharedConfig = loadAwsSharedConfig(platformProvider, profileName)
val sharedConfig = loadAwsSharedConfig(platformProvider, profileName, configurationSource)
logger.debug { "Loading credentials from profile `${sharedConfig.activeProfile.name}`" }
val chain = ProfileChain.resolve(sharedConfig)

Expand Down

0 comments on commit 8dfa5af

Please sign in to comment.