Skip to content

Commit

Permalink
chore: Set file permission 600 for both credentials and config files (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
poppoerika authored Mar 28, 2022
1 parent ea5c4a2 commit dc67c1b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 29 deletions.
2 changes: 1 addition & 1 deletion client-sdk-rust
10 changes: 1 addition & 9 deletions src/commands/configure/configure_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -219,12 +219,6 @@ async fn add_profile(
}
}
}
match file_types {
FileTypes::Credentials(_) => {
set_file_readonly(path).await.unwrap();
}
FileTypes::Config(_) => {}
}
}
Ok(())
}
Expand Down Expand Up @@ -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 {
Expand Down
19 changes: 0 additions & 19 deletions src/utils/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 19 additions & 0 deletions tests/momento_default_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit dc67c1b

Please sign in to comment.