-
Notifications
You must be signed in to change notification settings - Fork 189
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
rfc43: fix identity cache partition #3566
Merged
Merged
Changes from all commits
Commits
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "aws-credential-types" | ||
version = "1.1.8" | ||
version = "1.2.0" | ||
authors = ["AWS Rust SDK Team <[email protected]>"] | ||
description = "Types for AWS SDK credentials." | ||
edition = "2021" | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
use std::sync::atomic::{AtomicI32, Ordering}; | ||
use std::sync::Arc; | ||
|
||
use aws_config::{identity::IdentityCache, BehaviorVersion, Region}; | ||
use aws_credential_types::{ | ||
provider::{future::ProvideCredentials as ProvideCredentialsFuture, ProvideCredentials}, | ||
Credentials, | ||
}; | ||
use aws_sdk_s3::Client; | ||
use aws_smithy_runtime::client::http::test_util::infallible_client_fn; | ||
|
||
// NOTE: These tests are _not_ S3 specific and would apply to any AWS SDK but due to the need to consume `aws-config` | ||
// (which depends on relocated runtime crates) we can't make this an `awsSdkIntegrationTest(..)`. | ||
|
||
#[tokio::test] | ||
async fn test_identity_cache_reused_by_default() { | ||
let http_client = | ||
infallible_client_fn(|_req| http::Response::builder().status(200).body("OK!").unwrap()); | ||
|
||
let provider = TestCredProvider::new(); | ||
let cache = IdentityCache::lazy().build(); | ||
let config = aws_config::defaults(BehaviorVersion::latest()) | ||
.http_client(http_client) | ||
.credentials_provider(provider.clone()) | ||
// TODO(rfc-43) - remove adding a cache when this is the new default | ||
.identity_cache(cache) | ||
.region(Region::new("us-west-2")) | ||
.load() | ||
.await; | ||
|
||
let c1 = Client::new(&config); | ||
let _ = c1.list_buckets().send().await; | ||
assert_eq!(1, provider.invoke_count.load(Ordering::SeqCst)); | ||
|
||
let c2 = Client::new(&config); | ||
let _ = c2.list_buckets().send().await; | ||
assert_eq!(1, provider.invoke_count.load(Ordering::SeqCst)); | ||
} | ||
|
||
// TODO(rfc-43) - add no_identity_cache() to ConfigLoader and re-enable test | ||
// #[tokio::test] | ||
// async fn test_identity_cache_explicit_unset() { | ||
// let http_client = | ||
// infallible_client_fn(|_req| http::Response::builder().status(200).body("OK!").unwrap()); | ||
// | ||
// let provider = TestCredProvider::new(); | ||
// | ||
// let config = aws_config::defaults(BehaviorVersion::latest()) | ||
// .no_identity_cache() | ||
// .http_client(http_client) | ||
// .credentials_provider(provider.clone()) | ||
// .region(Region::new("us-west-2")) | ||
// .load() | ||
// .await; | ||
// | ||
// let c1 = Client::new(&config); | ||
// let _ = c1.list_buckets().send().await; | ||
// assert_eq!(1, provider.invoke_count.load(Ordering::SeqCst)); | ||
// | ||
// let c2 = Client::new(&config); | ||
// let _ = c2.list_buckets().send().await; | ||
// assert_eq!(2, provider.invoke_count.load(Ordering::SeqCst)); | ||
// } | ||
|
||
#[tokio::test] | ||
async fn test_identity_cache_ga_behavior_version() { | ||
let http_client = | ||
infallible_client_fn(|_req| http::Response::builder().status(200).body("OK!").unwrap()); | ||
|
||
let provider = TestCredProvider::new(); | ||
|
||
// no cache is defined in this behavior version by default so each client should get their own | ||
let config = aws_config::defaults(BehaviorVersion::v2023_11_09()) | ||
.http_client(http_client) | ||
.credentials_provider(provider.clone()) | ||
.region(Region::new("us-west-2")) | ||
.load() | ||
.await; | ||
|
||
let c1 = Client::new(&config); | ||
let _ = c1.list_buckets().send().await; | ||
assert_eq!(1, provider.invoke_count.load(Ordering::SeqCst)); | ||
|
||
let c2 = Client::new(&config); | ||
let _ = c2.list_buckets().send().await; | ||
assert_eq!(2, provider.invoke_count.load(Ordering::SeqCst)); | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
struct TestCredProvider { | ||
invoke_count: Arc<AtomicI32>, | ||
creds: Credentials, | ||
} | ||
|
||
impl TestCredProvider { | ||
fn new() -> Self { | ||
TestCredProvider { | ||
invoke_count: Arc::new(AtomicI32::default()), | ||
creds: Credentials::for_tests(), | ||
} | ||
} | ||
} | ||
|
||
impl ProvideCredentials for TestCredProvider { | ||
fn provide_credentials<'a>( | ||
&'a self, | ||
) -> aws_credential_types::provider::future::ProvideCredentials<'a> | ||
where | ||
Self: 'a, | ||
{ | ||
self.invoke_count.fetch_add(1, Ordering::SeqCst); | ||
ProvideCredentialsFuture::ready(Ok(self.creds.clone())) | ||
} | ||
} |
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
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.
If an integration test is service agnostic, it's a good practice we write it in Kotlin. Since the test uses
credentials_provider
, you can useawsSdkIntegrationTest
(example).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.
Does this end up on every generated client? If so is that what we want here?
It does use
credentials_provider
but with fake/test credentials. It really is just testing the cache behavior and interaction betweenSdkConfig
and generated client config. It doesn't make a real request.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 think it does.
awsSdkIntegrationTest
is a test helper that tests codegen itself but does not run against generated AWS SDKs.That does sound like service-agnostic, and that's what
awsSdkIntegrationTest
is forThere 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.
Just throwing one last thing on the table before leaving tests in
integration-tests/s3
, can we directly constructSdkConfig
in tests with necessary fields without going throughaws_config::defaults
? I'm assuming the tests won't need default configs in order to verify what they are supposed to test? If we don't useaws-config
, then we may be able to avoid the problem we discussed offline.But I am ok with what we have, and wanted to double-check.
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.
We can which would allow us to test some of this but not how different behavior versions behave in loading (which still require a subsequent PR to fully implement) if I understand correctly how it's all wired.