Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
jbesraa committed Nov 6, 2023
1 parent a23c24e commit 437b66a
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 75 deletions.
26 changes: 20 additions & 6 deletions fplus-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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::<String>("PR_NUMBER").expect("required");
let pull_request_number = sub_matches
.get_one::<String>("PR_NUMBER")
.expect("required");
let rkh_gh_handle = sub_matches
.get_one::<String>("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::<String>("PR_NUMBER").expect("required");
let pull_request_number = sub_matches
.get_one::<String>("PR_NUMBER")
.expect("required");
let notary_gh_handle = sub_matches
.get_one::<String>("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::<String>("PR_NUMBER").expect("required");
let pull_request_number = sub_matches
.get_one::<String>("PR_NUMBER")
.expect("required");
let notary_gh_handle = sub_matches
.get_one::<String>("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);
}
_ => {
Expand Down
8 changes: 5 additions & 3 deletions fplus-database/src/core/collections/logs.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -22,7 +22,9 @@ pub async fn find(state: web::Data<Mutex<Client>>) -> Result<Vec<Log>> {
if result {
let d = match cursor.deserialize_current() {
Ok(d) => d,
Err(_) => { continue; }
Err(_) => {
continue;
}
};
ret.push(d);
} else {
Expand Down
9 changes: 5 additions & 4 deletions fplus-database/src/core/collections/notary.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -14,7 +14,6 @@ pub struct Notary {
pub on_chain_address: String,
}


pub async fn find(state: web::Data<Mutex<Client>>) -> Result<Vec<Notary>> {
let notary_collection: Collection<Notary> = get_collection(state, COLLECTION_NAME).await?;
let mut cursor = notary_collection.find(None, None).await?;
Expand All @@ -23,7 +22,9 @@ pub async fn find(state: web::Data<Mutex<Client>>) -> Result<Vec<Notary>> {
if result {
let d = match cursor.deserialize_current() {
Ok(d) => d,
Err(_) => { continue; }
Err(_) => {
continue;
}
};
ret.push(d);
} else {
Expand Down
8 changes: 5 additions & 3 deletions fplus-database/src/core/collections/rkh.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -21,7 +21,9 @@ pub async fn find(state: web::Data<Mutex<Client>>) -> Result<Vec<RootKeyHolder>>
if result {
let d = match cursor.deserialize_current() {
Ok(d) => d,
Err(_) => { continue; }
Err(_) => {
continue;
}
};
ret.push(d);
} else {
Expand Down
8 changes: 4 additions & 4 deletions fplus-database/src/core/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ pub async fn setup() -> mongodb::error::Result<Client> {
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();
Expand Down
10 changes: 1 addition & 9 deletions fplus-http-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
32 changes: 17 additions & 15 deletions fplus-http-server/src/router/application.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand Down Expand Up @@ -133,7 +133,9 @@ pub async fn total_dc_reached(id: web::Path<String>) -> actix_web::Result<impl R
}

#[post("application/trigger/validate")]
pub async fn validate_application_trigger(info: web::Json<ValidationPullRequestData>) -> impl Responder {
pub async fn validate_application_trigger(
info: web::Json<ValidationPullRequestData>,
) -> impl Responder {
let pr_number = info.pr_number.trim_matches('"').parse::<u64>();

match pr_number {
Expand All @@ -142,36 +144,36 @@ pub async fn validate_application_trigger(info: web::Json<ValidationPullRequestD
Ok(result) => 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<ValidationPullRequestData>) -> impl Responder {
pub async fn validate_application_proposal(
info: web::Json<ValidationPullRequestData>,
) -> impl Responder {
let pr_number = info.pr_number.trim_matches('"').parse::<u64>();

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<ValidationPullRequestData>) -> impl Responder {
pub async fn validate_application_approval(
info: web::Json<ValidationPullRequestData>,
) -> impl Responder {
let pr_number = info.pr_number.trim_matches('"').parse::<u64>();

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"),
}
Expand Down
6 changes: 4 additions & 2 deletions fplus-http-server/src/router/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ pub async fn address_allowance(address: web::Path<String>) -> 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!");
}
}
}
Expand Down Expand Up @@ -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!");
}
}
}
7 changes: 1 addition & 6 deletions fplus-http-server/src/router/rkh.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
use actix_web::{get, HttpResponse,};

use actix_web::{get, HttpResponse};

#[get("/rkh")]
pub async fn get() -> HttpResponse {
HttpResponse::InternalServerError().finish()
}




11 changes: 5 additions & 6 deletions fplus-lib/src/core/application/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -52,7 +49,6 @@ impl file::ApplicationFile {
}
}


pub fn complete_governance_review(&self, actor: String, request: AllocationRequest) -> Self {
let new_life_cycle = self
.lifecycle
Expand All @@ -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,
Expand Down
26 changes: 14 additions & 12 deletions fplus-lib/src/external_services/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,25 +382,27 @@ impl GithubWrapper<'static> {
pub async fn get_main_branch_sha(&self) -> Result<String, http::Error> {
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::<String>(request, None).unwrap();
let request = http::request::Builder::new()
.method(http::Method::GET)
.uri(url);
let request = self.inner.build_request::<String>(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::<String>();
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::<String>();
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())
}

Expand Down
14 changes: 9 additions & 5 deletions fplus-lib/src/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
);
}
}

0 comments on commit 437b66a

Please sign in to comment.