-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added configuration options for sigv4a signing region set
- Loading branch information
Showing
10 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...ime/aws-config/common/src/aws/sdk/kotlin/runtime/config/sigv4a/ResolveSigningRegionSet.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package aws.sdk.kotlin.runtime.config.sigv4a | ||
|
||
import aws.sdk.kotlin.runtime.InternalSdkApi | ||
import aws.sdk.kotlin.runtime.config.AwsSdkSetting | ||
import aws.sdk.kotlin.runtime.config.profile.AwsProfile | ||
import aws.sdk.kotlin.runtime.config.profile.sigv4aSigningRegionSet | ||
import aws.smithy.kotlin.runtime.config.resolve | ||
import aws.smithy.kotlin.runtime.util.LazyAsyncValue | ||
import aws.smithy.kotlin.runtime.util.PlatformProvider | ||
|
||
/** | ||
* Attempts to resolve sigv4aSigningRegionSet from specified sources. | ||
* @return The sigv4aSigningRegionSet if found, null if not | ||
*/ | ||
@InternalSdkApi | ||
public suspend fun resolveSigningRegionSet(platform: PlatformProvider = PlatformProvider.System, profile: LazyAsyncValue<AwsProfile>): List<String>? { | ||
val rawString = AwsSdkSetting.AwsSigv4aSigningRegionSet.resolve(platform) ?: profile.get().sigv4aSigningRegionSet | ||
return rawString?.let { | ||
check(isValidListFormat(it)) { "Config setting sigv4aSigningRegionSet is not formatted as a list of strings" } | ||
it.split(",") | ||
} | ||
} | ||
|
||
/** | ||
* Makes sure that a string can be parsed into a list of non-empty strings | ||
*/ | ||
internal fun isValidListFormat(input: String): Boolean = | ||
Regex("^\\s*([^,\\s]+\\s*,\\s*)*[^,\\s]+\\s*\$").matches(input) |
25 changes: 25 additions & 0 deletions
25
...time/aws-config/common/test/aws/sdk/kotlin/runtime/config/sigv4a/IsValidListFormatTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.config.sigv4a | ||
|
||
import kotlin.test.Test | ||
import kotlin.test.assertFalse | ||
import kotlin.test.assertTrue | ||
|
||
class IsValidListFormatTest { | ||
@Test | ||
fun regexWorks() { | ||
assertTrue(isValidListFormat("apple")) | ||
assertTrue(isValidListFormat("apple,banana,orange")) | ||
assertTrue(isValidListFormat("apple, banana, orange")) | ||
assertTrue(isValidListFormat("apple, banana, orange ")) | ||
|
||
assertFalse(isValidListFormat("")) | ||
assertFalse(isValidListFormat(" ")) | ||
assertFalse(isValidListFormat("apple, , orange")) | ||
assertFalse(isValidListFormat("apple banana")) | ||
assertFalse(isValidListFormat("apple,banana,orange,")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters