Skip to content

Commit

Permalink
Added getters & setters for region to several credential providers
Browse files Browse the repository at this point in the history
  • Loading branch information
0marperez committed Jul 11, 2023
1 parent 74fb92d commit 25ff04b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions aws-runtime/aws-config/api/aws-config.api
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ public final class aws/sdk/kotlin/runtime/auth/credentials/ProfileCredentialsPro
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 close ()V
public final fun getRegion ()Ljava/lang/String;
public fun resolve (Laws/smithy/kotlin/runtime/util/Attributes;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun setRegion (Ljava/lang/String;)V
}

public final class aws/sdk/kotlin/runtime/auth/credentials/ProviderConfigurationException : aws/sdk/kotlin/runtime/ConfigurationException {
Expand Down Expand Up @@ -114,7 +116,9 @@ public final class aws/sdk/kotlin/runtime/auth/credentials/StaticCredentialsProv
public final class aws/sdk/kotlin/runtime/auth/credentials/StsAssumeRoleCredentialsProvider : aws/smithy/kotlin/runtime/auth/awscredentials/CredentialsProvider {
public synthetic fun <init> (Laws/smithy/kotlin/runtime/auth/awscredentials/CredentialsProvider;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JLaws/smithy/kotlin/runtime/http/engine/HttpClientEngine;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Laws/smithy/kotlin/runtime/auth/awscredentials/CredentialsProvider;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JLaws/smithy/kotlin/runtime/http/engine/HttpClientEngine;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun getRegion ()Ljava/lang/String;
public fun resolve (Laws/smithy/kotlin/runtime/util/Attributes;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun setRegion (Ljava/lang/String;)V
}

public final class aws/sdk/kotlin/runtime/auth/credentials/StsWebIdentityCredentialsProvider : aws/smithy/kotlin/runtime/auth/awscredentials/CredentialsProvider {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import aws.sdk.kotlin.runtime.config.AwsSdkSetting
import aws.sdk.kotlin.runtime.config.imds.ImdsClient
import aws.sdk.kotlin.runtime.config.profile.loadAwsSharedConfig
import aws.sdk.kotlin.runtime.region.resolveRegion
import aws.smithy.kotlin.runtime.InternalApi
import aws.smithy.kotlin.runtime.auth.awscredentials.CloseableCredentialsProvider
import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
import aws.smithy.kotlin.runtime.auth.awscredentials.CredentialsProvider
Expand Down Expand Up @@ -75,7 +76,7 @@ import kotlin.coroutines.coroutineContext
*/
public class ProfileCredentialsProvider(
private val profileName: String? = null,
private val region: String? = null,
private var region: String? = null,
private val platformProvider: PlatformProvider = PlatformProvider.System,
private val httpClient: HttpClientEngine? = null,
) : CloseableCredentialsProvider {
Expand All @@ -94,6 +95,14 @@ public class ProfileCredentialsProvider(
"EcsContainer" to EcsCredentialsProvider(platformProvider, httpClient),
)

@InternalApi
public fun getRegion(): String? = region

@InternalApi
public fun setRegion(region: String) {
this.region = region
}

override suspend fun resolve(attributes: Attributes): Credentials {
val logger = coroutineContext.getLogger<ProfileCredentialsProvider>()
val sharedConfig = loadAwsSharedConfig(platformProvider, profileName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import aws.sdk.kotlin.runtime.auth.credentials.internal.sts.StsClient
import aws.sdk.kotlin.runtime.auth.credentials.internal.sts.assumeRole
import aws.sdk.kotlin.runtime.auth.credentials.internal.sts.model.RegionDisabledException
import aws.sdk.kotlin.runtime.config.AwsSdkSetting
import aws.smithy.kotlin.runtime.InternalApi
import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
import aws.smithy.kotlin.runtime.auth.awscredentials.CredentialsProvider
import aws.smithy.kotlin.runtime.auth.awscredentials.CredentialsProviderException
Expand All @@ -18,7 +19,9 @@ import aws.smithy.kotlin.runtime.http.engine.HttpClientEngine
import aws.smithy.kotlin.runtime.time.Instant
import aws.smithy.kotlin.runtime.time.TimestampFormat
import aws.smithy.kotlin.runtime.time.epochMilliseconds
import aws.smithy.kotlin.runtime.tracing.*
import aws.smithy.kotlin.runtime.tracing.asNestedTracer
import aws.smithy.kotlin.runtime.tracing.logger
import aws.smithy.kotlin.runtime.tracing.traceSpan
import aws.smithy.kotlin.runtime.util.Attributes
import aws.smithy.kotlin.runtime.util.PlatformEnvironProvider
import aws.smithy.kotlin.runtime.util.PlatformProvider
Expand Down Expand Up @@ -52,13 +55,21 @@ private const val PROVIDER_NAME = "AssumeRoleProvider"
public class StsAssumeRoleCredentialsProvider(
private val credentialsProvider: CredentialsProvider,
private val roleArn: String,
private val region: String? = null,
private var region: String? = null,
private val roleSessionName: String? = null,
private val externalId: String? = null,
private val duration: Duration = DEFAULT_CREDENTIALS_REFRESH_SECONDS.seconds,
private val httpClient: HttpClientEngine? = null,
) : CredentialsProvider {

@InternalApi
public fun getRegion(): String? = region

@InternalApi
public fun setRegion(region: String) {
this.region = region
}

override suspend fun resolve(attributes: Attributes): Credentials {
val traceSpan = coroutineContext.traceSpan
val logger = traceSpan.logger<StsAssumeRoleCredentialsProvider>()
Expand Down

0 comments on commit 25ff04b

Please sign in to comment.