Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
0marperez committed Nov 4, 2024
1 parent 573facd commit 85b78d7
Show file tree
Hide file tree
Showing 24 changed files with 92 additions and 117 deletions.
18 changes: 11 additions & 7 deletions aws-runtime/aws-config/api/aws-config.api
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,6 @@ public final class aws/sdk/kotlin/runtime/auth/credentials/InvalidSsoTokenExcept
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/Throwable;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
}

public final class aws/sdk/kotlin/runtime/auth/credentials/LazilyInitializedCredentialsProvider : aws/smithy/kotlin/runtime/auth/awscredentials/CredentialsProvider {
public fun <init> (Ljava/lang/String;Laws/smithy/kotlin/runtime/businessmetrics/BusinessMetric;Lkotlin/jvm/functions/Function0;)V
public synthetic fun <init> (Ljava/lang/String;Laws/smithy/kotlin/runtime/businessmetrics/BusinessMetric;Lkotlin/jvm/functions/Function0;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun resolve (Laws/smithy/kotlin/runtime/collections/Attributes;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun toString ()Ljava/lang/String;
}

public final class aws/sdk/kotlin/runtime/auth/credentials/ProcessCredentialsProvider : aws/smithy/kotlin/runtime/auth/awscredentials/CredentialsProvider {
public fun <init> (Ljava/lang/String;Laws/smithy/kotlin/runtime/util/PlatformProvider;JJ)V
public synthetic fun <init> (Ljava/lang/String;Laws/smithy/kotlin/runtime/util/PlatformProvider;JJILkotlin/jvm/internal/DefaultConstructorMarker;)V
Expand Down Expand Up @@ -216,6 +209,17 @@ public final class aws/sdk/kotlin/runtime/auth/credentials/StsWebIdentityCredent
public static synthetic fun fromEnvironment-TUY-ock$default (Laws/sdk/kotlin/runtime/auth/credentials/StsWebIdentityCredentialsProvider$Companion;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JLaws/smithy/kotlin/runtime/util/PlatformProvider;Laws/smithy/kotlin/runtime/http/engine/HttpClientEngine;ILjava/lang/Object;)Laws/sdk/kotlin/runtime/auth/credentials/StsWebIdentityCredentialsProvider;
}

public final class aws/sdk/kotlin/runtime/auth/credentials/StsWebIdentityProvider : aws/smithy/kotlin/runtime/auth/awscredentials/CloseableCredentialsProvider {
public fun <init> ()V
public fun <init> (Laws/smithy/kotlin/runtime/util/PlatformProvider;Laws/smithy/kotlin/runtime/http/engine/HttpClientEngine;Ljava/lang/String;)V
public synthetic fun <init> (Laws/smithy/kotlin/runtime/util/PlatformProvider;Laws/smithy/kotlin/runtime/http/engine/HttpClientEngine;Ljava/lang/String;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;
public final fun getRegion ()Ljava/lang/String;
public fun resolve (Laws/smithy/kotlin/runtime/collections/Attributes;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public final class aws/sdk/kotlin/runtime/auth/credentials/SystemPropertyCredentialsProvider : aws/smithy/kotlin/runtime/auth/awscredentials/CredentialsProvider {
public fun <init> ()V
public fun <init> (Lkotlin/jvm/functions/Function1;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package aws.sdk.kotlin.runtime.auth.credentials
import aws.sdk.kotlin.runtime.config.AwsSdkSetting
import aws.sdk.kotlin.runtime.config.imds.ImdsClient
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.AwsBusinessMetric
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.withBusinessMetric
import aws.smithy.kotlin.runtime.auth.awscredentials.*
import aws.smithy.kotlin.runtime.collections.Attributes
import aws.smithy.kotlin.runtime.http.engine.DefaultHttpEngine
Expand Down Expand Up @@ -53,17 +54,8 @@ public class DefaultChainCredentialsProvider constructor(
private val chain = CredentialsProviderChain(
SystemPropertyCredentialsProvider(platformProvider::getProperty),
EnvironmentCredentialsProvider(platformProvider::getenv),
LazilyInitializedCredentialsProvider(
"EnvironmentStsWebIdentityCredentialsProvider",
AwsBusinessMetric.Credentials.CREDENTIALS_ENV_VARS_STS_WEB_ID_TOKEN,
) {
// STS web identity provider can be constructed from either the profile OR 100% from the environment
StsWebIdentityCredentialsProvider.fromEnvironment(
platformProvider = platformProvider,
httpClient = httpClient,
region = region,
)
},
// STS web identity provider can be constructed from either the profile OR 100% from the environment
StsWebIdentityProvider(platformProvider = platformProvider, httpClient = engine, region = region),
ProfileCredentialsProvider(profileName = profileName, platformProvider = platformProvider, httpClient = engine, region = region),
EcsCredentialsProvider(platformProvider, engine),
ImdsCredentialsProvider(
Expand All @@ -90,3 +82,20 @@ public class DefaultChainCredentialsProvider constructor(

override fun toString(): String = this.simpleClassName + ": " + this.chain
}

/**
* Wrapper around [StsWebIdentityCredentialsProvider] that delays any exceptions until [resolve] is invoked.
* This allows it to be part of the default chain and any failures result in the chain to move onto the next provider.
*/
public class StsWebIdentityProvider(
public val platformProvider: PlatformProvider = PlatformProvider.System,
public val httpClient: HttpClientEngine? = null,
public val region: String? = null,
) : CloseableCredentialsProvider {
override suspend fun resolve(attributes: Attributes): Credentials {
val wrapped = StsWebIdentityCredentialsProvider.fromEnvironment(platformProvider = platformProvider, httpClient = httpClient, region = region)
return wrapped.resolve(attributes).withBusinessMetric(AwsBusinessMetric.Credentials.CREDENTIALS_ENV_VARS_STS_WEB_ID_TOKEN)
}

override fun close() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package aws.sdk.kotlin.runtime.auth.credentials
import aws.sdk.kotlin.runtime.auth.credentials.internal.credentials
import aws.sdk.kotlin.runtime.config.AwsSdkSetting
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.AwsBusinessMetric
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.emitBusinessMetric
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.withBusinessMetric
import aws.smithy.kotlin.runtime.ErrorMetadata
import aws.smithy.kotlin.runtime.auth.awscredentials.*
import aws.smithy.kotlin.runtime.client.endpoints.Endpoint
Expand Down Expand Up @@ -113,7 +113,7 @@ public class EcsCredentialsProvider(

logger.debug { "obtained credentials from container metadata service; expiration=${creds.expiration?.format(TimestampFormat.ISO_8601)}" }

return creds.emitBusinessMetric(AwsBusinessMetric.Credentials.CREDENTIALS_HTTP)
return creds.withBusinessMetric(AwsBusinessMetric.Credentials.CREDENTIALS_HTTP)
}

private suspend fun loadAuthToken(): String? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package aws.sdk.kotlin.runtime.auth.credentials
import aws.sdk.kotlin.runtime.auth.credentials.internal.credentials
import aws.sdk.kotlin.runtime.config.AwsSdkSetting
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.AwsBusinessMetric
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.emitBusinessMetric
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.withBusinessMetric
import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
import aws.smithy.kotlin.runtime.auth.awscredentials.CredentialsProvider
import aws.smithy.kotlin.runtime.auth.awscredentials.simpleClassName
Expand Down Expand Up @@ -45,7 +45,7 @@ public class EnvironmentCredentialsProvider(
sessionToken = getEnv(SESSION_TOKEN),
providerName = PROVIDER_NAME,
accountId = getEnv(ACCOUNT_ID),
).emitBusinessMetric(AwsBusinessMetric.Credentials.CREDENTIALS_ENV_VARS)
).withBusinessMetric(AwsBusinessMetric.Credentials.CREDENTIALS_ENV_VARS)
}

override fun toString(): String = this.simpleClassName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import aws.sdk.kotlin.runtime.config.imds.EC2MetadataError
import aws.sdk.kotlin.runtime.config.imds.ImdsClient
import aws.sdk.kotlin.runtime.config.imds.InstanceMetadataProvider
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.AwsBusinessMetric
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.emitBusinessMetric
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.withBusinessMetric
import aws.smithy.kotlin.runtime.auth.awscredentials.*
import aws.smithy.kotlin.runtime.collections.Attributes
import aws.smithy.kotlin.runtime.config.resolve
Expand Down Expand Up @@ -108,7 +108,7 @@ public class ImdsCredentialsProvider(
resp.sessionToken,
resp.expiration,
PROVIDER_NAME,
).emitBusinessMetric(AwsBusinessMetric.Credentials.CREDENTIALS_IMDS)
).withBusinessMetric(AwsBusinessMetric.Credentials.CREDENTIALS_IMDS)

creds.also {
mu.withLock { previousCredentials = it }
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package aws.sdk.kotlin.runtime.auth.credentials

import aws.sdk.kotlin.runtime.auth.credentials.internal.credentials
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.AwsBusinessMetric
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.emitBusinessMetric
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.withBusinessMetric
import aws.smithy.kotlin.runtime.auth.awscredentials.*
import aws.smithy.kotlin.runtime.collections.Attributes
import aws.smithy.kotlin.runtime.serde.json.JsonDeserializer
Expand Down Expand Up @@ -75,7 +75,7 @@ public class ProcessCredentialsProvider(
resp.expiration ?: Instant.MAX_VALUE,
PROVIDER_NAME,
resp.accountId,
).emitBusinessMetric(AwsBusinessMetric.Credentials.CREDENTIALS_PROCESS)
).withBusinessMetric(AwsBusinessMetric.Credentials.CREDENTIALS_PROCESS)
}
else -> throw CredentialsProviderException("Credentials response was not of expected format")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ 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.http.interceptors.businessmetrics.AwsBusinessMetric
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.emitBusinessMetrics
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.withBusinessMetrics
import aws.sdk.kotlin.runtime.region.resolveRegion
import aws.smithy.kotlin.runtime.auth.awscredentials.*
import aws.smithy.kotlin.runtime.businessmetrics.BusinessMetric
Expand Down Expand Up @@ -148,7 +148,7 @@ public class ProfileCredentialsProvider @InternalSdkApi constructor(
}

logger.debug { "Obtained credentials from profile; expiration=${creds.expiration?.format(TimestampFormat.ISO_8601)}" }
return creds.emitBusinessMetrics(credentialsBusinessMetrics)
return creds.withBusinessMetrics(credentialsBusinessMetrics)
}

override fun close() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import aws.sdk.kotlin.runtime.auth.credentials.internal.credentials
import aws.sdk.kotlin.runtime.auth.credentials.internal.sso.SsoClient
import aws.sdk.kotlin.runtime.auth.credentials.internal.sso.getRoleCredentials
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.AwsBusinessMetric
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.emitBusinessMetric
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.withBusinessMetric
import aws.smithy.kotlin.runtime.auth.awscredentials.*
import aws.smithy.kotlin.runtime.client.SdkClientOption
import aws.smithy.kotlin.runtime.collections.Attributes
Expand Down Expand Up @@ -129,9 +129,9 @@ public class SsoCredentialsProvider public constructor(
)

return if (ssoTokenProvider != null) {
creds.emitBusinessMetric(AwsBusinessMetric.Credentials.CREDENTIALS_SSO)
creds.withBusinessMetric(AwsBusinessMetric.Credentials.CREDENTIALS_SSO)
} else {
creds.emitBusinessMetric(AwsBusinessMetric.Credentials.CREDENTIALS_SSO_LEGACY)
creds.withBusinessMetric(AwsBusinessMetric.Credentials.CREDENTIALS_SSO_LEGACY)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import aws.sdk.kotlin.runtime.auth.credentials.internal.sts.model.RegionDisabled
import aws.sdk.kotlin.runtime.auth.credentials.internal.sts.model.Tag
import aws.sdk.kotlin.runtime.config.AwsSdkSetting
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.AwsBusinessMetric
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.emitBusinessMetric
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.withBusinessMetric
import aws.smithy.kotlin.runtime.auth.awscredentials.*
import aws.smithy.kotlin.runtime.client.SdkClientOption
import aws.smithy.kotlin.runtime.collections.Attributes
Expand Down Expand Up @@ -148,7 +148,7 @@ public class StsAssumeRoleCredentialsProvider(
expiration = roleCredentials.expiration,
providerName = PROVIDER_NAME,
accountId = accountId,
).emitBusinessMetric(AwsBusinessMetric.Credentials.CREDENTIALS_STS_ASSUME_ROLE)
).withBusinessMetric(AwsBusinessMetric.Credentials.CREDENTIALS_STS_ASSUME_ROLE)
}

override fun toString(): String = this.simpleClassName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import aws.sdk.kotlin.runtime.auth.credentials.internal.sts.assumeRoleWithWebIde
import aws.sdk.kotlin.runtime.auth.credentials.internal.sts.model.PolicyDescriptorType
import aws.sdk.kotlin.runtime.config.AwsSdkSetting
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.AwsBusinessMetric
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.emitBusinessMetric
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.withBusinessMetric
import aws.smithy.kotlin.runtime.auth.awscredentials.*
import aws.smithy.kotlin.runtime.client.SdkClientOption
import aws.smithy.kotlin.runtime.collections.Attributes
Expand Down Expand Up @@ -152,7 +152,7 @@ public class StsWebIdentityCredentialsProvider(
expiration = roleCredentials.expiration,
providerName = PROVIDER_NAME,
accountId = accountId,
).emitBusinessMetric(AwsBusinessMetric.Credentials.CREDENTIALS_STS_ASSUME_ROLE_WEB_ID)
).withBusinessMetric(AwsBusinessMetric.Credentials.CREDENTIALS_STS_ASSUME_ROLE_WEB_ID)
}

override fun toString(): String = this.simpleClassName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package aws.sdk.kotlin.runtime.auth.credentials
import aws.sdk.kotlin.runtime.auth.credentials.internal.credentials
import aws.sdk.kotlin.runtime.config.AwsSdkSetting
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.AwsBusinessMetric
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.emitBusinessMetric
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.withBusinessMetric
import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
import aws.smithy.kotlin.runtime.auth.awscredentials.CredentialsProvider
import aws.smithy.kotlin.runtime.auth.awscredentials.simpleClassName
Expand Down Expand Up @@ -45,7 +45,7 @@ public class SystemPropertyCredentialsProvider(
sessionToken = getProperty(SESSION_TOKEN),
providerName = PROVIDER_NAME,
accountId = getProperty(ACCOUNT_ID),
).emitBusinessMetric(AwsBusinessMetric.Credentials.CREDENTIALS_JVM_SYSTEM_PROPERTIES)
).withBusinessMetric(AwsBusinessMetric.Credentials.CREDENTIALS_JVM_SYSTEM_PROPERTIES)
}

override fun toString(): String = this.simpleClassName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package aws.sdk.kotlin.runtime.auth.credentials
import aws.sdk.kotlin.runtime.auth.credentials.internal.credentials
import aws.sdk.kotlin.runtime.config.AwsSdkSetting
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.AwsBusinessMetric
import aws.sdk.kotlin.runtime.util.withBusinessMetrics
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.withBusinessMetric
import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
import aws.smithy.kotlin.runtime.auth.awscredentials.CredentialsProviderException
import aws.smithy.kotlin.runtime.http.Headers
Expand Down Expand Up @@ -48,7 +48,7 @@ class EcsCredentialsProviderTest {
"test-token",
expectedExpiration,
"EcsContainer",
).withBusinessMetrics(AwsBusinessMetric.Credentials.CREDENTIALS_HTTP)
).withBusinessMetric(AwsBusinessMetric.Credentials.CREDENTIALS_HTTP)

