Skip to content

Commit

Permalink
fix: fix clippy issues (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
shanithkk authored Nov 22, 2023
1 parent 1f09715 commit 8e0f629
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 38 deletions.
5 changes: 3 additions & 2 deletions actions/balance-notification-registration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ pub fn main(args: Value) -> Result<Value, Error> {
}))
}
"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)
}
}
}

Expand Down
15 changes: 8 additions & 7 deletions actions/common/src/types/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl Context {
pub fn update_document(&self, id: &str, rev: &str, doc: &Value) -> Result<String, Error> {
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),
}
}
Expand All @@ -223,22 +223,22 @@ impl Context {
pub fn insert_document(&self, doc: &Value, id: Option<String>) -> Result<String, Error> {
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),
}
}

pub fn get_document(&self, id: &str) -> Result<Value, Error> {
match self.db.get(id).send::<Value>() {
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<Value, Error> {
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 => {
Expand All @@ -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)
}
}

Expand Down
6 changes: 3 additions & 3 deletions actions/event-registration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct Input {
db_name: String,
db_url: String,
feed: String,
brokers: Vec<String>
brokers: Vec<String>,
}

struct Action {
Expand Down Expand Up @@ -84,7 +84,7 @@ impl Action {
&serde_json::json!({
"annotations": [{
"key": "feed",
"value": format!("/{}/{}", namespace, feed)
"value": format!("/{namespace}/{feed}")
}],
"parameters": [{
"key": "topic",
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions actions/push-notification/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ pub fn main(args: Value) -> Result<Value, Error> {
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)
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions actions/user-login/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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("[email protected]".to_string()))
.unwrap();
Expand Down Expand Up @@ -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();
}
}
4 changes: 2 additions & 2 deletions actions/user-registration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 3 additions & 2 deletions actions/workflow-invoker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Action {
Ok(parsed.data)
}

pub fn invoke_trigger(&mut self, payload: &mut Vec<UserData>) -> Result<Value, Error> {
pub fn invoke_trigger(&mut self, payload: &mut [UserData]) -> Result<Value, Error> {
let mut failed_triggers = vec![];

for user in payload.iter_mut() {
Expand All @@ -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()
Expand All @@ -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!({
Expand Down
2 changes: 1 addition & 1 deletion actions/workflow-invoker/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Value>
for (key, value) in map_src {
// if key is not in map_dest, create a Null object
Expand Down
16 changes: 8 additions & 8 deletions actions/workflow-management/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?)?;
Expand Down Expand Up @@ -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())?)
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -247,8 +246,9 @@ pub fn main(args: Value) -> Result<Value, Error> {
}))
}

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)
}
}
}

Expand Down
11 changes: 4 additions & 7 deletions actions/workflow-registration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<NativeClient>::new(Some(&client_props));

let action = openwhisk_client_rust::Action {
Expand Down Expand Up @@ -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),
}
}
}
Expand Down

0 comments on commit 8e0f629

Please sign in to comment.