@@ -18,7 +18,7 @@ pub(crate) fn rotate_secrets_using_switch_method(
18
18
let vault_path = config. vault . clone ( ) . path ;
19
19
let mut secret: VaultStructure = vault
20
20
. 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?" ) ) ;
22
22
23
23
if secret. postgresql_active_user != secret. postgresql_user_1
24
24
&& secret. postgresql_active_user != secret. postgresql_user_2
@@ -52,11 +52,19 @@ pub(crate) fn rotate_secrets_using_switch_method(
52
52
53
53
fn switch_active_user ( secret : & mut VaultStructure ) {
54
54
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 ) ;
57
61
} 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 ) ;
60
68
}
61
69
62
70
trace ! ( "Switched active and passive user in Vault secret (locally)" )
@@ -70,19 +78,19 @@ fn update_passive_user_postgres_password(
70
78
let ( passive_user, passive_user_password) =
71
79
if secret. postgresql_active_user == secret. postgresql_user_1 {
72
80
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 ) ;
74
82
( secret. postgresql_user_2 . clone ( ) , original_password)
75
83
} else {
76
84
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 ) ;
78
86
( secret. postgresql_user_1 . clone ( ) , original_password)
79
87
} ;
80
88
81
89
let mut conn = db. connect_for_user ( passive_user. clone ( ) , passive_user_password) ;
82
90
let query = format ! ( "ALTER ROLE {passive_user} WITH PASSWORD '{new_password}'" ) ;
83
91
84
92
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}'" ) ) ;
86
94
87
95
debug ! ( "Successfully rotated PostgreSQL password of passive user" ) ;
88
96
}
0 commit comments