Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/next' into icon-eth-development
Browse files Browse the repository at this point in the history
  • Loading branch information
shanithkk committed May 12, 2024
2 parents f395c1e + 246aaca commit f2a48b9
Show file tree
Hide file tree
Showing 72 changed files with 3,583 additions and 77 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set stable version
run: rustup default 1.74
- name: Install clippy
run: rustup component add clippy
- name: Build
run: cargo build --verbose
- name: Run tests
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ members = [
# "workflow/composer-v2",
"primitives",
# "workflow/workflow_apis",
"workflow/test_util"
"workflow/test_util",
"workflow/hello_world_macro",
]

[workspace.package]
authors = ["The HugoByte Team <[email protected]>"]
edition = "2021"
repository = "https://github.com/hugobyte/aurras.git"
version = "0.0.1"
version = "0.0.1"
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ This is the end user facing component to utilize the workflow. This component co
* Balance Filter
* Balance Notification Register
* Push Notification
* Substrate Event Processor
* User Login
* User Registration
* Workflow Invoker
* Workflow Management
* Workflow Registration

### Installation

Expand All @@ -59,7 +65,7 @@ git clone https://github.com/HugoByte/aurras.git
cd aurras
```

3. Generate server token from https://console.firebase.google.com/project/[<PROJECT_NAME>/settings/cloudmessaging and add as env FIREBASE_API_KEY
3. Generate server token from https://console.firebase.google.com/project/<PROJECT_NAME>/settings/cloudmessaging and add as env FIREBASE_API_KEY

4. Deploy the actions using the deploy script. The script supports optional parameters which can be found [here](./docs/configuration.md).

Expand Down
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
11 changes: 8 additions & 3 deletions actions/workflow-invoker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ extern crate serde_json;

use serde_derive::{Deserialize, Serialize};
use serde_json::{Error, Value};
use types::UserData;
mod types;
use crate::types::update_with;
#[cfg(test)]
Expand Down Expand Up @@ -56,7 +57,7 @@ impl Action {
self.context.as_mut().expect("Action not Initialized!")
}

pub fn fetch_input(&mut self) -> Result<Vec<Value>, Error> {
pub fn fetch_input(&mut self) -> Result<Vec<UserData>, Error> {
let id = self.params.messages.clone()[0].topic.clone();
let data = self.get_context().get_document(&id)?;
let parsed = serde_json::from_value::<Topic>(data)?;
Expand Down Expand Up @@ -99,7 +100,7 @@ impl Action {

for message in payload.iter_mut() {
let data = serde_json::from_str::<Value>(&self.params.messages[0].value).unwrap();
update_with(message, &data);
update_with(&mut user.input_data, &data);

if self
.get_context()
Expand Down Expand Up @@ -163,7 +164,11 @@ mod tests {
let workflow_db = action.connect_db(&action.params.db_url, &action.params.db_name);
let workflow_management_db_context = Context::new(workflow_db, None);
let doc = serde_json::json!({
"data": [{ "url": "todo!()".to_string(), "validator": "todo!()".to_string(), "owner_key": "todo!()".to_string() }]
"data": [{
"user_id" : "asdf",
"status" : true,
"input_data" :{ "url": "todo!()".to_string(), "validator": "todo!()".to_string(), "owner_key": "todo!()".to_string() }
}]
});
let _ = workflow_management_db_context
.insert_document(&doc, Some(action.params.messages[0].topic.clone()));
Expand Down
18 changes: 13 additions & 5 deletions actions/workflow-invoker/src/types/data.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
use serde_derive::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Topic {
#[serde(rename = "_id")]
pub id: String,
#[serde(rename = "_rev")]
pub rev: String,
pub data: Vec<UserData>,
}

#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct DbDatas {
pub endpoint: String,
pub validator: String,
pub key: String,
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
pub struct UserData {
pub user_id: String,
pub status: bool,
pub input_data: serde_json::Value,
}
5 changes: 2 additions & 3 deletions actions/workflow-invoker/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ pub mod source;
pub mod topic;
pub use message::{Era, Message};
pub use source::Source;
pub use topic::Topic;
mod data;
pub use data::*;
pub use data::{Topic, UserData};

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
10 changes: 0 additions & 10 deletions actions/workflow-invoker/src/types/topic.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
use serde_derive::{Deserialize, Serialize};
use serde_json::Value;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Topic {
#[serde(skip_serializing, rename(deserialize = "_id"))]
pub id: String,
#[serde(skip_serializing, rename(deserialize = "_rev"))]
pub rev: String,
pub data: Vec<Value>,
}

#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
Expand Down
7 changes: 5 additions & 2 deletions actions/workflow-management/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ actions-common = { git = "https://github.com/HugoByte/aurras", rev = '1f7e117' }
reqwest = { version = "0.11", features = ["blocking", "json"] }
bcrypt = "0.13.0"
jsonwebtoken = "7.1"
chrono = { version = "0.4", features = ["serde"] }

[dev-dependencies]
actions-common = { git = "https://github.com/HugoByte/aurras", rev = '1f7e117', features = ["mock_containers"] }
tokio = { version = "1.0.0", features = ["macros"] }
actions-common = { git = "https://github.com/HugoByte/aurras", rev = '1f7e117', features = [
"mock_containers",
] }
tokio = { version = "1.0.0", features = ["macros"] }
Loading

0 comments on commit f2a48b9

Please sign in to comment.