diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 529fc3e..bfc956e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -39,7 +39,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: clippy - # args: -- -D warnings + args: -- -D warnings - name: Unit and Integration Tests uses: actions-rs/cargo@v1 env: diff --git a/src/config.rs b/src/config.rs index fed9f85..b7a3f50 100644 --- a/src/config.rs +++ b/src/config.rs @@ -27,7 +27,7 @@ pub(crate) fn read_config(config_path: PathBuf) -> Config { let mut config_data: String = String::new(); let mut config_file: File = File::open(config_path) - .expect(format!("Failed to read configuration file: '{path_string}'").as_str()); + .unwrap_or_else(|_| panic!("Failed to read configuration file: '{path_string}'")); config_file .read_to_string(&mut config_data) .expect("Failed to read configuration file"); diff --git a/src/vault.rs b/src/vault.rs index 7926224..3573c1c 100644 --- a/src/vault.rs +++ b/src/vault.rs @@ -10,7 +10,7 @@ use vaultrs::kv2; use crate::config::{Config, VaultConfig}; -const VAULT_TOKEN: &'static str = "VAULT_TOKEN"; +const VAULT_TOKEN: &str = "VAULT_TOKEN"; #[derive(Debug, Deserialize, Serialize)] pub(crate) struct VaultStructure { @@ -67,7 +67,7 @@ impl Vault { self.rt.block_on(kv2::read( &self.vault_client, "secret", - &*self.vault_config.path, + &self.vault_config.path, )) } @@ -78,7 +78,7 @@ impl Vault { self.rt.block_on(kv2::set( &self.vault_client, "secret", - &*self.vault_config.path, + &self.vault_config.path, &vault_structure, )) } diff --git a/src/workflow.rs b/src/workflow.rs index 7a6e431..7135f4d 100644 --- a/src/workflow.rs +++ b/src/workflow.rs @@ -18,7 +18,7 @@ pub(crate) fn rotate_secrets_using_switch_method( let vault_path = config.vault.clone().path; let mut secret: VaultStructure = vault .read_secret() - .expect(format!("Failed to read path '{vault_path}' - did you init Vault?").as_str()); + .unwrap_or_else(|_| panic!("Failed to read path '{vault_path}' - did you init Vault?")); if secret.postgresql_active_user != secret.postgresql_user_1 && secret.postgresql_active_user != secret.postgresql_user_2 @@ -52,11 +52,19 @@ pub(crate) fn rotate_secrets_using_switch_method( fn switch_active_user(secret: &mut VaultStructure) { if secret.postgresql_active_user == secret.postgresql_user_1 { - secret.postgresql_active_user = secret.postgresql_user_2.clone(); - secret.postgresql_active_user_password = secret.postgresql_user_2_password.clone() + secret + .postgresql_active_user + .clone_from(&secret.postgresql_user_2); + secret + .postgresql_active_user_password + .clone_from(&secret.postgresql_user_2_password); } else { - secret.postgresql_active_user = secret.postgresql_user_1.clone(); - secret.postgresql_active_user_password = secret.postgresql_user_1_password.clone() + secret + .postgresql_active_user + .clone_from(&secret.postgresql_user_1); + secret + .postgresql_active_user_password + .clone_from(&secret.postgresql_user_1_password); } trace!("Switched active and passive user in Vault secret (locally)") @@ -70,11 +78,11 @@ fn update_passive_user_postgres_password( let (passive_user, passive_user_password) = if secret.postgresql_active_user == secret.postgresql_user_1 { let original_password = secret.postgresql_user_2_password.clone(); - secret.postgresql_user_2_password = new_password.clone(); + secret.postgresql_user_2_password.clone_from(&new_password); (secret.postgresql_user_2.clone(), original_password) } else { let original_password = secret.postgresql_user_1_password.clone(); - secret.postgresql_user_1_password = new_password.clone(); + secret.postgresql_user_1_password.clone_from(&new_password); (secret.postgresql_user_1.clone(), original_password) }; @@ -82,7 +90,7 @@ fn update_passive_user_postgres_password( let query = format!("ALTER ROLE {passive_user} WITH PASSWORD '{new_password}'"); conn.execute(query.as_str(), &[]) - .expect(format!("Failed to update password of '{passive_user}'").as_str()); + .unwrap_or_else(|_| panic!("Failed to update password of '{passive_user}'")); debug!("Successfully rotated PostgreSQL password of passive user"); }