From 8e0f6294e98a11f195be826dc4855cdf81af75f4 Mon Sep 17 00:00:00 2001 From: SHANiTH K K <59169878+shanithkk@users.noreply.github.com> Date: Wed, 22 Nov 2023 11:06:25 +0530 Subject: [PATCH] fix: fix clippy issues (#85) --- .../balance-notification-registration/src/lib.rs | 5 +++-- actions/common/src/types/context.rs | 15 ++++++++------- actions/event-registration/src/lib.rs | 6 +++--- actions/push-notification/src/lib.rs | 5 +++-- actions/user-login/src/lib.rs | 8 ++++---- actions/user-registration/src/lib.rs | 4 ++-- actions/workflow-invoker/src/lib.rs | 5 +++-- actions/workflow-invoker/src/types/mod.rs | 2 +- actions/workflow-management/src/lib.rs | 16 ++++++++-------- actions/workflow-registration/src/lib.rs | 11 ++++------- 10 files changed, 39 insertions(+), 38 deletions(-) diff --git a/actions/balance-notification-registration/src/lib.rs b/actions/balance-notification-registration/src/lib.rs index c7afe6a2..c5ba92fa 100644 --- a/actions/balance-notification-registration/src/lib.rs +++ b/actions/balance-notification-registration/src/lib.rs @@ -139,8 +139,9 @@ pub fn main(args: Value) -> Result { })) } "get" => action.get_event_sources(), - method => Err(format!("method not supported document {}", method)) - .map_err(serde::de::Error::custom), + method => { + Err(format!("method not supported document {method}")).map_err(serde::de::Error::custom) + } } } diff --git a/actions/common/src/types/context.rs b/actions/common/src/types/context.rs index 44ab6006..092d1de2 100644 --- a/actions/common/src/types/context.rs +++ b/actions/common/src/types/context.rs @@ -211,7 +211,7 @@ impl Context { pub fn update_document(&self, id: &str, rev: &str, doc: &Value) -> Result { match self.db.update(doc, id, rev).send() { Ok(r) => Ok(r.id), - Err(err) => Err(format!("error updating document {}: {:?}", doc, err)) + Err(err) => Err(format!("error updating document {doc}: {err:?}")) .map_err(serde::de::Error::custom), } } @@ -223,7 +223,7 @@ impl Context { pub fn insert_document(&self, doc: &Value, id: Option) -> Result { match self.db.insert(doc, id).send() { Ok(r) => Ok(r.id), - Err(err) => Err(format!("error creating document {}: {:?}", doc, err)) + Err(err) => Err(format!("error creating document {doc}: {err:?}")) .map_err(serde::de::Error::custom), } } @@ -231,14 +231,14 @@ impl Context { pub fn get_document(&self, id: &str) -> Result { match self.db.get(id).send::() { Ok(v) => Ok(v.into_inner().unwrap()), - Err(err) => Err(format!("error fetching document {}: {:?}", id, err)) + Err(err) => Err(format!("error fetching document {id}: {err:?}")) .map_err(serde::de::Error::custom), } } pub fn get_list(&self, db_url: &str, db_name: &str) -> Result { let client = client(); - let url = format!("{}/{}/_all_docs?include_docs=true", db_url, db_name); + let url = format!("{db_url}/{db_name}/_all_docs?include_docs=true"); if let Ok(response) = invoke_client(client.get(url)) { return match response.status() { StatusCode::OK => { @@ -254,12 +254,13 @@ impl Context { .map_err(serde::de::Error::custom); } } - _ => Err(format!("error fetching list {}", db_name)) - .map_err(serde::de::Error::custom), + _ => { + Err(format!("error fetching list {db_name}")).map_err(serde::de::Error::custom) + } }; }; - Err(format!("error fetching list {}", db_name)).map_err(serde::de::Error::custom) + Err(format!("error fetching list {db_name}")).map_err(serde::de::Error::custom) } } diff --git a/actions/event-registration/src/lib.rs b/actions/event-registration/src/lib.rs index ba8a5b6c..01d96d19 100644 --- a/actions/event-registration/src/lib.rs +++ b/actions/event-registration/src/lib.rs @@ -16,7 +16,7 @@ struct Input { db_name: String, db_url: String, feed: String, - brokers: Vec + brokers: Vec, } struct Action { @@ -84,7 +84,7 @@ impl Action { &serde_json::json!({ "annotations": [{ "key": "feed", - "value": format!("/{}/{}", namespace, feed) + "value": format!("/{namespace}/{feed}") }], "parameters": [{ "key": "topic", @@ -95,7 +95,7 @@ impl Action { self.get_context().invoke_action( &feed, &serde_json::json!({ - "triggerName": format!("/{}/{}", namespace, topic), + "triggerName": format!("/{namespace}/{topic}"), "lifecycleEvent": "CREATE", "authKey": auth_key, "topic": topic, diff --git a/actions/push-notification/src/lib.rs b/actions/push-notification/src/lib.rs index 56fbc5c4..a3deba70 100644 --- a/actions/push-notification/src/lib.rs +++ b/actions/push-notification/src/lib.rs @@ -51,8 +51,9 @@ pub fn main(args: Value) -> Result { StatusCode::OK => Ok(serde_json::json!({ "action": "success" })), - error => Err(format!("failed to push notification {:?}", error)) - .map_err(serde::de::Error::custom), + error => { + Err(format!("failed to push notification {error:?}")).map_err(serde::de::Error::custom) + } } } diff --git a/actions/user-login/src/lib.rs b/actions/user-login/src/lib.rs index 7a661f71..a291b201 100644 --- a/actions/user-login/src/lib.rs +++ b/actions/user-login/src/lib.rs @@ -66,7 +66,7 @@ impl Action { let user_id: UserId = serde_json::from_value(user_id_res).unwrap(); let res = self.get_context().get_document(&user_id.user_id)?; let user: User = serde_json::from_value(res).unwrap(); - if verify(self.params.password.clone(), &user.get_password()).unwrap() { + if verify(self.params.password.clone(), user.get_password()).unwrap() { let headers = Header::default(); let encoding_key = EncodingKey::from_secret("user_registration_token_secret_key".as_bytes()); @@ -127,7 +127,7 @@ mod tests { }); let id = uuid::Uuid::new_v4().to_string(); let doc_id = serde_json::to_value(UserId::new(id.clone())).unwrap(); - let _id_store= action + let _id_store = action .get_context() .insert_document(&doc_id, Some("test@example.com".to_string())) .unwrap(); @@ -179,8 +179,8 @@ mod tests { .get_context() .insert_document(&user, Some(id.clone())); assert_eq!(user_id.unwrap(), id); - action.login_user().unwrap(); - + let res = action.login_user(); couchdb.delete().await.expect("Stopping Container Failed"); + res.unwrap(); } } diff --git a/actions/user-registration/src/lib.rs b/actions/user-registration/src/lib.rs index 2206b962..5f9adc47 100644 --- a/actions/user-registration/src/lib.rs +++ b/actions/user-registration/src/lib.rs @@ -67,11 +67,11 @@ impl Action { let user_mail_id = self.params.email.clone(); let user = User::new(self.params.name.clone(), user_mail_id.clone(), hash); let user_id = self.generate_event_id(); - let doc = serde_json::to_value(user.clone()).unwrap(); + let doc = serde_json::to_value(user).unwrap(); let uder_id_doc = serde_json::to_value(user_id.clone()).unwrap(); self.get_context() - .insert_document(&uder_id_doc, Some(user_mail_id.clone()))?; + .insert_document(&uder_id_doc, Some(user_mail_id))?; if let Ok(id) = self .get_context() .insert_document(&doc, Some(user_id.user_id)) diff --git a/actions/workflow-invoker/src/lib.rs b/actions/workflow-invoker/src/lib.rs index c3440435..e4ec050b 100644 --- a/actions/workflow-invoker/src/lib.rs +++ b/actions/workflow-invoker/src/lib.rs @@ -64,7 +64,7 @@ impl Action { Ok(parsed.data) } - pub fn invoke_trigger(&mut self, payload: &mut Vec) -> Result { + pub fn invoke_trigger(&mut self, payload: &mut [UserData]) -> Result { let mut failed_triggers = vec![]; for user in payload.iter_mut() { @@ -73,6 +73,7 @@ impl Action { let trigger = self.params.polkadot_payout_trigger.clone(); + #[allow(clippy::collapsible_if)] if user.status { if self .get_context() @@ -84,7 +85,7 @@ impl Action { } } if !failed_triggers.is_empty() { - return Err(format!("error in triggers {:?}", failed_triggers)) + return Err(format!("error in triggers {failed_triggers:?}")) .map_err(serde::de::Error::custom); } Ok(serde_json::json!({ diff --git a/actions/workflow-invoker/src/types/mod.rs b/actions/workflow-invoker/src/types/mod.rs index db682eee..0fa9b00f 100644 --- a/actions/workflow-invoker/src/types/mod.rs +++ b/actions/workflow-invoker/src/types/mod.rs @@ -10,7 +10,7 @@ pub fn update_with(dest: &mut serde_json::Value, src: &serde_json::Value) { use serde_json::Value::{Null, Object}; match (dest, src) { - (&mut Object(ref mut map_dest), &Object(ref map_src)) => { + (&mut Object(ref mut map_dest), Object(map_src)) => { // map_dest and map_src both are Map for (key, value) in map_src { // if key is not in map_dest, create a Null object diff --git a/actions/workflow-management/src/lib.rs b/actions/workflow-management/src/lib.rs index dfea79d6..8614e4ba 100644 --- a/actions/workflow-management/src/lib.rs +++ b/actions/workflow-management/src/lib.rs @@ -130,7 +130,7 @@ impl Action { "input_data": db_input }] }), - Some(topic.to_string()), + Some(topic), ) } else { let mut doc: Topic = serde_json::from_value(context.get_document(&topic)?)?; @@ -169,10 +169,9 @@ impl Action { user_index = Some(index); } } - let status = self.params.status.clone() == "active".to_string(); - match user_index { - Some(x) => doc.data[x].status = status, - None => (), + let status = self.params.status.clone() == "active"; + if let Some(x) = user_index { + doc.data[x].status = status } context.update_document(&topic, &doc.rev, &serde_json::to_value(doc.clone())?) @@ -196,7 +195,7 @@ impl Action { doc.data.remove(x); } None => { - return Err(format!("User didnt subscribed this service",)) + return Err("User didnt subscribed this service".to_string()) .map_err(serde::de::Error::custom) } } @@ -247,8 +246,9 @@ pub fn main(args: Value) -> Result { })) } - method => Err(format!("method not supported document {}", method)) - .map_err(serde::de::Error::custom), + method => { + Err(format!("method not supported document {method}")).map_err(serde::de::Error::custom) + } } } diff --git a/actions/workflow-registration/src/lib.rs b/actions/workflow-registration/src/lib.rs index bf812785..8ba9eb9d 100644 --- a/actions/workflow-registration/src/lib.rs +++ b/actions/workflow-registration/src/lib.rs @@ -80,12 +80,9 @@ impl Action { let _data = context.get_document(&uuid)?; } let auth = self.params.openwhisk_auth.clone(); - let client_props = WskProperties::new( - auth.to_string(), - self.params.endpoint.clone(), - "guest".to_string(), - ) - .set_bypass_cerificate_check(true); + let client_props = + WskProperties::new(auth, self.params.endpoint.clone(), "guest".to_string()) + .set_bypass_cerificate_check(true); let client = OpenwhiskClient::::new(Some(&client_props)); let action = openwhisk_client_rust::Action { @@ -137,7 +134,7 @@ impl Action { Ok(serde_json::json!({"action_name" : x.name})) } - Err(e) => return Err(e).map_err(serde::de::Error::custom), + Err(e) => Err(e).map_err(serde::de::Error::custom), } } }