Skip to content

Commit afd01ff

Browse files
committed
use new constructor
1 parent 3324220 commit afd01ff

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

runtime/auth/http-auth/api/http-auth.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public abstract interface class aws/smithy/kotlin/runtime/http/auth/CloseableBea
6262
public final class aws/smithy/kotlin/runtime/http/auth/EnvironmentBearerTokenProvider : aws/smithy/kotlin/runtime/http/auth/BearerTokenProvider {
6363
public fun <init> (Ljava/lang/String;Laws/smithy/kotlin/runtime/util/PlatformProvider;)V
6464
public synthetic fun <init> (Ljava/lang/String;Laws/smithy/kotlin/runtime/util/PlatformProvider;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
65+
public fun <init> (Ljava/lang/String;Ljava/lang/String;Laws/smithy/kotlin/runtime/util/PlatformProvider;)V
66+
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Laws/smithy/kotlin/runtime/util/PlatformProvider;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
6567
public fun resolve (Laws/smithy/kotlin/runtime/collections/Attributes;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
6668
}
6769

runtime/auth/http-auth/common/src/aws/smithy/kotlin/runtime/http/auth/EnvironmentBearerTokenProvider.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,20 @@ import aws.smithy.kotlin.runtime.util.PlatformProvider
1515
* A [BearerTokenProvider] that extracts the bearer token from JVM system properties or environment variables.
1616
*/
1717
public class EnvironmentBearerTokenProvider(
18-
private val key: String,
18+
private val sysPropKey: String?,
19+
private val envKey: String?,
1920
private val platform: PlatformProvider = PlatformProvider.System,
2021
) : BearerTokenProvider {
22+
@Deprecated("Use constructor with separate system property and environment variable keys")
23+
public constructor(
24+
key: String,
25+
platform: PlatformProvider = PlatformProvider.System,
26+
) : this(null, key, platform)
27+
2128
override suspend fun resolve(attributes: Attributes): BearerToken {
22-
val bearerToken = platform.getProperty(key) ?: platform.getenv(key)
23-
?: error("$key environment variable is not set")
29+
val bearerToken = sysPropKey?.let { platform.getProperty(it) }
30+
?: envKey?.let { platform.getenv(it) }
31+
?: error("environment variable is not set")
2432
return object : BearerToken {
2533
override val token: String = bearerToken
2634
override val attributes: Attributes = mutableAttributes().apply {

runtime/auth/http-auth/common/test/aws/smithy/kotlin/runtime/http/auth/EnvironmentBearerTokenProviderTest.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ class EnvironmentBearerTokenProviderTest {
1010
@Test
1111
fun testResolveFromEnvVar() = runTest {
1212
val provider = EnvironmentBearerTokenProvider(
13-
"TEST_TOKEN",
13+
"TEST_SYS_PROPS_TOKEN",
14+
"TEST_ENV_TOKEN",
1415
TestPlatformProvider(
15-
env = mutableMapOf("TEST_TOKEN" to "test-env-bearer-token"),
16+
env = mutableMapOf("TEST_ENV_TOKEN" to "test-env-bearer-token"),
1617
),
1718
)
1819

@@ -24,9 +25,10 @@ class EnvironmentBearerTokenProviderTest {
2425
@Test
2526
fun testResolveFromSysProps() = runTest {
2627
val provider = EnvironmentBearerTokenProvider(
27-
"TEST_TOKEN",
28+
"TEST_SYS_PROPS_TOKEN",
29+
"TEST_ENV_TOKEN",
2830
TestPlatformProvider(
29-
props = mutableMapOf("TEST_TOKEN" to "test-sys-props-bearer-token"),
31+
props = mutableMapOf("TEST_SYS_PROPS_TOKEN" to "test-sys-props-bearer-token"),
3032
),
3133
)
3234

@@ -38,6 +40,7 @@ class EnvironmentBearerTokenProviderTest {
3840
@Test
3941
fun testResolveWithMissingToken() = runTest {
4042
val provider = EnvironmentBearerTokenProvider(
43+
"MISSING_TEST_TOKEN",
4144
"MISSING_TEST_TOKEN",
4245
TestPlatformProvider(
4346
env = mutableMapOf("TEST_TOKEN" to "test-env-bearer-token"),
@@ -48,6 +51,6 @@ class EnvironmentBearerTokenProviderTest {
4851
val exception = assertFailsWith<IllegalStateException> {
4952
provider.resolve()
5053
}
51-
assertEquals("MISSING_TEST_TOKEN environment variable is not set", exception.message)
54+
assertEquals("environment variable is not set", exception.message)
5255
}
5356
}

0 commit comments

Comments
 (0)