private fun ecsResponse(accountId: String? = null): HttpResponse {
val payload = buildJsonObject {
Expand Down Expand Up @@ -578,7 +578,7 @@ class EcsCredentialsProviderTest {
expectedExpiration,
"EcsContainer",
"12345",
).withBusinessMetrics(AwsBusinessMetric.Credentials.CREDENTIALS_HTTP)
).withBusinessMetric(AwsBusinessMetric.Credentials.CREDENTIALS_HTTP)
assertEquals(expected, actual)
engine.assertRequests()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package aws.sdk.kotlin.runtime.auth.credentials
import aws.sdk.kotlin.runtime.client.AwsClientOption
import aws.sdk.kotlin.runtime.config.AwsSdkSetting
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.AwsBusinessMetric
import aws.sdk.kotlin.runtime.util.withBusinessMetrics
import aws.sdk.kotlin.runtime.http.interceptors.businessmetrics.withBusinessMetric
import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
import aws.smithy.kotlin.runtime.collections.attributesOf
import io.kotest.matchers.string.shouldContain
Expand All @@ -34,7 +34,7 @@ class EnvironmentCredentialsProviderTest {
"def",
"ghi",
providerName = "Environment",
).withBusinessMetrics(AwsBusinessMetric.Credentials.CREDENTIALS_ENV_VARS),
).withBusinessMetric(AwsBusinessMetric.Credentials.CREDENTIALS_ENV_VARS),
)
}

Expand All @@ -51,7 +51,7 @@ class EnvironmentCredentialsProviderTest {
"def",
null,
providerName = "Environment",
).withBusinessMetrics(AwsBusinessMetric.Credentials.CREDENTIALS_ENV_VARS),
).withBusinessMetric(AwsBusinessMetric.Credentials.CREDENTIALS_ENV_VARS),
)
}

Expand Down Expand Up @@ -103,7 +103,7 @@ class EnvironmentCredentialsProviderTest {
"def",
providerName = "Environment",
attributes = attributesOf { AwsClientOption.AccountId to "12345" },
).withBusinessMetrics(AwsBusinessMetric.Credentials.CREDENTIALS_ENV_VARS)
).withBusinessMetric(AwsBusinessMetric.Credentials.CREDENTIALS_ENV_VARS)
assertEquals(expected, actual)
}
}
Loading

0 comments on commit 85b78d7

Please sign in to comment.