-
Notifications
You must be signed in to change notification settings - Fork 55
feat: add JVM property region provider #295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1d71ff3
1807dfe
fa3962c
5e21e5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0. | ||
| */ | ||
|
|
||
| package aws.sdk.kotlin.runtime | ||
|
|
||
| // NOTE: The JVM property names MUST match the ones defined in the Java SDK for any setting added. | ||
| // see: https://github.com/aws/aws-sdk-java-v2/blob/master/core/sdk-core/src/main/java/software/amazon/awssdk/core/SdkSystemSetting.java | ||
|
|
||
| /** | ||
| * Settings to configure SDK runtime behavior | ||
| */ | ||
| @InternalSdkApi | ||
| public sealed class AwsSdkSetting<T> ( | ||
| /** | ||
| * The name of the corresponding environment variable that configures the setting | ||
| */ | ||
| public val environmentVariable: String, | ||
|
|
||
| /** | ||
| * The name of the corresponding JVM system property that configures the setting | ||
| */ | ||
| public val jvmProperty: String, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment Would we ever have a case for a setting available via environment but not the jvm?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought of that and wasn't sure. I slept on it and think the answer is probably no. If there is an environment variable there ought to be a corresponding JVM property. I don't see any cases in the Java SDK where this isn't true FWIW. |
||
|
|
||
| /** | ||
| * The default value (if one exists) | ||
| */ | ||
| public val defaultValue: T? = null | ||
| ) { | ||
| /** | ||
| * Configure the AWS access key ID. | ||
| * | ||
| * This value will not be ignored if the [AwsSecretAccessKey] is not specified. | ||
| */ | ||
| public object AwsAccessKeyId : AwsSdkSetting<String>("AWS_ACCESS_KEY_ID", "aws.accessKeyId") | ||
|
|
||
| /** | ||
| * Configure the AWS secret access key. | ||
| * | ||
| * This value will not be ignored if the [AwsAccessKeyId] is not specified. | ||
| */ | ||
| public object AwsSecretAccessKey : AwsSdkSetting<String>("AWS_SECRET_ACCESS_KEY", "aws.secretAccessKey") | ||
|
|
||
| /** | ||
| * Configure the AWS session token. | ||
| */ | ||
| public object AwsSessionToken : AwsSdkSetting<String>("AWS_SESSION_TOKEN", "aws.sessionToken") | ||
|
|
||
| /** | ||
| * Configure the default region. | ||
| */ | ||
| public object AwsRegion : AwsSdkSetting<String>("AWS_REGION", "aws.region") | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0. | ||
| */ | ||
|
|
||
| package aws.sdk.kotlin.runtime.regions.providers | ||
|
|
||
| public actual class DefaultAwsRegionProviderChain public actual constructor() : | ||
| AwsRegionProvider, | ||
| AwsRegionProviderChain( | ||
| JvmSystemPropRegionProvider(), | ||
| EnvironmentRegionProvider() | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0. | ||
| */ | ||
|
|
||
| package aws.sdk.kotlin.runtime.regions.providers | ||
|
|
||
| import aws.sdk.kotlin.runtime.AwsSdkSetting | ||
|
|
||
| /** | ||
| * [AwsRegionProvider] that checks `aws.region` system property | ||
| */ | ||
| internal class JvmSystemPropRegionProvider : AwsRegionProvider { | ||
| override suspend fun getRegion(): String? = System.getProperty(AwsSdkSetting.AwsRegion.jvmProperty, null) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0. | ||
| */ | ||
|
|
||
| package aws.sdk.kotlin.runtime.regions.providers | ||
|
|
||
| import aws.sdk.kotlin.runtime.AwsSdkSetting | ||
| import aws.sdk.kotlin.runtime.testing.runSuspendTest | ||
| import org.junit.jupiter.api.Test | ||
| import kotlin.test.assertEquals | ||
| import kotlin.test.assertNull | ||
|
|
||
| class JvmSystemPropRegionProviderTest { | ||
|
|
||
| @Test | ||
| fun testGetRegion() = runSuspendTest { | ||
| val provider = JvmSystemPropRegionProvider() | ||
|
|
||
| assertNull(provider.getRegion()) | ||
|
|
||
| System.setProperty(AwsSdkSetting.AwsRegion.jvmProperty, "us-east-1") | ||
| assertEquals("us-east-1", provider.getRegion()) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much cleaner!