Skip to content

Commit

Permalink
Fix bug where cache was being cleared by mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoh committed Jan 3, 2023
1 parent 47d39d6 commit bc24c4c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
31 changes: 30 additions & 1 deletion aws/rust-runtime/aws-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,26 +568,39 @@ mod loader {
use aws_smithy_async::rt::sleep::TokioSleep;
use aws_smithy_client::erase::DynConnector;
use aws_smithy_client::never::NeverConnector;
use aws_types::os_shim_internal::Env;
use aws_types::app_name::AppName;
use aws_types::os_shim_internal::{Env, Fs};
use tracing_test::traced_test;

use crate::from_env;
use crate::profile::profile_file::{ProfileFileKind, ProfileFiles};
use crate::provider_config::ProviderConfig;

#[tokio::test]
#[traced_test]
async fn provider_config_used() {
let env = Env::from_slice(&[
("AWS_MAX_ATTEMPTS", "10"),
("AWS_REGION", "us-west-4"),
("AWS_ACCESS_KEY_ID", "akid"),
("AWS_SECRET_ACCESS_KEY", "secret"),
]);
let fs =
Fs::from_slice(&[("test_config", "[profile custom]\nsdk-ua-app-id = correct")]);
let loader = from_env()
.configure(
ProviderConfig::empty()
.with_sleep(TokioSleep::new())
.with_env(env)
.with_fs(fs)
.with_http_connector(DynConnector::new(NeverConnector::new())),
)
.profile_name("custom")
.profile_files(
ProfileFiles::builder()
.with_file(ProfileFileKind::Config, "test_config")
.build(),
)
.load()
.await;
assert_eq!(loader.retry_config().unwrap().max_attempts(), 10);
Expand All @@ -602,6 +615,22 @@ mod loader {
.access_key_id(),
"akid"
);
assert_eq!(loader.app_name(), Some(&AppName::new("correct").unwrap()));
logs_assert(|lines| {
let num_config_loader_logs = lines
.iter()
.filter(|l| l.contains("provider_config_used"))
.filter(|l| l.contains("config file loaded"))
.count();
match num_config_loader_logs {
0 => Err("no config file logs found!".to_string()),
1 => Ok(()),
more => Err(format!(
"the config file was parsed more than once! (parsed {})",
more
)),
}
});
}
}
}
1 change: 1 addition & 0 deletions aws/rust-runtime/aws-config/src/profile/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub async fn load(
if let Some(profile) = selected_profile_override {
source.profile = profile;
}

Ok(ProfileSet::parse(source)?)
}

Expand Down
5 changes: 5 additions & 0 deletions aws/rust-runtime/aws-config/src/provider_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,16 @@ impl ProviderConfig {
self
}

/// Override profile-file (`~/.aws/config` et al) configuration
pub(crate) fn with_profile_config(
self,
profile_files: Option<ProfileFiles>,
profile_name_override: Option<String>,
) -> Self {
// if there is no override, then don't clear out `parsed_profile`.
if profile_files.is_none() && profile_name_override.is_none() {
return self;
}
ProviderConfig {
// clear out the profile since we need to reparse it
parsed_profile: Default::default(),
Expand Down

0 comments on commit bc24c4c

Please sign in to comment.