From dc67c1b7e8d9fc65a2dcc42762f48b1ae0f87cc5 Mon Sep 17 00:00:00 2001 From: Erika Tharp Date: Mon, 28 Mar 2022 16:00:56 -0700 Subject: [PATCH] chore: Set file permission 600 for both credentials and config files (#85) --- client-sdk-rust | 2 +- src/commands/configure/configure_cli.rs | 10 +--------- src/utils/file.rs | 19 ------------------- tests/momento_default_profile.rs | 19 +++++++++++++++++++ 4 files changed, 21 insertions(+), 29 deletions(-) diff --git a/client-sdk-rust b/client-sdk-rust index 171d5481..b4772bed 160000 --- a/client-sdk-rust +++ b/client-sdk-rust @@ -1 +1 @@ -Subproject commit 171d5481c2c1f274d4f850545976f7e7058d796f +Subproject commit b4772bed67732762b9f971ca6d35544843b7ca9a diff --git a/src/commands/configure/configure_cli.rs b/src/commands/configure/configure_cli.rs index bfcf1e9b..a2d36f38 100644 --- a/src/commands/configure/configure_cli.rs +++ b/src/commands/configure/configure_cli.rs @@ -10,7 +10,7 @@ use crate::{ file::{ create_file, get_config_file_path, get_credentials_file_path, get_momento_dir, open_file, prompt_user_for_input, read_file_contents, set_file_read_write, - set_file_readonly, write_to_file, + write_to_file, }, ini_config::{ add_new_profile_to_config, add_new_profile_to_credentials, update_profile_values, @@ -219,12 +219,6 @@ async fn add_profile( } } } - match file_types { - FileTypes::Credentials(_) => { - set_file_readonly(path).await.unwrap(); - } - FileTypes::Config(_) => {} - } } Ok(()) } @@ -307,8 +301,6 @@ async fn add_new_profile_to_new_file( Ok(_) => {} Err(e) => return Err(e), } - // explicitly revoking that access - set_file_readonly(path).await.unwrap(); Ok(()) } FileTypes::Config(cf) => match add_new_profile_to_config(profile_name, path, cf).await { diff --git a/src/utils/file.rs b/src/utils/file.rs index 80709741..ff8eaa12 100644 --- a/src/utils/file.rs +++ b/src/utils/file.rs @@ -110,25 +110,6 @@ pub async fn ini_write_to_file(ini_map: Ini, path: &str) -> Result<(), CliError> } } -pub async fn set_file_readonly(path: &str) -> Result<(), CliError> { - let mut perms = match fs::metadata(path).await { - Ok(p) => p, - Err(e) => { - return Err(CliError { - msg: format!("failed to get file permissions {}", e), - }) - } - } - .permissions(); - perms.set_mode(0o400); - match fs::set_permissions(path, perms).await { - Ok(_) => Ok(()), - Err(e) => Err(CliError { - msg: format!("failed to set file permissions {}", e), - }), - } -} - pub async fn set_file_read_write(path: &str) -> Result<(), CliError> { let mut perms = match fs::metadata(path).await { Ok(p) => p, diff --git a/tests/momento_default_profile.rs b/tests/momento_default_profile.rs index 2eab3585..657dd662 100644 --- a/tests/momento_default_profile.rs +++ b/tests/momento_default_profile.rs @@ -2,9 +2,28 @@ mod tests { use assert_cmd::Command; + use std::str; async fn momento_cache_create_default_profile() { let test_cache_default = std::env::var("TEST_CACHE_DEFAULT").unwrap(); + let output = Command::cargo_bin("momento") + .unwrap() + .args(&["cache", "list"]) + .output() + .unwrap() + .stdout; + if !output.is_empty() { + let string_output = str::from_utf8(&output).unwrap(); + let v: Vec<&str> = string_output.split('\n').collect(); + for cache in v.iter() { + if !cache.is_empty() { + Command::cargo_bin("momento") + .unwrap() + .args(&["cache", "delete", "--name", cache]) + .unwrap(); + } + } + } let mut cmd = Command::cargo_bin("momento").unwrap(); cmd.args(&["cache", "create", "--name", &test_cache_default]) .assert()