Skip to content

Commit bfbd1ac

Browse files
committed
add constructor
1 parent 5dca4b4 commit bfbd1ac

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +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
65+
public fun <init> (Ljava/lang/String;Ljava/lang/String;Laws/smithy/kotlin/runtime/util/PlatformProvider;Z)V
66+
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Laws/smithy/kotlin/runtime/util/PlatformProvider;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
6767
public fun resolve (Laws/smithy/kotlin/runtime/collections/Attributes;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
6868
}
6969

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,28 @@ import aws.smithy.kotlin.runtime.util.PlatformProvider
1414
/**
1515
* A [BearerTokenProvider] that extracts the bearer token from JVM system properties or environment variables.
1616
*/
17-
public class EnvironmentBearerTokenProvider(
17+
public class EnvironmentBearerTokenProvider private constructor(
1818
private val sysPropKey: String?,
19-
private val envKey: String?,
19+
private val envKey: String,
2020
private val platform: PlatformProvider = PlatformProvider.System,
2121
) : BearerTokenProvider {
22-
@Deprecated("Use constructor with separate system property and environment variable keys")
22+
@Deprecated("This constructor does not support a parameter for a system property key and will be removed in version 1.6.x")
2323
public constructor(
24-
key: String,
24+
envKey: String,
2525
platform: PlatformProvider = PlatformProvider.System,
26-
) : this(null, key, platform)
26+
) : this(null, envKey, platform)
27+
28+
public constructor(
29+
sysPropKey: String,
30+
envKey: String,
31+
platform: PlatformProvider = PlatformProvider.System,
32+
@Suppress("UNUSED_PARAMETER") dummy: Boolean = true,
33+
) : this(sysPropKey as String?, envKey, platform)
2734

2835
override suspend fun resolve(attributes: Attributes): BearerToken {
29-
val bearerToken = sysPropKey?.let { platform.getProperty(it) }
30-
?: envKey?.let { platform.getenv(it) }
31-
?: error("neither system property $sysPropKey nor environment variable $envKey is set")
36+
val bearerToken = sysPropKey?.let(platform::getProperty) ?: platform.getenv(envKey)
37+
if (bearerToken.isNullOrBlank()) throw IllegalStateException("""Missing values for system property "$sysPropKey" and environment variable "$envKey"""")
38+
3239
return object : BearerToken {
3340
override val token: String = bearerToken
3441
override val attributes: Attributes = mutableAttributes().apply {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class EnvironmentBearerTokenProviderTest {
1313
"TEST_SYS_PROPS_TOKEN",
1414
"TEST_ENV_TOKEN",
1515
TestPlatformProvider(
16-
env = mutableMapOf("TEST_ENV_TOKEN" to "test-env-bearer-token"),
16+
env = mapOf("TEST_ENV_TOKEN" to "test-env-bearer-token"),
1717
),
1818
)
1919

@@ -28,7 +28,7 @@ class EnvironmentBearerTokenProviderTest {
2828
"TEST_SYS_PROPS_TOKEN",
2929
"TEST_ENV_TOKEN",
3030
TestPlatformProvider(
31-
props = mutableMapOf("TEST_SYS_PROPS_TOKEN" to "test-sys-props-bearer-token"),
31+
props = mapOf("TEST_SYS_PROPS_TOKEN" to "test-sys-props-bearer-token"),
3232
),
3333
)
3434

@@ -43,8 +43,8 @@ class EnvironmentBearerTokenProviderTest {
4343
"TEST_SYS_PROPS_TOKEN",
4444
"TEST_ENV_TOKEN",
4545
TestPlatformProvider(
46-
props = mutableMapOf("TEST_SYS_PROPS_TOKEN" to "test-sys-props-bearer-token"),
47-
env = mutableMapOf("TEST_ENV_TOKEN" to "test-env-bearer-token"),
46+
props = mapOf("TEST_SYS_PROPS_TOKEN" to "test-sys-props-bearer-token"),
47+
env = mapOf("TEST_ENV_TOKEN" to "test-env-bearer-token"),
4848
),
4949
)
5050

@@ -59,8 +59,8 @@ class EnvironmentBearerTokenProviderTest {
5959
"MISSING_TEST_TOKEN",
6060
"MISSING_TEST_TOKEN",
6161
TestPlatformProvider(
62-
env = mutableMapOf("TEST_TOKEN" to "test-env-bearer-token"),
63-
props = mutableMapOf("TEST_TOKEN" to "test-sys-props-bearer-token"),
62+
env = mapOf("TEST_TOKEN" to "test-env-bearer-token"),
63+
props = mapOf("TEST_TOKEN" to "test-sys-props-bearer-token"),
6464
),
6565
)
6666

0 commit comments

Comments
 (0)