-
Notifications
You must be signed in to change notification settings - Fork 55
refactor!: require a resolved configuration #351
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5a972e6
refactor!: remove AuthConfig and RegionConfig; replace with AwsClient…
aajtodd 3c84ded
update configuration properties to use new property type; refactor re…
aajtodd 22e12d9
fix aws service config integration properties
aajtodd 7746558
refactor: override AWS client construction
aajtodd 80cfa94
refactor how region is resolved and fill in load from environment
aajtodd 9dfada5
Merge remote-tracking branch 'origin/main' into feat-config-loading
aajtodd c9e2979
change exception type
aajtodd 369fe8c
render service client config with explicit constructor
aajtodd 1736a9a
add future action item
aajtodd 016d566
update presign config generation to use new property type capabilities
aajtodd a831ab0
loadFromEnvironment -> fromEnvironment; use additionalImports
aajtodd 1e8a95a
Merge remote-tracking branch 'origin/main' into feat-config-loading
aajtodd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/AwsClientConfigLoader.kt
This file contains hidden or 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,60 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0. | ||
| */ | ||
|
|
||
| package aws.sdk.kotlin.runtime.config | ||
|
|
||
| import aws.sdk.kotlin.runtime.auth.credentials.CredentialsProvider | ||
| import aws.sdk.kotlin.runtime.auth.credentials.DefaultChainCredentialsProvider | ||
| import aws.sdk.kotlin.runtime.client.AwsClientConfig | ||
| import aws.sdk.kotlin.runtime.region.resolveRegion | ||
| import aws.smithy.kotlin.runtime.util.Platform | ||
| import aws.smithy.kotlin.runtime.util.PlatformProvider | ||
|
|
||
| /** | ||
| * Options that control how an [aws.sdk.kotlin.runtime.client.AwsClientConfig] is resolved | ||
| */ | ||
| public class AwsClientConfigLoadOptions { | ||
| // TODO - see Go SDK for an idea of possible knobs | ||
| // https://github.com/aws/aws-sdk-go-v2/blob/973e5f5e9477e0690bcb4be3145bb72e956651cc/config/load_options.go#L22 | ||
| // Most of these will not be needed if you are using a corresponding environment variable or system property but there should be an explicit | ||
| // option to control behavior. | ||
|
|
||
| /** | ||
| * The region to make requests to. When set, region will not attempt to be resolved from other sources | ||
| */ | ||
| public var region: String? = null | ||
|
|
||
| /** | ||
| * The [CredentialsProvider] to use when sourcing [aws.sdk.kotlin.runtime.auth.credentials.Credentials]. | ||
| */ | ||
| public var credentialsProvider: CredentialsProvider? = null | ||
|
|
||
| // FIXME - expose profile name override and thread through region/cred provider chains | ||
| } | ||
|
|
||
| /** | ||
| * Load the AWS client configuration from the environment. | ||
| */ | ||
| public suspend fun AwsClientConfig.Companion.fromEnvironment( | ||
| block: AwsClientConfigLoadOptions.() -> Unit = {} | ||
| ): AwsClientConfig = loadAwsClientConfig(Platform, block) | ||
|
|
||
| internal suspend fun loadAwsClientConfig( | ||
| platformProvider: PlatformProvider, | ||
| block: AwsClientConfigLoadOptions.() -> Unit | ||
| ): AwsClientConfig { | ||
| val opts = AwsClientConfigLoadOptions().apply(block) | ||
|
|
||
| val region = opts.region ?: resolveRegion(platformProvider) | ||
|
|
||
| val credentialsProvider = opts.credentialsProvider ?: DefaultChainCredentialsProvider() | ||
|
|
||
| return ResolvedAwsConfig(region, credentialsProvider) | ||
| } | ||
|
|
||
| private data class ResolvedAwsConfig( | ||
| override val region: String, | ||
| override val credentialsProvider: CredentialsProvider | ||
| ) : AwsClientConfig |
This file contains hidden or 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 hidden or 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 hidden or 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
28 changes: 28 additions & 0 deletions
28
...runtime/aws-config/common/test/aws/sdk/kotlin/runtime/config/AwsClientConfigLoaderTest.kt
This file contains hidden or 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,28 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0. | ||
| */ | ||
|
|
||
| package aws.sdk.kotlin.runtime.config | ||
|
|
||
| import aws.sdk.kotlin.runtime.auth.credentials.StaticCredentialsProvider | ||
| import aws.sdk.kotlin.runtime.testing.TestPlatformProvider | ||
| import aws.sdk.kotlin.runtime.testing.runSuspendTest | ||
| import kotlin.test.Test | ||
| import kotlin.test.assertEquals | ||
|
|
||
| class AwsClientConfigLoaderTest { | ||
| @Test | ||
| fun testExplicit(): Unit = runSuspendTest { | ||
| val provider = TestPlatformProvider() | ||
| val actual = loadAwsClientConfig(provider) { | ||
| region = "us-east-2" | ||
| credentialsProvider = StaticCredentialsProvider { | ||
| accessKeyId = "AKID" | ||
| secretAccessKey = "secret" | ||
| } | ||
| } | ||
| assertEquals("us-east-2", actual.region) | ||
| assertEquals("AKID", actual.credentialsProvider.getCredentials().accessKeyId) | ||
| } | ||
| } |
31 changes: 0 additions & 31 deletions
31
aws-runtime/aws-config/common/test/aws/sdk/kotlin/runtime/region/ResolveRegionTest.kt
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
19 changes: 0 additions & 19 deletions
19
aws-runtime/aws-core/common/src/aws/sdk/kotlin/runtime/client/AwsAdvancedClientOption.kt
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
aws-runtime/aws-types/common/src/aws/sdk/kotlin/runtime/auth/AuthConfig.kt
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
aws-runtime/aws-types/common/src/aws/sdk/kotlin/runtime/client/AwsClientConfig.kt
This file contains hidden or 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.client | ||
|
|
||
| import aws.sdk.kotlin.runtime.auth.credentials.CredentialsProvider | ||
|
|
||
| /** | ||
| * Shared AWS service client configuration that all AWS service clients implement as part of their configuration state. | ||
| */ | ||
| public interface AwsClientConfig { | ||
| /** | ||
| * The AWS region to make requests to | ||
| */ | ||
| public val region: String | ||
|
|
||
| /** | ||
| * The [CredentialsProvider] that will be called to resolve credentials before making AWS service calls | ||
| */ | ||
| public val credentialsProvider: CredentialsProvider | ||
|
|
||
| public companion object {} | ||
| } | ||
17 changes: 0 additions & 17 deletions
17
aws-runtime/aws-types/common/src/aws/sdk/kotlin/runtime/region/RegionConfig.kt
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Question: Why does
AwsClientConfigneed a public empty companion object?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.
It's extended in aws-config