From 0f902f595adacf834da6b870f9b8be5e5df90dfd Mon Sep 17 00:00:00 2001 From: jbesraa Date: Thu, 5 Oct 2023 16:36:50 +0300 Subject: [PATCH 1/4] add validate rkh gh handle --- Cargo.lock | 3 +++ fplus/Cargo.toml | 3 +++ fplus/src/main.rs | 38 ++++++++++++++++++++++++++++++++++---- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 27cb4eda..a5cdce9b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -828,7 +828,10 @@ dependencies = [ name = "fplus" version = "0.1.0" dependencies = [ + "actix-web", "clap", + "database", + "mongodb", ] [[package]] diff --git a/fplus/Cargo.toml b/fplus/Cargo.toml index 060d97bf..cd020b31 100644 --- a/fplus/Cargo.toml +++ b/fplus/Cargo.toml @@ -6,4 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +actix-web = "4.4.0" clap = { version = "4.4.6", features = ["derive"] } +database = { path = "../database" } +mongodb = "2.7.0" diff --git a/fplus/src/main.rs b/fplus/src/main.rs index 79c43474..cc5c3dd9 100644 --- a/fplus/src/main.rs +++ b/fplus/src/main.rs @@ -1,5 +1,30 @@ +use std::sync::Mutex; + +use actix_web::web; use clap::{arg, Command}; +async fn validate_rkh_holder(github_handle: String, app_id: String) { + let db_connection: web::Data> = + web::Data::new(Mutex::new(database::core::setup::setup().await.unwrap())); + let rkh_holders = database::core::collections::rkh::find(db_connection) + .await + .unwrap(); + let rkh_holders: Option = rkh_holders + .into_iter() + .find(|rkh| &rkh.github_handle == &github_handle); + if rkh_holders.is_none() { + println!( + "No Root Key Holder found with github handle {}", + github_handle + ); + } else { + println!( + "Validated Root Key Holder {} for application {}", + github_handle, app_id + ); + } +} + fn cli() -> Command { Command::new("filplus") .about("Fil+ CLI - Management tool for fil+ applications") @@ -9,6 +34,7 @@ fn cli() -> Command { Command::new("validate-trigger") .about("Validates triggering an application") .arg(arg!( "Application ID")) + .arg(arg!( "Github handle of Root Key Holder")) .arg_required_else_help(true), ) .subcommand( @@ -25,13 +51,17 @@ fn cli() -> Command { ) } -fn main() { +#[actix_web::main] +async fn main() -> std::io::Result<()> { let matches = cli().get_matches(); - match matches.subcommand() { + Ok(match matches.subcommand() { Some(("validate-trigger", sub_matches)) => { let app_id = sub_matches.get_one::("APP_ID").expect("required"); - println!("Validated Trigger {}", app_id); + let rkh_gh_handle = sub_matches + .get_one::("RKH_GITHUB_HANDLE") + .expect("required"); + validate_rkh_holder(rkh_gh_handle.to_string(), app_id.to_string()).await; } Some(("validate-proposal", sub_matches)) => { let app_id = sub_matches.get_one::("APP_ID").expect("required"); @@ -44,5 +74,5 @@ fn main() { _ => { println!("No subcommand was used"); } - } + }) } From 96cf3227d4069dbeefe86ff706f2b273a6b064d0 Mon Sep 17 00:00:00 2001 From: jbesraa Date: Fri, 6 Oct 2023 13:59:46 +0300 Subject: [PATCH 2/4] add another validators and remove env file(s) --- Cargo.lock | 3 +- database/Cargo.toml | 1 - database/src/core/setup.rs | 3 +- fplus/Cargo.toml | 1 + fplus/src/main.rs | 54 ++++++++------------- fplus/src/validators.rs | 74 +++++++++++++++++++++++++++++ http-server/Cargo.toml | 1 - lib/src/core/mod.rs | 20 +++++++- lib/src/external_services/github.rs | 12 +++-- 9 files changed, 126 insertions(+), 43 deletions(-) create mode 100644 fplus/src/validators.rs diff --git a/Cargo.lock b/Cargo.lock index a5cdce9b..96117301 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -647,7 +647,6 @@ version = "0.1.0" dependencies = [ "actix-web", "anyhow", - "dotenv", "mongodb", "serde", ] @@ -831,6 +830,7 @@ dependencies = [ "actix-web", "clap", "database", + "lib", "mongodb", ] @@ -1063,7 +1063,6 @@ dependencies = [ "async-trait", "chrono", "database", - "dotenv", "env_logger", "futures", "lib", diff --git a/database/Cargo.toml b/database/Cargo.toml index 3e7da0ac..9b20447f 100644 --- a/database/Cargo.toml +++ b/database/Cargo.toml @@ -8,6 +8,5 @@ edition = "2021" [dependencies] actix-web = "4.4.0" anyhow = "1.0.75" -dotenv = "0.15.0" mongodb = "2.7.0" serde = "1.0.188" diff --git a/database/src/core/setup.rs b/database/src/core/setup.rs index 3237a6aa..57a3575d 100644 --- a/database/src/core/setup.rs +++ b/database/src/core/setup.rs @@ -1,4 +1,3 @@ -use dotenv; use mongodb::{ bson::doc, options::{ClientOptions, ServerApi, ServerApiVersion}, @@ -18,7 +17,7 @@ pub async fn db_health_check(client: Client) -> mongodb::error::Result<()> { pub async fn setup() -> mongodb::error::Result { let key = "MONGODB_URL"; - let value = dotenv::var(key).expect("Expected a MONGODB_URL in the environment"); + let value = std::env::var(key).expect("Expected a MONGODB_URL in the environment"); let mut client_options = ClientOptions::parse(value).await?; // Set the server_api field of the client_options object to Stable API version 1 diff --git a/fplus/Cargo.toml b/fplus/Cargo.toml index cd020b31..776bd437 100644 --- a/fplus/Cargo.toml +++ b/fplus/Cargo.toml @@ -9,4 +9,5 @@ edition = "2021" actix-web = "4.4.0" clap = { version = "4.4.6", features = ["derive"] } database = { path = "../database" } +lib = { path = "../lib" } mongodb = "2.7.0" diff --git a/fplus/src/main.rs b/fplus/src/main.rs index cc5c3dd9..ac09372c 100644 --- a/fplus/src/main.rs +++ b/fplus/src/main.rs @@ -1,29 +1,9 @@ -use std::sync::Mutex; - -use actix_web::web; use clap::{arg, Command}; +use validators::{validate_trigger, validate_proposal}; -async fn validate_rkh_holder(github_handle: String, app_id: String) { - let db_connection: web::Data> = - web::Data::new(Mutex::new(database::core::setup::setup().await.unwrap())); - let rkh_holders = database::core::collections::rkh::find(db_connection) - .await - .unwrap(); - let rkh_holders: Option = rkh_holders - .into_iter() - .find(|rkh| &rkh.github_handle == &github_handle); - if rkh_holders.is_none() { - println!( - "No Root Key Holder found with github handle {}", - github_handle - ); - } else { - println!( - "Validated Root Key Holder {} for application {}", - github_handle, app_id - ); - } -} +use crate::validators::validate_approval; + +pub mod validators; fn cli() -> Command { Command::new("filplus") @@ -33,20 +13,21 @@ fn cli() -> Command { .subcommand( Command::new("validate-trigger") .about("Validates triggering an application") - .arg(arg!( "Application ID")) + .arg(arg!( "Pull Request Number")) .arg(arg!( "Github handle of Root Key Holder")) .arg_required_else_help(true), ) .subcommand( Command::new("validate-proposal") .about("Validates proposing an application") - .arg(arg!( "Application ID")) + .arg(arg!( "Pull Request Number")) + .arg(arg!( "Github handle of Notary")) .arg_required_else_help(true), ) .subcommand( Command::new("validate-approval") .about("Validates approving an application") - .arg(arg!( "Application ID")) + .arg(arg!( "Pull Request Number")) .arg_required_else_help(true), ) } @@ -57,19 +38,26 @@ async fn main() -> std::io::Result<()> { Ok(match matches.subcommand() { Some(("validate-trigger", sub_matches)) => { - let app_id = sub_matches.get_one::("APP_ID").expect("required"); + let pull_request_number = sub_matches.get_one::("PR_NUMBER").expect("required"); let rkh_gh_handle = sub_matches .get_one::("RKH_GITHUB_HANDLE") .expect("required"); - validate_rkh_holder(rkh_gh_handle.to_string(), app_id.to_string()).await; + validate_trigger(rkh_gh_handle.to_string(), pull_request_number.to_string()).await; } Some(("validate-proposal", sub_matches)) => { - let app_id = sub_matches.get_one::("APP_ID").expect("required"); - println!("Validated proposal {}", app_id); + let pull_request_number = sub_matches.get_one::("PR_NUMBER").expect("required"); + let notary_gh_handle = sub_matches + .get_one::("NOTARY_GITHUB_HANDLE") + .expect("required"); + validate_proposal(notary_gh_handle.to_string(), pull_request_number.to_string()).await; } Some(("validate-approval", sub_matches)) => { - let app_id = sub_matches.get_one::("APP_ID").expect("required"); - println!("Validated approval {}", app_id); + let pull_request_number = sub_matches.get_one::("PR_NUMBER").expect("required"); + let notary_gh_handle = sub_matches + .get_one::("NOTARY_GITHUB_HANDLE") + .expect("required"); + validate_approval(notary_gh_handle.to_string(), pull_request_number.to_string()).await; + println!("Validated approval {}", pull_request_number); } _ => { println!("No subcommand was used"); diff --git a/fplus/src/validators.rs b/fplus/src/validators.rs new file mode 100644 index 00000000..529934fe --- /dev/null +++ b/fplus/src/validators.rs @@ -0,0 +1,74 @@ +use actix_web::web; +use lib::core::application::ApplicationFile; +use lib; +use std::sync::Mutex; + +pub async fn validate_trigger(github_handle: String, pull_request_number: String) { + if validate_rkh_holder(&github_handle).await { + println!( + "Validated Root Key Holder {} for application {}", + &github_handle, pull_request_number + ); + } else { + println!( + "No Root Key Holder found with github handle {}", + github_handle + ); + } +} + +pub async fn validate_proposal(github_handle: String, pull_request_number: String) { + if validate_notary(&github_handle).await { + println!( + "Validated Notary {} Proposal for application {}", + &github_handle, pull_request_number + ); + } else { + println!("No Notary found with github handle {}", github_handle); + } +} + +pub async fn validate_approval(github_handle: String, pull_request_number: String) { + if validate_notary(&github_handle).await { + println!( + "Validated Notary {} Approval for application {}", + &github_handle, pull_request_number + ); + } else { + println!("No Notary found with github handle {}", github_handle); + } + let application_file: ApplicationFile = + lib::core::LDNApplication::get_by_pr_number(pull_request_number.parse().unwrap()).await.unwrap(); +} + +async fn validate_rkh_holder(github_handle: &str) -> bool { + let db_connection: web::Data> = + web::Data::new(Mutex::new(database::core::setup::setup().await.unwrap())); + let rkh_holders = database::core::collections::rkh::find(db_connection) + .await + .unwrap(); + let rkh_holders: Option = rkh_holders + .into_iter() + .find(|rkh| &rkh.github_handle == github_handle); + if rkh_holders.is_none() { + false + } else { + true + } +} + +async fn validate_notary(github_handle: &str) -> bool { + let db_connection: web::Data> = + web::Data::new(Mutex::new(database::core::setup::setup().await.unwrap())); + let notary = database::core::collections::notary::find(db_connection) + .await + .unwrap(); + let notary: Option = notary + .into_iter() + .find(|n| &n.github_handle == github_handle); + if notary.is_none() { + false + } else { + true + } +} diff --git a/http-server/Cargo.toml b/http-server/Cargo.toml index d7043226..317d0e09 100644 --- a/http-server/Cargo.toml +++ b/http-server/Cargo.toml @@ -7,7 +7,6 @@ edition = "2021" [dependencies] actix-web = "4.3.1" -dotenv = "0.15.0" serde = { version = "1.0.164", features = ["derive", "std", "serde_derive", "alloc", "rc"] } tokio = { version = "1.29.1", features = ["full"] } diff --git a/lib/src/core/mod.rs b/lib/src/core/mod.rs index dc6e4816..39386877 100644 --- a/lib/src/core/mod.rs +++ b/lib/src/core/mod.rs @@ -129,7 +129,6 @@ impl LDNApplication { /// we want to get all the pull requests, validate and then get the files from them /// we need to know how to build the path paramer the is used to get the file along with the /// branch name. - /// WIP pub async fn get_all_active_applications() -> Result, LDNApplicationError> { let gh: GithubWrapper = GithubWrapper::new(); @@ -188,7 +187,26 @@ impl LDNApplication { Ok(apps) } + /// Get Application by Pull Request Number + pub async fn get_by_pr_number(pr_number: u64) -> Result { + let gh: GithubWrapper = GithubWrapper::new(); + let pr = gh.get_pull_request_files(pr_number).await.unwrap(); + // we should only have single file in the PR + let file: FileDiff = pr[0].clone(); + let file = reqwest::Client::new() + .get(&file.raw_url.to_string()) + .send() + .await + .unwrap() + .text() + .await + .unwrap(); + let file = serde_json::from_str::(&file).unwrap(); + Ok(file) + } + /// Load Application By ID + /// TODO: FIXME! pub async fn load(application_id: String) -> Result { let gh: GithubWrapper = GithubWrapper::new(); let app_path = LDNPullRequest::application_path(&application_id); diff --git a/lib/src/external_services/github.rs b/lib/src/external_services/github.rs index 81086b12..0ee5114c 100644 --- a/lib/src/external_services/github.rs +++ b/lib/src/external_services/github.rs @@ -63,6 +63,14 @@ impl GithubWrapper<'static> { installation_id, main_branch_hash, } = GithubParams::test_env(); + dotenv::dotenv().ok(); + let gh_private_key = match std::env::var("GITHUB_PRIVATE_KEY") { + Ok(g) => g, + Err(_) => { + println!("GITHUB_PRIVATE_KEY not found in .env file"); + std::process::exit(1); + } + }; let connector = HttpsConnectorBuilder::new() .with_native_roots() // enabled the `rustls-native-certs` feature in hyper-rustls .https_only() @@ -72,9 +80,7 @@ impl GithubWrapper<'static> { let client = hyper::Client::builder() .pool_idle_timeout(std::time::Duration::from_secs(15)) .build(connector); - let key = - jsonwebtoken::EncodingKey::from_rsa_pem(include_bytes!("../../../gh-private-key.pem")) - .unwrap(); + let key = jsonwebtoken::EncodingKey::from_rsa_pem(gh_private_key.as_bytes()).unwrap(); let octocrab = OctocrabBuilder::new_empty() .with_service(client) .with_layer(&BaseUriLayer::new(Uri::from_static(GITHUB_API_URL))) From 37f3a78149f63d915642999d4d4e5a1af7ebcb59 Mon Sep 17 00:00:00 2001 From: jbesraa Date: Fri, 6 Oct 2023 14:17:39 +0300 Subject: [PATCH 3/4] change folder names --- Cargo.lock | 110 +++++++++--------- Cargo.toml | 8 +- fplus-cli/Cargo.toml | 16 +++ {fplus => fplus-cli}/src/main.rs | 0 {fplus => fplus-cli}/src/validators.rs | 17 ++- {database => fplus-database}/Cargo.toml | 2 +- .../src/core/collections/logs.rs | 0 .../src/core/collections/mod.rs | 0 .../src/core/collections/notary.rs | 0 .../src/core/collections/rkh.rs | 0 .../src/core/common.rs | 0 {database => fplus-database}/src/core/mod.rs | 0 .../src/core/setup.rs | 0 {database => fplus-database}/src/lib.rs | 0 {http-server => fplus-http-server}/Cargo.lock | 0 {http-server => fplus-http-server}/Cargo.toml | 6 +- .../src/main.rs | 2 +- .../src/router/application.rs | 2 +- .../src/router/blockchain.rs | 2 +- .../src/router/logs.rs | 6 +- .../src/router/mod.rs | 2 +- .../src/router/notary.rs | 6 +- .../src/router/rkh.rs | 6 +- {lib => fplus-lib}/Cargo.lock | 0 {lib => fplus-lib}/Cargo.toml | 2 +- Dockerfile => fplus-lib/Dockerfile | 0 {http-server => fplus-lib}/deployment.sh | 0 {lib => fplus-lib}/src/base64.rs | 0 .../src/core/application/allocations.rs | 0 .../src/core/application/core_info.rs | 0 .../src/core/application/lifecycle.rs | 0 .../src/core/application/mod.rs | 0 {lib => fplus-lib}/src/core/mod.rs | 0 .../src/external_services/blockchain.rs | 0 .../src/external_services/github.rs | 0 .../src/external_services/mod.rs | 0 {lib => fplus-lib}/src/lib.rs | 0 {lib => fplus-lib}/src/parsers.rs | 0 fplus/Cargo.toml | 13 --- 39 files changed, 101 insertions(+), 99 deletions(-) create mode 100644 fplus-cli/Cargo.toml rename {fplus => fplus-cli}/src/main.rs (100%) rename {fplus => fplus-cli}/src/validators.rs (73%) rename {database => fplus-database}/Cargo.toml (90%) rename {database => fplus-database}/src/core/collections/logs.rs (100%) rename {database => fplus-database}/src/core/collections/mod.rs (100%) rename {database => fplus-database}/src/core/collections/notary.rs (100%) rename {database => fplus-database}/src/core/collections/rkh.rs (100%) rename {database => fplus-database}/src/core/common.rs (100%) rename {database => fplus-database}/src/core/mod.rs (100%) rename {database => fplus-database}/src/core/setup.rs (100%) rename {database => fplus-database}/src/lib.rs (100%) rename {http-server => fplus-http-server}/Cargo.lock (100%) rename {http-server => fplus-http-server}/Cargo.toml (78%) rename {http-server => fplus-http-server}/src/main.rs (96%) rename {http-server => fplus-http-server}/src/router/application.rs (99%) rename {http-server => fplus-http-server}/src/router/blockchain.rs (95%) rename {http-server => fplus-http-server}/src/router/logs.rs (72%) rename {http-server => fplus-http-server}/src/router/mod.rs (85%) rename {http-server => fplus-http-server}/src/router/notary.rs (71%) rename {http-server => fplus-http-server}/src/router/rkh.rs (71%) rename {lib => fplus-lib}/Cargo.lock (100%) rename {lib => fplus-lib}/Cargo.toml (97%) rename Dockerfile => fplus-lib/Dockerfile (100%) rename {http-server => fplus-lib}/deployment.sh (100%) rename {lib => fplus-lib}/src/base64.rs (100%) rename {lib => fplus-lib}/src/core/application/allocations.rs (100%) rename {lib => fplus-lib}/src/core/application/core_info.rs (100%) rename {lib => fplus-lib}/src/core/application/lifecycle.rs (100%) rename {lib => fplus-lib}/src/core/application/mod.rs (100%) rename {lib => fplus-lib}/src/core/mod.rs (100%) rename {lib => fplus-lib}/src/external_services/blockchain.rs (100%) rename {lib => fplus-lib}/src/external_services/github.rs (100%) rename {lib => fplus-lib}/src/external_services/mod.rs (100%) rename {lib => fplus-lib}/src/lib.rs (100%) rename {lib => fplus-lib}/src/parsers.rs (100%) delete mode 100644 fplus/Cargo.toml diff --git a/Cargo.lock b/Cargo.lock index 96117301..60368158 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -641,16 +641,6 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2e66c9d817f1720209181c316d28635c050fa304f9c79e47a520882661b7308" -[[package]] -name = "database" -version = "0.1.0" -dependencies = [ - "actix-web", - "anyhow", - "mongodb", - "serde", -] - [[package]] name = "deranged" version = "0.3.8" @@ -824,14 +814,66 @@ dependencies = [ ] [[package]] -name = "fplus" +name = "fplus-cli" version = "0.1.0" dependencies = [ "actix-web", "clap", - "database", - "lib", + "fplus-database", + "fplus-lib", + "mongodb", +] + +[[package]] +name = "fplus-database" +version = "0.1.0" +dependencies = [ + "actix-web", + "anyhow", "mongodb", + "serde", +] + +[[package]] +name = "fplus-http-server" +version = "0.1.0" +dependencies = [ + "actix-cors", + "actix-web", + "anyhow", + "async-trait", + "chrono", + "env_logger", + "fplus-database", + "fplus-lib", + "futures", + "mongodb", + "reqwest", + "serde", + "serde_json", + "tokio", +] + +[[package]] +name = "fplus-lib" +version = "0.1.0" +dependencies = [ + "actix-web", + "base64 0.13.1", + "chrono", + "dotenv", + "env_logger", + "futures", + "http", + "hyper", + "hyper-rustls", + "jsonwebtoken", + "markdown", + "octocrab", + "reqwest", + "serde", + "serde_json", + "tokio", ] [[package]] @@ -1053,26 +1095,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "add0ab9360ddbd88cfeb3bd9574a1d85cfdfa14db10b3e21d3700dbc4328758f" -[[package]] -name = "http-server" -version = "0.1.0" -dependencies = [ - "actix-cors", - "actix-web", - "anyhow", - "async-trait", - "chrono", - "database", - "env_logger", - "futures", - "lib", - "mongodb", - "reqwest", - "serde", - "serde_json", - "tokio", -] - [[package]] name = "httparse" version = "1.8.0" @@ -1305,28 +1327,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -[[package]] -name = "lib" -version = "0.1.0" -dependencies = [ - "actix-web", - "base64 0.13.1", - "chrono", - "dotenv", - "env_logger", - "futures", - "http", - "hyper", - "hyper-rustls", - "jsonwebtoken", - "markdown", - "octocrab", - "reqwest", - "serde", - "serde_json", - "tokio", -] - [[package]] name = "libc" version = "0.2.148" diff --git a/Cargo.toml b/Cargo.toml index a9631805..361a407c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,10 @@ [workspace] members = [ - "lib", - "http-server", - "fplus", - "database" + "fplus-lib", + "fplus-http-server", + "fplus-cli", + "fplus-database" ] resolver = "2" diff --git a/fplus-cli/Cargo.toml b/fplus-cli/Cargo.toml new file mode 100644 index 00000000..5f3030b5 --- /dev/null +++ b/fplus-cli/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "fplus-cli" +authors = ["jbesraa"] +version = "0.1.0" +edition = "2021" +description = "FPlus cli tool to validate different states of an application" +license = "MIT OR Apache-2.0" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +actix-web = "4.4.0" +clap = { version = "4.4.6", features = ["derive"] } +fplus-database = { path = "../fplus-database", version = "0.1.0" } +fplus-lib = { path = "../fplus-lib" , version = "0.1.0" } +mongodb = "2.7.0" diff --git a/fplus/src/main.rs b/fplus-cli/src/main.rs similarity index 100% rename from fplus/src/main.rs rename to fplus-cli/src/main.rs diff --git a/fplus/src/validators.rs b/fplus-cli/src/validators.rs similarity index 73% rename from fplus/src/validators.rs rename to fplus-cli/src/validators.rs index 529934fe..df2cb958 100644 --- a/fplus/src/validators.rs +++ b/fplus-cli/src/validators.rs @@ -1,6 +1,5 @@ use actix_web::web; -use lib::core::application::ApplicationFile; -use lib; +use fplus_lib::core::application::ApplicationFile; use std::sync::Mutex; pub async fn validate_trigger(github_handle: String, pull_request_number: String) { @@ -38,16 +37,16 @@ pub async fn validate_approval(github_handle: String, pull_request_number: Strin println!("No Notary found with github handle {}", github_handle); } let application_file: ApplicationFile = - lib::core::LDNApplication::get_by_pr_number(pull_request_number.parse().unwrap()).await.unwrap(); + fplus_lib::core::LDNApplication::get_by_pr_number(pull_request_number.parse().unwrap()).await.unwrap(); } async fn validate_rkh_holder(github_handle: &str) -> bool { let db_connection: web::Data> = - web::Data::new(Mutex::new(database::core::setup::setup().await.unwrap())); - let rkh_holders = database::core::collections::rkh::find(db_connection) + web::Data::new(Mutex::new(fplus_database::core::setup::setup().await.unwrap())); + let rkh_holders = fplus_database::core::collections::rkh::find(db_connection) .await .unwrap(); - let rkh_holders: Option = rkh_holders + let rkh_holders: Option = rkh_holders .into_iter() .find(|rkh| &rkh.github_handle == github_handle); if rkh_holders.is_none() { @@ -59,11 +58,11 @@ async fn validate_rkh_holder(github_handle: &str) -> bool { async fn validate_notary(github_handle: &str) -> bool { let db_connection: web::Data> = - web::Data::new(Mutex::new(database::core::setup::setup().await.unwrap())); - let notary = database::core::collections::notary::find(db_connection) + web::Data::new(Mutex::new(fplus_database::core::setup::setup().await.unwrap())); + let notary = fplus_database::core::collections::notary::find(db_connection) .await .unwrap(); - let notary: Option = notary + let notary: Option = notary .into_iter() .find(|n| &n.github_handle == github_handle); if notary.is_none() { diff --git a/database/Cargo.toml b/fplus-database/Cargo.toml similarity index 90% rename from database/Cargo.toml rename to fplus-database/Cargo.toml index 9b20447f..7b40e52c 100644 --- a/database/Cargo.toml +++ b/fplus-database/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "database" +name = "fplus-database" version = "0.1.0" edition = "2021" diff --git a/database/src/core/collections/logs.rs b/fplus-database/src/core/collections/logs.rs similarity index 100% rename from database/src/core/collections/logs.rs rename to fplus-database/src/core/collections/logs.rs diff --git a/database/src/core/collections/mod.rs b/fplus-database/src/core/collections/mod.rs similarity index 100% rename from database/src/core/collections/mod.rs rename to fplus-database/src/core/collections/mod.rs diff --git a/database/src/core/collections/notary.rs b/fplus-database/src/core/collections/notary.rs similarity index 100% rename from database/src/core/collections/notary.rs rename to fplus-database/src/core/collections/notary.rs diff --git a/database/src/core/collections/rkh.rs b/fplus-database/src/core/collections/rkh.rs similarity index 100% rename from database/src/core/collections/rkh.rs rename to fplus-database/src/core/collections/rkh.rs diff --git a/database/src/core/common.rs b/fplus-database/src/core/common.rs similarity index 100% rename from database/src/core/common.rs rename to fplus-database/src/core/common.rs diff --git a/database/src/core/mod.rs b/fplus-database/src/core/mod.rs similarity index 100% rename from database/src/core/mod.rs rename to fplus-database/src/core/mod.rs diff --git a/database/src/core/setup.rs b/fplus-database/src/core/setup.rs similarity index 100% rename from database/src/core/setup.rs rename to fplus-database/src/core/setup.rs diff --git a/database/src/lib.rs b/fplus-database/src/lib.rs similarity index 100% rename from database/src/lib.rs rename to fplus-database/src/lib.rs diff --git a/http-server/Cargo.lock b/fplus-http-server/Cargo.lock similarity index 100% rename from http-server/Cargo.lock rename to fplus-http-server/Cargo.lock diff --git a/http-server/Cargo.toml b/fplus-http-server/Cargo.toml similarity index 78% rename from http-server/Cargo.toml rename to fplus-http-server/Cargo.toml index 317d0e09..9a6483da 100644 --- a/http-server/Cargo.toml +++ b/fplus-http-server/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "http-server" +name = "fplus-http-server" version = "0.1.0" edition = "2021" @@ -17,8 +17,8 @@ actix-cors = "0.6.4" reqwest = { version = "0.11.18", features = ["json"] } futures = "0.3.28" mongodb = "2.6.1" -lib = { path = "../lib" } -database = { path = "../database" } +fplus-lib = { path = "../fplus-lib", version = "0.1.0" } +fplus-database = { path = "../fplus-database", version = "0.1.0" } anyhow = "1.0.75" async-trait = "0.1.73" diff --git a/http-server/src/main.rs b/fplus-http-server/src/main.rs similarity index 96% rename from http-server/src/main.rs rename to fplus-http-server/src/main.rs index aaf1f3b6..ea1b5070 100644 --- a/http-server/src/main.rs +++ b/fplus-http-server/src/main.rs @@ -22,7 +22,7 @@ pub(crate) mod router; #[tokio::main] async fn main() -> std::io::Result<()> { env_logger::init_from_env(env_logger::Env::new().default_filter_or("debug")); - let client = match database::core::setup::setup().await { + let client = match fplus_database::core::setup::setup().await { Ok(client) => client, Err(e) => panic!("Error setting up database: {}", e), }; diff --git a/http-server/src/router/application.rs b/fplus-http-server/src/router/application.rs similarity index 99% rename from http-server/src/router/application.rs rename to fplus-http-server/src/router/application.rs index 3614cd22..e6260de3 100644 --- a/http-server/src/router/application.rs +++ b/fplus-http-server/src/router/application.rs @@ -1,5 +1,5 @@ use actix_web::{get, post, web, HttpResponse, Responder}; -use lib::core::{ +use fplus_lib::core::{ CompleteGovernanceReviewInfo, CompleteNewApplicationProposalInfo, CreateApplicationInfo, LDNApplication, }; diff --git a/http-server/src/router/blockchain.rs b/fplus-http-server/src/router/blockchain.rs similarity index 95% rename from http-server/src/router/blockchain.rs rename to fplus-http-server/src/router/blockchain.rs index 460aa484..5502169f 100644 --- a/http-server/src/router/blockchain.rs +++ b/fplus-http-server/src/router/blockchain.rs @@ -1,5 +1,5 @@ use actix_web::{get, web, HttpResponse, Responder}; -use lib::external_services::blockchain::BlockchainData; +use fplus_lib::external_services::blockchain::BlockchainData; /// Address Allowance. /// diff --git a/http-server/src/router/logs.rs b/fplus-http-server/src/router/logs.rs similarity index 72% rename from http-server/src/router/logs.rs rename to fplus-http-server/src/router/logs.rs index 95dd69b9..ab89b795 100644 --- a/http-server/src/router/logs.rs +++ b/fplus-http-server/src/router/logs.rs @@ -4,7 +4,7 @@ use std::sync::Mutex; #[get("/logs")] pub async fn get(db_connection: web::Data>) -> HttpResponse { - match database::core::collections::logs::find(db_connection).await { + match fplus_database::core::collections::logs::find(db_connection).await { Ok(i) => HttpResponse::Ok() .content_type(ContentType::json()) .body(serde_json::to_string(&i).unwrap()), @@ -15,9 +15,9 @@ pub async fn get(db_connection: web::Data>) -> HttpResponse { #[post("/logs")] pub async fn post( db_connection: web::Data>, - rkh: web::Json, + rkh: web::Json, ) -> HttpResponse { - match database::core::collections::logs::insert(db_connection, rkh.into_inner()).await { + match fplus_database::core::collections::logs::insert(db_connection, rkh.into_inner()).await { Ok(_) => HttpResponse::Ok().finish(), Err(_) => HttpResponse::InternalServerError().finish(), } diff --git a/http-server/src/router/mod.rs b/fplus-http-server/src/router/mod.rs similarity index 85% rename from http-server/src/router/mod.rs rename to fplus-http-server/src/router/mod.rs index 7656d51f..790a9ec4 100644 --- a/http-server/src/router/mod.rs +++ b/fplus-http-server/src/router/mod.rs @@ -12,7 +12,7 @@ pub mod rkh; #[get("/health")] pub async fn health(client: actix_web::web::Data>) -> impl Responder { let client = client.lock().unwrap(); - match database::core::setup::db_health_check(client.clone()).await { + match fplus_database::core::setup::db_health_check(client.clone()).await { Ok(_) => HttpResponse::Ok().body("OK"), Err(e) => HttpResponse::InternalServerError().body(format!("Error: {}", e)), } diff --git a/http-server/src/router/notary.rs b/fplus-http-server/src/router/notary.rs similarity index 71% rename from http-server/src/router/notary.rs rename to fplus-http-server/src/router/notary.rs index e3a75c7c..52961a08 100644 --- a/http-server/src/router/notary.rs +++ b/fplus-http-server/src/router/notary.rs @@ -4,7 +4,7 @@ use std::sync::Mutex; #[get("/notary")] pub async fn get(db_connection: web::Data>) -> HttpResponse { - match database::core::collections::notary::find(db_connection).await { + match fplus_database::core::collections::notary::find(db_connection).await { Ok(i) => HttpResponse::Ok() .content_type(ContentType::json()) .body(serde_json::to_string(&i).unwrap()), @@ -15,9 +15,9 @@ pub async fn get(db_connection: web::Data>) -> HttpResponse { #[post("/notary")] pub async fn post( db_connection: web::Data>, - rkh: web::Json, + rkh: web::Json, ) -> HttpResponse { - match database::core::collections::notary::insert(db_connection, rkh.into_inner()).await { + match fplus_database::core::collections::notary::insert(db_connection, rkh.into_inner()).await { Ok(_) => HttpResponse::Ok().finish(), Err(_) => HttpResponse::InternalServerError().finish(), } diff --git a/http-server/src/router/rkh.rs b/fplus-http-server/src/router/rkh.rs similarity index 71% rename from http-server/src/router/rkh.rs rename to fplus-http-server/src/router/rkh.rs index b35d6733..ff230157 100644 --- a/http-server/src/router/rkh.rs +++ b/fplus-http-server/src/router/rkh.rs @@ -4,7 +4,7 @@ use std::sync::Mutex; #[get("/rkh")] pub async fn get(db_connection: web::Data>) -> HttpResponse { - match database::core::collections::rkh::find(db_connection).await { + match fplus_database::core::collections::rkh::find(db_connection).await { Ok(i) => HttpResponse::Ok() .content_type(ContentType::json()) .body(serde_json::to_string(&i).unwrap()), @@ -15,9 +15,9 @@ pub async fn get(db_connection: web::Data>) -> HttpResponse { #[post("/rkh")] pub async fn post( db_connection: web::Data>, - rkh: web::Json, + rkh: web::Json, ) -> HttpResponse { - match database::core::collections::rkh::insert(db_connection, rkh.into_inner()).await { + match fplus_database::core::collections::rkh::insert(db_connection, rkh.into_inner()).await { Ok(_) => HttpResponse::Ok().finish(), Err(_) => HttpResponse::InternalServerError().finish(), } diff --git a/lib/Cargo.lock b/fplus-lib/Cargo.lock similarity index 100% rename from lib/Cargo.lock rename to fplus-lib/Cargo.lock diff --git a/lib/Cargo.toml b/fplus-lib/Cargo.toml similarity index 97% rename from lib/Cargo.toml rename to fplus-lib/Cargo.toml index dc10d3a9..5f3938c9 100644 --- a/lib/Cargo.toml +++ b/fplus-lib/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "lib" +name = "fplus-lib" version = "0.1.0" edition = "2021" diff --git a/Dockerfile b/fplus-lib/Dockerfile similarity index 100% rename from Dockerfile rename to fplus-lib/Dockerfile diff --git a/http-server/deployment.sh b/fplus-lib/deployment.sh similarity index 100% rename from http-server/deployment.sh rename to fplus-lib/deployment.sh diff --git a/lib/src/base64.rs b/fplus-lib/src/base64.rs similarity index 100% rename from lib/src/base64.rs rename to fplus-lib/src/base64.rs diff --git a/lib/src/core/application/allocations.rs b/fplus-lib/src/core/application/allocations.rs similarity index 100% rename from lib/src/core/application/allocations.rs rename to fplus-lib/src/core/application/allocations.rs diff --git a/lib/src/core/application/core_info.rs b/fplus-lib/src/core/application/core_info.rs similarity index 100% rename from lib/src/core/application/core_info.rs rename to fplus-lib/src/core/application/core_info.rs diff --git a/lib/src/core/application/lifecycle.rs b/fplus-lib/src/core/application/lifecycle.rs similarity index 100% rename from lib/src/core/application/lifecycle.rs rename to fplus-lib/src/core/application/lifecycle.rs diff --git a/lib/src/core/application/mod.rs b/fplus-lib/src/core/application/mod.rs similarity index 100% rename from lib/src/core/application/mod.rs rename to fplus-lib/src/core/application/mod.rs diff --git a/lib/src/core/mod.rs b/fplus-lib/src/core/mod.rs similarity index 100% rename from lib/src/core/mod.rs rename to fplus-lib/src/core/mod.rs diff --git a/lib/src/external_services/blockchain.rs b/fplus-lib/src/external_services/blockchain.rs similarity index 100% rename from lib/src/external_services/blockchain.rs rename to fplus-lib/src/external_services/blockchain.rs diff --git a/lib/src/external_services/github.rs b/fplus-lib/src/external_services/github.rs similarity index 100% rename from lib/src/external_services/github.rs rename to fplus-lib/src/external_services/github.rs diff --git a/lib/src/external_services/mod.rs b/fplus-lib/src/external_services/mod.rs similarity index 100% rename from lib/src/external_services/mod.rs rename to fplus-lib/src/external_services/mod.rs diff --git a/lib/src/lib.rs b/fplus-lib/src/lib.rs similarity index 100% rename from lib/src/lib.rs rename to fplus-lib/src/lib.rs diff --git a/lib/src/parsers.rs b/fplus-lib/src/parsers.rs similarity index 100% rename from lib/src/parsers.rs rename to fplus-lib/src/parsers.rs diff --git a/fplus/Cargo.toml b/fplus/Cargo.toml deleted file mode 100644 index 776bd437..00000000 --- a/fplus/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "fplus" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -actix-web = "4.4.0" -clap = { version = "4.4.6", features = ["derive"] } -database = { path = "../database" } -lib = { path = "../lib" } -mongodb = "2.7.0" From 5ad84cf821135ae10007ccb515830d4bb19e3a13 Mon Sep 17 00:00:00 2001 From: jbesraa Date: Fri, 6 Oct 2023 14:57:06 +0300 Subject: [PATCH 4/4] change env name --- fplus-lib/src/external_services/github.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fplus-lib/src/external_services/github.rs b/fplus-lib/src/external_services/github.rs index 0ee5114c..a93988f1 100644 --- a/fplus-lib/src/external_services/github.rs +++ b/fplus-lib/src/external_services/github.rs @@ -64,10 +64,10 @@ impl GithubWrapper<'static> { main_branch_hash, } = GithubParams::test_env(); dotenv::dotenv().ok(); - let gh_private_key = match std::env::var("GITHUB_PRIVATE_KEY") { + let gh_private_key = match std::env::var("GH_PRIVATE_KEY") { Ok(g) => g, Err(_) => { - println!("GITHUB_PRIVATE_KEY not found in .env file"); + println!("GH_PRIVATE_KEY not found in .env file"); std::process::exit(1); } };