diff --git a/fplus-cli/src/main.rs b/fplus-cli/src/main.rs index ac09372c..a9c08821 100644 --- a/fplus-cli/src/main.rs +++ b/fplus-cli/src/main.rs @@ -1,5 +1,5 @@ use clap::{arg, Command}; -use validators::{validate_trigger, validate_proposal}; +use validators::{validate_proposal, validate_trigger}; use crate::validators::validate_approval; @@ -38,25 +38,39 @@ async fn main() -> std::io::Result<()> { Ok(match matches.subcommand() { Some(("validate-trigger", sub_matches)) => { - let pull_request_number = sub_matches.get_one::("PR_NUMBER").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_trigger(rkh_gh_handle.to_string(), pull_request_number.to_string()).await; } Some(("validate-proposal", sub_matches)) => { - let pull_request_number = sub_matches.get_one::("PR_NUMBER").expect("required"); + 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; + validate_proposal( + notary_gh_handle.to_string(), + pull_request_number.to_string(), + ) + .await; } Some(("validate-approval", sub_matches)) => { - let pull_request_number = sub_matches.get_one::("PR_NUMBER").expect("required"); + 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; + validate_approval( + notary_gh_handle.to_string(), + pull_request_number.to_string(), + ) + .await; println!("Validated approval {}", pull_request_number); } _ => { diff --git a/fplus-database/src/core/collections/logs.rs b/fplus-database/src/core/collections/logs.rs index 1fe41b90..62134227 100644 --- a/fplus-database/src/core/collections/logs.rs +++ b/fplus-database/src/core/collections/logs.rs @@ -1,8 +1,8 @@ use actix_web::web; +use anyhow::Result; use mongodb::{Client, Collection}; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::sync::Mutex; -use anyhow::Result; use crate::core::common::get_collection; @@ -22,7 +22,9 @@ pub async fn find(state: web::Data>) -> Result> { if result { let d = match cursor.deserialize_current() { Ok(d) => d, - Err(_) => { continue; } + Err(_) => { + continue; + } }; ret.push(d); } else { diff --git a/fplus-database/src/core/collections/notary.rs b/fplus-database/src/core/collections/notary.rs index 3b546503..f300ba64 100644 --- a/fplus-database/src/core/collections/notary.rs +++ b/fplus-database/src/core/collections/notary.rs @@ -1,8 +1,8 @@ use actix_web::web; +use anyhow::Result; use mongodb::{Client, Collection}; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::sync::Mutex; -use anyhow::Result; use crate::core::common::get_collection; @@ -14,7 +14,6 @@ pub struct Notary { pub on_chain_address: String, } - pub async fn find(state: web::Data>) -> Result> { let notary_collection: Collection = get_collection(state, COLLECTION_NAME).await?; let mut cursor = notary_collection.find(None, None).await?; @@ -23,7 +22,9 @@ pub async fn find(state: web::Data>) -> Result> { if result { let d = match cursor.deserialize_current() { Ok(d) => d, - Err(_) => { continue; } + Err(_) => { + continue; + } }; ret.push(d); } else { diff --git a/fplus-database/src/core/collections/rkh.rs b/fplus-database/src/core/collections/rkh.rs index bf3248d4..e37e2350 100644 --- a/fplus-database/src/core/collections/rkh.rs +++ b/fplus-database/src/core/collections/rkh.rs @@ -1,8 +1,8 @@ use actix_web::web; +use anyhow::Result; use mongodb::{Client, Collection}; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::sync::Mutex; -use anyhow::Result; use crate::core::common::get_collection; @@ -21,7 +21,9 @@ pub async fn find(state: web::Data>) -> Result> if result { let d = match cursor.deserialize_current() { Ok(d) => d, - Err(_) => { continue; } + Err(_) => { + continue; + } }; ret.push(d); } else { diff --git a/fplus-database/src/core/setup.rs b/fplus-database/src/core/setup.rs index bc0c0c24..c7a97439 100644 --- a/fplus-database/src/core/setup.rs +++ b/fplus-database/src/core/setup.rs @@ -20,10 +20,10 @@ pub async fn setup() -> mongodb::error::Result { let value = std::env::var(key).expect("Expected a MONGODB_URL in the environment"); let mut client_options = ClientOptions::parse(value).await?; - let mut tls_options = TlsOptions::default(); - tls_options.allow_invalid_hostnames = Some(true); - tls_options.allow_invalid_certificates = Some(true); - client_options.tls = Some(Tls::Enabled(tls_options)); + let mut tls_options = TlsOptions::default(); + tls_options.allow_invalid_hostnames = Some(true); + tls_options.allow_invalid_certificates = Some(true); + client_options.tls = Some(Tls::Enabled(tls_options)); // Set the server_api field of the client_options object to Stable API version 1 let server_api = ServerApi::builder().version(ServerApiVersion::V1).build(); diff --git a/fplus-http-server/src/main.rs b/fplus-http-server/src/main.rs index edc07e6e..0c6476db 100644 --- a/fplus-http-server/src/main.rs +++ b/fplus-http-server/src/main.rs @@ -1,26 +1,18 @@ use actix_web::middleware::Logger; -use actix_web::{web, App, HttpServer}; +use actix_web::{App, HttpServer}; use env_logger; -use std::sync::Mutex; 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 fplus_database::core::setup::setup().await { - Ok(client) => client, - Err(e) => panic!("Error setting up database: {}", e), - }; - - let db_connection = web::Data::new(Mutex::new(client)); HttpServer::new(move || { let cors = actix_cors::Cors::default() .allow_any_origin() .allow_any_method() .allow_any_header(); App::new() - .app_data(db_connection.clone()) .wrap(Logger::default()) .wrap(cors) .service(router::health) diff --git a/fplus-http-server/src/router/application.rs b/fplus-http-server/src/router/application.rs index 8b2c49a6..5f1f2f20 100644 --- a/fplus-http-server/src/router/application.rs +++ b/fplus-http-server/src/router/application.rs @@ -1,7 +1,7 @@ use actix_web::{get, post, web, HttpResponse, Responder}; use fplus_lib::core::{ CompleteGovernanceReviewInfo, CompleteNewApplicationProposalInfo, CreateApplicationInfo, - LDNApplication, RefillInfo, ValidationPullRequestData, ValidationIssueData + LDNApplication, RefillInfo, ValidationPullRequestData, }; #[post("/application")] @@ -133,7 +133,9 @@ pub async fn total_dc_reached(id: web::Path) -> actix_web::Result) -> impl Responder { +pub async fn validate_application_trigger( + info: web::Json, +) -> impl Responder { let pr_number = info.pr_number.trim_matches('"').parse::(); match pr_number { @@ -142,36 +144,36 @@ pub async fn validate_application_trigger(info: web::Json HttpResponse::Ok().json(result), Err(e) => HttpResponse::InternalServerError().json(e.to_string()), } - }, + } Err(_) => HttpResponse::BadRequest().json("Invalid PR Number"), } } #[post("application/proposal/validate")] -pub async fn validate_application_proposal(info: web::Json) -> impl Responder { +pub async fn validate_application_proposal( + info: web::Json, +) -> impl Responder { let pr_number = info.pr_number.trim_matches('"').parse::(); match pr_number { - Ok(pr_number) => { - match LDNApplication::validate_proposal(pr_number).await { - Ok(result) => HttpResponse::Ok().json(result), - Err(e) => HttpResponse::InternalServerError().json(e.to_string()), - } + Ok(pr_number) => match LDNApplication::validate_proposal(pr_number).await { + Ok(result) => HttpResponse::Ok().json(result), + Err(e) => HttpResponse::InternalServerError().json(e.to_string()), }, Err(_) => HttpResponse::BadRequest().json("Invalid PR Number"), } } #[post("application/approval/validate")] -pub async fn validate_application_approval(info: web::Json) -> impl Responder { +pub async fn validate_application_approval( + info: web::Json, +) -> impl Responder { let pr_number = info.pr_number.trim_matches('"').parse::(); match pr_number { - Ok(pr_number) => { - match LDNApplication::validate_approval(pr_number).await { - Ok(result) => HttpResponse::Ok().json(result), - Err(e) => HttpResponse::InternalServerError().json(e.to_string()), - } + Ok(pr_number) => match LDNApplication::validate_approval(pr_number).await { + Ok(result) => HttpResponse::Ok().json(result), + Err(e) => HttpResponse::InternalServerError().json(e.to_string()), }, Err(_) => HttpResponse::BadRequest().json("Invalid PR Number"), } diff --git a/fplus-http-server/src/router/blockchain.rs b/fplus-http-server/src/router/blockchain.rs index 5502169f..8f7eefd9 100644 --- a/fplus-http-server/src/router/blockchain.rs +++ b/fplus-http-server/src/router/blockchain.rs @@ -28,7 +28,8 @@ pub async fn address_allowance(address: web::Path) -> impl Responder { { Ok(res) => return HttpResponse::Ok().body(res), Err(_) => { - return HttpResponse::InternalServerError().body("SOMETHING IS WRONG WITH DEMOB SETUP!"); + return HttpResponse::InternalServerError() + .body("SOMETHING IS WRONG WITH DEMOB SETUP!"); } } } @@ -57,7 +58,8 @@ pub async fn verified_clients() -> impl Responder { match blockchain.get_verified_clients().await { Ok(res) => return HttpResponse::Ok().body(res), Err(_) => { - return HttpResponse::InternalServerError().body("SOMETHING IS WRONG WITH DEMOB SETUP!"); + return HttpResponse::InternalServerError() + .body("SOMETHING IS WRONG WITH DEMOB SETUP!"); } } } diff --git a/fplus-http-server/src/router/rkh.rs b/fplus-http-server/src/router/rkh.rs index c45144d2..24c90f78 100644 --- a/fplus-http-server/src/router/rkh.rs +++ b/fplus-http-server/src/router/rkh.rs @@ -1,11 +1,6 @@ -use actix_web::{get, HttpResponse,}; - +use actix_web::{get, HttpResponse}; #[get("/rkh")] pub async fn get() -> HttpResponse { HttpResponse::InternalServerError().finish() } - - - - diff --git a/fplus-lib/src/core/application/mod.rs b/fplus-lib/src/core/application/mod.rs index 2bda8d52..29240f35 100644 --- a/fplus-lib/src/core/application/mod.rs +++ b/fplus-lib/src/core/application/mod.rs @@ -40,10 +40,7 @@ impl file::ApplicationFile { } pub fn move_back_to_governance_review(&self) -> Self { - let new_life_cycle = self - .lifecycle - .clone() - .move_back_to_governance_review(); // move back to submitted state + let new_life_cycle = self.lifecycle.clone().move_back_to_governance_review(); // move back to submitted state let allocation = Allocations::default(); // empty allocations Self { lifecycle: new_life_cycle, @@ -52,7 +49,6 @@ impl file::ApplicationFile { } } - pub fn complete_governance_review(&self, actor: String, request: AllocationRequest) -> Self { let new_life_cycle = self .lifecycle @@ -67,7 +63,10 @@ impl file::ApplicationFile { } pub fn start_refill_request(&mut self, request: AllocationRequest) -> Self { - let new_life_cycle = self.lifecycle.clone().start_refill_request(request.id.clone()); + let new_life_cycle = self + .lifecycle + .clone() + .start_refill_request(request.id.clone()); let allocations = self.allocation.clone().push(request.clone()); Self { lifecycle: new_life_cycle, diff --git a/fplus-lib/src/external_services/github.rs b/fplus-lib/src/external_services/github.rs index 86f98803..0a88c4b0 100644 --- a/fplus-lib/src/external_services/github.rs +++ b/fplus-lib/src/external_services/github.rs @@ -382,25 +382,27 @@ impl GithubWrapper<'static> { pub async fn get_main_branch_sha(&self) -> Result { let url = "https://api.github.com/repos/filecoin-project/filplus-tooling-backend-test/git/refs"; - let request = http::request::Builder::new().method(http::Method::GET).uri(url); - let request = self.inner.build_request::(request, None).unwrap(); + let request = http::request::Builder::new() + .method(http::Method::GET) + .uri(url); + let request = self.inner.build_request::(request, None).unwrap(); let mut response = match self.inner.execute(request).await { - Ok( r) => r, + Ok(r) => r, Err(e) => { println!("Error getting main branch sha: {:?}", e); return Ok("".to_string()); } }; - let response = response.body_mut(); - let body = hyper::body::to_bytes(response).await.unwrap(); - let shas = body.into_iter().map(|b| b as char).collect::(); - let shas: RefList = serde_json::from_str(&shas).unwrap(); - for sha in shas.0 { - if sha._ref == "refs/heads/main" { - return Ok(sha.object.sha); - } - } + let response = response.body_mut(); + let body = hyper::body::to_bytes(response).await.unwrap(); + let shas = body.into_iter().map(|b| b as char).collect::(); + let shas: RefList = serde_json::from_str(&shas).unwrap(); + for sha in shas.0 { + if sha._ref == "refs/heads/main" { + return Ok(sha.object.sha); + } + } Ok("".to_string()) } diff --git a/fplus-lib/src/parsers.rs b/fplus-lib/src/parsers.rs index d19c6f9c..715edaa0 100644 --- a/fplus-lib/src/parsers.rs +++ b/fplus-lib/src/parsers.rs @@ -3,9 +3,7 @@ use std::str::FromStr; use markdown::{mdast::Node, to_mdast, ParseOptions}; use serde::{Deserialize, Serialize}; -use crate::core::application::file::{ - Client, DataType, Datacap, DatacapGroup, Project, -}; +use crate::core::application::file::{Client, DataType, Datacap, DatacapGroup, Project}; #[derive(Serialize, Deserialize, Debug)] pub enum ParsedApplicationDataFields { @@ -307,8 +305,14 @@ mod tests { assert_eq!(parsed_ldn.project.project_id, "IDID".to_string()); assert_eq!(parsed_ldn.project.history, "history".to_string()); - assert_eq!(parsed_ldn.project.associated_projects, "asodfjads".to_string()); + assert_eq!( + parsed_ldn.project.associated_projects, + "asodfjads".to_string() + ); - assert_eq!(parsed_ldn.datacap.total_requested_amount, "11GB".to_string()); + assert_eq!( + parsed_ldn.datacap.total_requested_amount, + "11GB".to_string() + ); } }