-
Notifications
You must be signed in to change notification settings - Fork 55
feat(rt)!: kmp default credentials provider chain #491
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
15 commits
Select commit
Hold shift + click to select a range
416ad72
refactor(rt)!: implement kmp default chain; import test suite
aajtodd 8288a75
fix web identity tests
aajtodd 2d3e1a0
rm crt providers
aajtodd 733851a
cleanup docs
aajtodd 0837b24
style: make field name consistent across providers
aajtodd 703ba11
fix sso expiration
aajtodd 9d9567e
improve debug logging for region resolution
aajtodd 7dcd197
add sso test from working capture
aajtodd 0498bbe
fix http engine lifetime in default cred chain
aajtodd 8b5a867
refactor: relocate provider chains to aws-config
aajtodd 9ada835
fix credential provider chain exception
aajtodd a625ef2
cache region after resolving it
aajtodd a675de6
import sts retry on error test case
aajtodd c4bd3a2
close cached provider source; ensure chain is completely closed befor…
aajtodd 1559c56
fix chain close
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
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
62 changes: 62 additions & 0 deletions
62
...aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/CredentialsProviderChain.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,62 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0. | ||
| */ | ||
|
|
||
| package aws.sdk.kotlin.runtime.auth.credentials | ||
|
|
||
| import aws.smithy.kotlin.runtime.io.Closeable | ||
| import aws.smithy.kotlin.runtime.logging.Logger | ||
|
|
||
| // TODO - support caching the provider that actually resolved credentials such that future calls don't involve going through the full chain | ||
|
|
||
| /** | ||
| * Composite [CredentialsProvider] that delegates to a chain of providers. When asked for credentials [providers] | ||
| * are consulted in the order given until one succeeds. If none of the providers in the chain can provide credentials | ||
| * then this class will throw an exception. The exception will include the providers tried in the message. Each | ||
| * individual exception is available as a suppressed exception. | ||
| * | ||
| * @param providers the list of providers to delegate to | ||
| */ | ||
| public open class CredentialsProviderChain( | ||
| protected vararg val providers: CredentialsProvider | ||
| ) : CredentialsProvider, Closeable { | ||
| private val logger = Logger.getLogger<CredentialsProviderChain>() | ||
|
|
||
| init { | ||
| require(providers.isNotEmpty()) { "at least one provider must be in the chain" } | ||
| } | ||
|
|
||
| override fun toString(): String = | ||
| (listOf(this) + providers).map { it::class.simpleName }.joinToString(" -> ") | ||
|
|
||
| override suspend fun getCredentials(): Credentials { | ||
| val chainException = lazy { CredentialsProviderException("No credentials could be loaded from the chain: $this") } | ||
| for (provider in providers) { | ||
| try { | ||
| return provider.getCredentials() | ||
| } catch (ex: Exception) { | ||
| logger.debug { "unable to load credentials from $provider: ${ex.message}" } | ||
| chainException.value.addSuppressed(ex) | ||
| } | ||
| } | ||
|
|
||
| throw chainException.value | ||
| } | ||
|
|
||
| override fun close() { | ||
| val exceptions = providers.mapNotNull { | ||
| try { | ||
| (it as? Closeable)?.close() | ||
| null | ||
| } catch (ex: Exception) { | ||
| ex | ||
| } | ||
| } | ||
| if (exceptions.isNotEmpty()) { | ||
| val ex = exceptions.first() | ||
| exceptions.drop(1).forEach(ex::addSuppressed) | ||
| throw ex | ||
| } | ||
| } | ||
| } |
14 changes: 0 additions & 14 deletions
14
...-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/CrtBasedCredentialsProvider.kt
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
...ntime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/CrtCredentialUtils.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
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
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
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: Can any code be removed from crt-util now?
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.
Maybe haven't checked. A lot of crt-util supports signing
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.
I don't see anything that should be removed at a glance