Skip to content

Commit b98af94

Browse files
committed
fix(clippy): removed code smells
1 parent 4f1c9a7 commit b98af94

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
uses: actions-rs/cargo@v1
4040
with:
4141
command: clippy
42-
# args: -- -D warnings
42+
args: -- -D warnings
4343
- name: Unit and Integration Tests
4444
uses: actions-rs/cargo@v1
4545
env:

src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub(crate) fn read_config(config_path: PathBuf) -> Config {
2727

2828
let mut config_data: String = String::new();
2929
let mut config_file: File = File::open(config_path)
30-
.expect(format!("Failed to read configuration file: '{path_string}'").as_str());
30+
.unwrap_or_else(|_| panic!("Failed to read configuration file: '{path_string}'"));
3131
config_file
3232
.read_to_string(&mut config_data)
3333
.expect("Failed to read configuration file");

src/vault.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use vaultrs::kv2;
1010

1111
use crate::config::{Config, VaultConfig};
1212

13-
const VAULT_TOKEN: &'static str = "VAULT_TOKEN";
13+
const VAULT_TOKEN: &str = "VAULT_TOKEN";
1414

1515
#[derive(Debug, Deserialize, Serialize)]
1616
pub(crate) struct VaultStructure {
@@ -67,7 +67,7 @@ impl Vault {
6767
self.rt.block_on(kv2::read(
6868
&self.vault_client,
6969
"secret",
70-
&*self.vault_config.path,
70+
&self.vault_config.path,
7171
))
7272
}
7373

@@ -78,7 +78,7 @@ impl Vault {
7878
self.rt.block_on(kv2::set(
7979
&self.vault_client,
8080
"secret",
81-
&*self.vault_config.path,
81+
&self.vault_config.path,
8282
&vault_structure,
8383
))
8484
}

src/workflow.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub(crate) fn rotate_secrets_using_switch_method(
1818
let vault_path = config.vault.clone().path;
1919
let mut secret: VaultStructure = vault
2020
.read_secret()
21-
.expect(format!("Failed to read path '{vault_path}' - did you init Vault?").as_str());
21+
.unwrap_or_else(|_| panic!("Failed to read path '{vault_path}' - did you init Vault?"));
2222

2323
if secret.postgresql_active_user != secret.postgresql_user_1
2424
&& secret.postgresql_active_user != secret.postgresql_user_2
@@ -52,11 +52,19 @@ pub(crate) fn rotate_secrets_using_switch_method(
5252

5353
fn switch_active_user(secret: &mut VaultStructure) {
5454
if secret.postgresql_active_user == secret.postgresql_user_1 {
55-
secret.postgresql_active_user = secret.postgresql_user_2.clone();
56-
secret.postgresql_active_user_password = secret.postgresql_user_2_password.clone()
55+
secret
56+
.postgresql_active_user
57+
.clone_from(&secret.postgresql_user_2);
58+
secret
59+
.postgresql_active_user_password
60+
.clone_from(&secret.postgresql_user_2_password);
5761
} else {
58-
secret.postgresql_active_user = secret.postgresql_user_1.clone();
59-
secret.postgresql_active_user_password = secret.postgresql_user_1_password.clone()
62+
secret
63+
.postgresql_active_user
64+
.clone_from(&secret.postgresql_user_1);
65+
secret
66+
.postgresql_active_user_password
67+
.clone_from(&secret.postgresql_user_1_password);
6068
}
6169

6270
trace!("Switched active and passive user in Vault secret (locally)")
@@ -70,19 +78,19 @@ fn update_passive_user_postgres_password(
7078
let (passive_user, passive_user_password) =
7179
if secret.postgresql_active_user == secret.postgresql_user_1 {
7280
let original_password = secret.postgresql_user_2_password.clone();
73-
secret.postgresql_user_2_password = new_password.clone();
81+
secret.postgresql_user_2_password.clone_from(&new_password);
7482
(secret.postgresql_user_2.clone(), original_password)
7583
} else {
7684
let original_password = secret.postgresql_user_1_password.clone();
77-
secret.postgresql_user_1_password = new_password.clone();
85+
secret.postgresql_user_1_password.clone_from(&new_password);
7886
(secret.postgresql_user_1.clone(), original_password)
7987
};
8088

8189
let mut conn = db.connect_for_user(passive_user.clone(), passive_user_password);
8290
let query = format!("ALTER ROLE {passive_user} WITH PASSWORD '{new_password}'");
8391

8492
conn.execute(query.as_str(), &[])
85-
.expect(format!("Failed to update password of '{passive_user}'").as_str());
93+
.unwrap_or_else(|_| panic!("Failed to update password of '{passive_user}'"));
8694

8795
debug!("Successfully rotated PostgreSQL password of passive user");
8896
}

0 commit comments

Comments
 (0)