Skip to content

Commit

Permalink
Make possible to disable version check
Browse files Browse the repository at this point in the history
  • Loading branch information
sam701 committed Oct 7, 2021
1 parent 41acdff commit 53df589
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
13 changes: 7 additions & 6 deletions src/assume/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ fn run_raw(profile: &str, config: &Config) -> Result<(), String> {
let mut assumer = RoleAssumer::new(config.region.clone(), &mut cred_file, config);
assumer.assume(profile)?;
print_profile(profile, config);
if Utc::now() - state.last_version_check_time
> Duration::days(config.check_new_version_interval_days as i64)
{
check_newer_version();
state.last_version_check_time = Utc::now();
state.save()?;

if let Some(check_every_days) = config.check_new_version_interval_days {
if Utc::now() - state.last_version_check_time > Duration::days(check_every_days as i64) {
check_newer_version();
state.last_version_check_time = Utc::now();
state.save()?;
}
}

main_credentials::rotate_if_needed(config, &mut cred_file, &mut state)?;
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct Config {
mfa_serial_number: String,
mfa_command: Option<String>,
pub profiles: LinkedHashMap<ProfileName, Profile>,
pub check_new_version_interval_days: u32,
pub check_new_version_interval_days: Option<u32>,
pub modify_shell_prompt: bool,
pub region: Region,
session_name: String,
Expand Down Expand Up @@ -108,7 +108,7 @@ impl Config {
)
})
.collect(),
check_new_version_interval_days: rc.check_new_version_interval_days.unwrap_or(7),
check_new_version_interval_days: rc.check_new_version_interval_days,
modify_shell_prompt: rc.modify_shell_prompt.unwrap_or(true),
region,
session_name: rc.session_name.unwrap_or_else(|| "awscredx".to_owned()),
Expand Down
3 changes: 2 additions & 1 deletion src/init/templates/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ mfa_serial_number = "arn:aws:iam::MAIN_ACCOUNT_ID:mfa/USERNAME"
# mfa_command = "ykman oath accounts code | awk '/SOME_PATTERN/ {print $2}'"

# How often to check for new version.
check_new_version_interval_days = 7
# Comment out to disable.
check_new_version_interval_days = 30

# This will prepend the assumed profile and the expiration time to your shell prompt.
# You can disable this feature and directly use environment variable `AWS_PROFILE` with
Expand Down

0 comments on commit 53df589

Please sign in to comment.