Skip to content

Commit e6481c0

Browse files
authored
Merge pull request #128 from wa5i/clippy
fix: make clippy happy
2 parents caeeca1 + 31409ef commit e6481c0

30 files changed

+89
-87
lines changed

src/api/client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl Client {
157157
}
158158

159159
pub fn request(&self, method: &str, path: &str, data: Option<Map<String, Value>>) -> Result<HttpResponse, RvError> {
160-
let url = if path.starts_with("/") {
160+
let url = if path.starts_with('/') {
161161
format!("{}{}", self.address, path)
162162
} else {
163163
format!("{}/{}", self.address, path)

src/cli/command/server.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl Server {
8888

8989
let mut work_dir = WORK_DIR_PATH_DEFAULT.to_string();
9090
if !config.work_dir.is_empty() {
91-
work_dir = config.work_dir.clone();
91+
work_dir.clone_from(&config.work_dir);
9292
}
9393

9494
if !Path::new(work_dir.as_str()).exists() {
@@ -101,18 +101,18 @@ impl Server {
101101
// start daemon
102102
let log_path = format!("{}/rusty_vault.log", work_dir);
103103
let mut pid_path = config.pid_file.clone();
104-
if !config.pid_file.starts_with("/") {
104+
if !config.pid_file.starts_with('/') {
105105
pid_path = work_dir.clone() + pid_path.as_str();
106106
}
107107

108108
let mut user = "onbody".to_owned();
109109
if !config.daemon_user.is_empty() {
110-
user = config.daemon_user.clone();
110+
user.clone_from(&config.daemon_user);
111111
}
112112

113113
let mut group = "onbody".to_owned();
114114
if !config.daemon_group.is_empty() {
115-
group = config.daemon_group.clone();
115+
group.clone_from(&config.daemon_group);
116116
}
117117

118118
let log_file = std::fs::OpenOptions::new()

src/cli/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ fn load_config_file(path: &str) -> Result<Config, RvError> {
312312
}
313313

314314
fn set_config_type_field(config: &mut Config) -> Result<(), RvError> {
315-
config.storage.iter_mut().for_each(|(key, value)| value.stype = key.clone());
316-
config.listener.iter_mut().for_each(|(key, value)| value.ltype = key.clone());
315+
config.storage.iter_mut().for_each(|(key, value)| value.stype.clone_from(key));
316+
config.listener.iter_mut().for_each(|(key, value)| value.ltype.clone_from(key));
317317
Ok(())
318318
}
319319

src/http/logical.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ async fn logical_request_handler(
5252
let mut req_conn = ReqConnection::default();
5353
req_conn.peer_addr = conn.peer.to_string();
5454
if conn.tls.is_some() {
55-
req_conn.peer_tls_cert = conn.tls.as_ref().unwrap().client_cert_chain.clone();
55+
req_conn.peer_tls_cert.clone_from(&conn.tls.as_ref().unwrap().client_cert_chain);
5656
}
5757

5858
let mut r = request_auth(&req);
59-
r.path = path.into_inner().clone();
59+
r.path.clone_from(&path.into_inner());
6060
r.connection = Some(req_conn);
6161

6262
match method {
@@ -103,7 +103,7 @@ fn response_logical(resp: &Response, path: &str) -> Result<HttpResponse, RvError
103103
let mut no_content = true;
104104

105105
if let Some(ref secret) = &resp.secret {
106-
logical_resp.lease_id = secret.lease_id.clone();
106+
logical_resp.lease_id.clone_from(&secret.lease_id);
107107
logical_resp.renewable = secret.lease.renewable;
108108
logical_resp.lease_duration = secret.lease.ttl.as_secs();
109109
no_content = false;

src/logical/request.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,15 @@ impl Request {
174174
if self.data.is_some() {
175175
if let Some(secret_str) = self.data.as_mut().unwrap().get_mut(key) {
176176
if let Value::String(ref mut s) = *secret_str {
177-
*s = "".to_owned();
177+
"".clone_into(s);
178178
}
179179
}
180180
}
181181

182182
if self.body.is_some() {
183183
if let Some(secret_str) = self.body.as_mut().unwrap().get_mut(key) {
184184
if let Value::String(ref mut s) = *secret_str {
185-
*s = "".to_owned();
185+
"".clone_into(s);
186186
}
187187
}
188188
}

src/logical/secret.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl Secret {
4040
let mut secret = SecretData { lease, lease_id: String::new(), internal_data: Map::new() };
4141

4242
if internal.is_some() {
43-
secret.internal_data = internal.as_ref().unwrap().clone();
43+
secret.internal_data.clone_from(internal.as_ref().unwrap());
4444
}
4545

4646
secret.internal_data.insert("secret_type".to_owned(), Value::String(self.secret_type.clone()));

src/modules/auth/expiration.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl ExpirationManager {
227227

228228
le.data = resp.data.clone().unwrap_or(Map::new());
229229
le.expire_time = resp.secret.as_ref().unwrap().expiration_time();
230-
le.secret = resp.secret.clone();
230+
le.secret.clone_from(&resp.secret);
231231

232232
self.persist_lease_entry(&le)?;
233233
self.register_lease_entry(Arc::new(le))?;
@@ -278,7 +278,7 @@ impl ExpirationManager {
278278
auth.explicit_max_ttl,
279279
le.issue_time,
280280
)?;
281-
auth.client_token = te.id.clone();
281+
auth.client_token.clone_from(&te.id);
282282

283283
le.expire_time = auth.expiration_time();
284284
le.auth = Some(auth.clone());
@@ -305,7 +305,7 @@ impl ExpirationManager {
305305

306306
let lease_id = format!("{}/{}", req.path, generate_uuid());
307307

308-
secret.lease_id = lease_id.clone();
308+
secret.lease_id.clone_from(&lease_id);
309309

310310
let le = LeaseEntry {
311311
lease_id: lease_id.clone(),
@@ -401,7 +401,7 @@ impl ExpirationManager {
401401
/// Revokes all lease entries with a given prefix.
402402
pub fn revoke_prefix(&self, prefix: &str) -> Result<(), RvError> {
403403
let mut prefix = prefix.to_string();
404-
if !prefix.ends_with("/") {
404+
if !prefix.ends_with('/') {
405405
prefix += "/";
406406
}
407407

@@ -655,7 +655,7 @@ impl ExpirationManager {
655655
if le.auth.is_some() {
656656
let mut au = le.auth.as_ref().unwrap().clone();
657657
if le.path.starts_with("auth/token/") {
658-
au.client_token = le.client_token.clone();
658+
au.client_token.clone_from(&le.client_token);
659659
} else {
660660
au.client_token = "".to_string();
661661
}

src/modules/auth/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl AuthModule {
8787
let mut auth_table = router_store.mounts.entries.write()?;
8888
let mut entry = me.clone();
8989

90-
if !entry.path.ends_with("/") {
90+
if !entry.path.ends_with('/') {
9191
entry.path += "/";
9292
}
9393

@@ -142,7 +142,7 @@ impl AuthModule {
142142
let router_store = self.router_store.read()?;
143143

144144
let mut path = path.to_string();
145-
if !path.ends_with("/") {
145+
if !path.ends_with('/') {
146146
path += "/";
147147
}
148148

@@ -172,11 +172,11 @@ impl AuthModule {
172172
let mut src = src.to_string();
173173
let mut dst = dst.to_string();
174174

175-
if !src.ends_with("/") {
175+
if !src.ends_with('/') {
176176
src += "/";
177177
}
178178

179-
if !dst.ends_with("/") {
179+
if !dst.ends_with('/') {
180180
dst += "/";
181181
}
182182

src/modules/auth/token_store.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -525,19 +525,19 @@ impl TokenStore {
525525
if !is_root {
526526
return Err(RvError::ErrRequestInvalid);
527527
}
528-
te.id = data.id.clone();
528+
te.id.clone_from(&data.id);
529529
}
530530

531531
if data.policies.is_empty() {
532-
data.policies = parent.policies.clone();
532+
data.policies.clone_from(&parent.policies);
533533
sanitize_policies(&mut data.policies, false);
534534
}
535535

536536
if !is_root && !is_str_subset(&data.policies, &parent.policies) {
537537
return Err(RvError::ErrRequestInvalid);
538538
}
539539

540-
te.policies = data.policies.clone();
540+
te.policies.clone_from(&data.policies);
541541

542542
for policy in te.policies.iter() {
543543
if NON_ASSIGNABLE_POLICIES.contains(&policy.as_str()) {
@@ -657,7 +657,7 @@ impl TokenStore {
657657
log::debug!("lookup token");
658658
let mut id = req.get_data_as_str("token")?;
659659
if id.is_empty() {
660-
id = req.client_token.clone();
660+
id.clone_from(&req.client_token);
661661
}
662662

663663
if id.is_empty() {
@@ -771,7 +771,7 @@ impl Handler for TokenStore {
771771
return Err(RvError::ErrPermissionDenied);
772772
}
773773

774-
req.name = auth.as_ref().unwrap().display_name.clone();
774+
req.name.clone_from(&auth.as_ref().unwrap().display_name);
775775
req.auth = auth;
776776

777777
req.handle_phase = HandlePhase::PostAuth;
@@ -826,9 +826,9 @@ impl Handler for TokenStore {
826826
if let Some(auth) = resp.auth.as_mut() {
827827
if is_unauth_path {
828828
let source = self.router.matching_mount(&req.path)?;
829-
let source = source.as_str().trim_start_matches(AUTH_ROUTER_PREFIX).replace("/", "-");
830-
auth.display_name = (source + &auth.display_name).trim_end_matches("-").to_string();
831-
req.name = auth.display_name.clone();
829+
let source = source.as_str().trim_start_matches(AUTH_ROUTER_PREFIX).replace('/', "-");
830+
auth.display_name = (source + &auth.display_name).trim_end_matches('-').to_string();
831+
req.name.clone_from(&auth.display_name);
832832
} else if !req.path.starts_with("auth/token/") {
833833
return Err(RvError::ErrPermissionDenied);
834834
}
@@ -852,7 +852,7 @@ impl Handler for TokenStore {
852852
SystemTime::now(),
853853
)?;
854854

855-
auth.token_policies = auth.policies.clone();
855+
auth.token_policies.clone_from(&auth.policies);
856856
sanitize_policies(&mut auth.token_policies, !auth.no_default_policy);
857857

858858
let all_policies = auth.token_policies.clone();
@@ -876,7 +876,7 @@ impl Handler for TokenStore {
876876

877877
self.create(&mut te)?;
878878

879-
auth.client_token = te.id.clone();
879+
auth.client_token.clone_from(&te.id);
880880
auth.ttl = Duration::from_secs(te.ttl);
881881

882882
self.expiration.register_auth(&te, auth)?;

src/modules/credential/approle/path_role.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,7 @@ or 'secret_id_ttl' option on the role, and/or the backend mount's maximum TTL va
916916
}
917917
}
918918

919+
#[allow(clippy::assigning_clones)]
919920
impl AppRoleBackendInner {
920921
pub fn get_role_id(&self, req: &mut Request, role_id: &str) -> Result<Option<RoleIdEntry>, RvError> {
921922
if role_id.is_empty() {
@@ -995,7 +996,7 @@ impl AppRoleBackendInner {
995996
}
996997

997998
if !role_entry.bound_cidr_list.is_empty() {
998-
role_entry.secret_id_bound_cidrs = role_entry.bound_cidr_list.clone();
999+
role_entry.secret_id_bound_cidrs.clone_from(&role_entry.bound_cidr_list);
9991000
role_entry.bound_cidr_list.clear();
10001001
}
10011002

@@ -1090,7 +1091,7 @@ impl AppRoleBackendInner {
10901091
role_entry.policies = role_entry.token_policies.clone();
10911092
} else if let Ok(policies_value) = req.get_data("policies") {
10921093
let policies = policies_value.as_comma_string_slice().ok_or(RvError::ErrRequestFieldInvalid)?;
1093-
role_entry.policies = policies.clone();
1094+
role_entry.policies.clone_from(&policies);
10941095
role_entry.token_policies = policies;
10951096
}
10961097

@@ -1284,7 +1285,7 @@ impl AppRoleBackendInner {
12841285

12851286
if let Some(mut role) = self.get_role(req, &role_name)? {
12861287
sanitize_policies(&mut token_policies, false);
1287-
role.policies = token_policies.clone();
1288+
role.policies.clone_from(&token_policies);
12881289
role.token_policies = token_policies;
12891290
self.set_role(req, &role_name, &role, "")?;
12901291
} else {
@@ -1455,7 +1456,7 @@ impl AppRoleBackendInner {
14551456
}
14561457
}
14571458
"role_id" => {
1458-
previous_role_id = role.role_id.clone();
1459+
previous_role_id.clone_from(&role.role_id);
14591460
role.role_id = field_value.as_str().ok_or(RvError::ErrLogicalOperationUnsupported)?.to_string();
14601461
if role.role_id.as_str() == "" {
14611462
return Err(RvError::ErrResponse("missing role_id".to_string()));
@@ -2090,7 +2091,7 @@ impl AppRoleBackendInner {
20902091
&role_name_hmac,
20912092
&accessor_entry.secret_id_hmac,
20922093
)? {
2093-
let data = serde_json::to_value(&secret_id_entry)?;
2094+
let data = serde_json::to_value(secret_id_entry)?;
20942095
return Ok(Some(Response::data_response(Some(data.as_object().unwrap().clone()))));
20952096
}
20962097
} else {

src/modules/credential/approle/path_tidy_secret_id.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl AppRoleBackendInner {
141141

142142
let role_name_hmacs = storage.list(secret_id_prefix_to_use)?;
143143
for item in role_name_hmacs.iter() {
144-
let role_name_hmac = item.trim_end_matches("/");
144+
let role_name_hmac = item.trim_end_matches('/');
145145
log::info!("listing secret id HMACs, role_hame: {}", role_name_hmac);
146146
let key = format!("{}{}/", secret_id_prefix_to_use, role_name_hmac);
147147
let secret_id_hmacs = storage.list(&key)?;
@@ -157,7 +157,7 @@ impl AppRoleBackendInner {
157157
// mean that we fail to clean up something we ought to.
158158
let mut all_secret_id_hmacs: HashMap<String, bool> = HashMap::new();
159159
for item in role_name_hmacs.iter() {
160-
let role_name_hmac = item.trim_end_matches("/");
160+
let role_name_hmac = item.trim_end_matches('/');
161161
let key = format!("{}{}/", secret_id_prefix_to_use, role_name_hmac);
162162
let secret_id_hmacs = storage.list(&key)?;
163163
for secret_id_hmac in secret_id_hmacs.iter() {

src/modules/credential/approle/validation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ pub fn verify_cidr_role_secret_id_subset(
381381
if !secret_id_cidrs.is_empty() && !role_bound_cidr_list.is_empty() {
382382
let cidr_list: Vec<String> = role_bound_cidr_list
383383
.iter()
384-
.map(|cidr| if cidr.contains("/") { cidr.clone() } else { format!("{}/32", cidr) })
384+
.map(|cidr| if cidr.contains('/') { cidr.clone() } else { format!("{}/32", cidr) })
385385
.collect();
386386

387387
let cidr_list_ref: Vec<&str> = cidr_list.iter().map(String::as_str).collect();

src/modules/credential/cert/path_certs.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ then the next renew will cause the lease to expire.
232232
}
233233
}
234234

235+
#[allow(clippy::assigning_clones)]
235236
impl CertBackendInner {
236237
pub fn get_cert(&self, req: &Request, name: &str) -> Result<Option<CertEntry>, RvError> {
237238
let key = format!("cert/{}", name.to_lowercase());
@@ -308,7 +309,7 @@ impl CertBackendInner {
308309
if entry.is_some() {
309310
cert_entry = entry.unwrap();
310311
} else {
311-
cert_entry.name = name.clone();
312+
cert_entry.name.clone_from(&name);
312313
}
313314

314315
if let Ok(certificate_raw) = req.get_data("certificate") {
@@ -395,7 +396,7 @@ impl CertBackendInner {
395396
cert_entry.policies = cert_entry.token_policies.clone();
396397
} else if let Ok(policies_value) = req.get_data("policies") {
397398
let policies = policies_value.as_comma_string_slice().ok_or(RvError::ErrRequestFieldInvalid)?;
398-
cert_entry.policies = policies.clone();
399+
cert_entry.policies.clone_from(&policies);
399400
cert_entry.token_policies = policies;
400401
}
401402

@@ -439,7 +440,7 @@ impl CertBackendInner {
439440
}
440441

441442
if cert_entry.display_name.is_empty() {
442-
cert_entry.display_name = name.clone();
443+
cert_entry.display_name.clone_from(&name);
443444
}
444445

445446
//TODO: TTL check

src/modules/credential/cert/path_config.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ impl CertBackendInner {
8484
return Ok(None);
8585
}
8686

87-
let cfg = config.unwrap();
88-
let cfg_data = serde_json::to_value(&cfg)?;
87+
let cfg_data = serde_json::to_value(config.unwrap())?;
8988

9089
Ok(Some(Response::data_response(Some(cfg_data.as_object().unwrap().clone()))))
9190
}

src/modules/credential/cert/path_login.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ impl CertBackendInner {
658658
let mut allowed_oid_map: HashMap<String, String> = HashMap::new();
659659

660660
for oid_string in config.entry.allowed_metadata_extensions.iter() {
661-
allowed_oid_map.insert(oid_string.clone(), oid_string.replace(".", "-"));
661+
allowed_oid_map.insert(oid_string.clone(), oid_string.replace('.', "-"));
662662
}
663663

664664
unsafe {

0 commit comments

Comments
 (0)