Skip to content

Commit

Permalink
Merge pull request #37 from filecoin-project/disable-database
Browse files Browse the repository at this point in the history
temp disable db integration
  • Loading branch information
kokal33 authored Oct 16, 2023
2 parents 505e74b + 550dcac commit 5d93e09
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 124 deletions.
125 changes: 63 additions & 62 deletions fplus-cli/src/validators.rs
Original file line number Diff line number Diff line change
@@ -1,73 +1,74 @@
use actix_web::web;
use fplus_lib::core::application::ApplicationFile;
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_trigger(github_handle: String, pull_request_number: String) -> bool {
true
// 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_proposal(github_handle: String, pull_request_number: String) -> bool {
true
// 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 =
fplus_lib::core::LDNApplication::get_by_pr_number(pull_request_number.parse().unwrap()).await.unwrap();
pub async fn validate_approval(github_handle: String, pull_request_number: String) -> bool {
true
// 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);
// }
}

async fn validate_rkh_holder(github_handle: &str) -> bool {
let db_connection: web::Data<Mutex<mongodb::Client>> =
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<fplus_database::core::collections::rkh::RootKeyHolder> = rkh_holders
.into_iter()
.find(|rkh| &rkh.github_handle == github_handle);
if rkh_holders.is_none() {
false
} else {
true
}
true
// let db_connection: web::Data<Mutex<mongodb::Client>> = 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<fplus_database::core::collections::rkh::RootKeyHolder> = 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<Mutex<mongodb::Client>> =
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<fplus_database::core::collections::notary::Notary> = notary
.into_iter()
.find(|n| &n.github_handle == github_handle);
if notary.is_none() {
false
} else {
true
}
true
// let db_connection: web::Data<Mutex<mongodb::Client>> = 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<fplus_database::core::collections::notary::Notary> = notary
// .into_iter()
// .find(|n| &n.github_handle == github_handle);
// if notary.is_none() {
// false
// } else {
// true
// }
}
3 changes: 0 additions & 3 deletions fplus-http-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ async fn main() -> std::io::Result<()> {
.service(router::application::get_all_applications)
.service(router::blockchain::address_allowance)
.service(router::blockchain::verified_clients)
.service(router::logs::get)
.service(router::notary::get)
.service(router::rkh::get)
})
.bind(("0.0.0.0", 8080))?
.run()
Expand Down
21 changes: 5 additions & 16 deletions fplus-http-server/src/router/logs.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
use actix_web::{get, http::header::ContentType, web, HttpResponse, post};
use actix_web::{get, http::header::ContentType, post, web, HttpResponse};
use mongodb::Client;
use std::sync::Mutex;

#[get("/logs")]
pub async fn get(db_connection: web::Data<Mutex<Client>>) -> HttpResponse {
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()),
Err(_) => HttpResponse::InternalServerError().finish(),
}
pub async fn get() -> HttpResponse {
HttpResponse::InternalServerError().finish()
}

#[post("/logs")]
pub async fn post(
db_connection: web::Data<Mutex<Client>>,
rkh: web::Json<fplus_database::core::collections::logs::Log>,
) -> HttpResponse {
match fplus_database::core::collections::logs::insert(db_connection, rkh.into_inner()).await {
Ok(_) => HttpResponse::Ok().finish(),
Err(_) => HttpResponse::InternalServerError().finish(),
}
pub async fn post() -> HttpResponse {
HttpResponse::InternalServerError().finish()
}
13 changes: 2 additions & 11 deletions fplus-http-server/src/router/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
use std::sync::Mutex;

use actix_web::{get, HttpResponse, Responder};

pub mod application;
pub mod blockchain;
pub mod logs;
pub mod notary;
pub mod rkh;

/// Return server health status
#[get("/health")]
pub async fn health(client: actix_web::web::Data<Mutex<mongodb::Client>>) -> impl Responder {
let client = client.lock().unwrap();
match fplus_database::core::setup::db_health_check(client.clone()).await {
Ok(_) => HttpResponse::Ok().body("OK"),
Err(e) => HttpResponse::InternalServerError().body(format!("Error: {}", e)),
}
pub async fn health() -> impl Responder {
HttpResponse::Ok().body("OK")
}
21 changes: 5 additions & 16 deletions fplus-http-server/src/router/notary.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
use actix_web::{get, http::header::ContentType, web, HttpResponse, post};
use actix_web::{get, http::header::ContentType, post, web, HttpResponse};
use mongodb::Client;
use std::sync::Mutex;

#[get("/notary")]
pub async fn get(db_connection: web::Data<Mutex<Client>>) -> HttpResponse {
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()),
Err(_) => HttpResponse::InternalServerError().finish(),
}
pub async fn get() -> HttpResponse {
HttpResponse::InternalServerError().finish()
}

#[post("/notary")]
pub async fn post(
db_connection: web::Data<Mutex<Client>>,
rkh: web::Json<fplus_database::core::collections::notary::Notary>,
) -> HttpResponse {
match fplus_database::core::collections::notary::insert(db_connection, rkh.into_inner()).await {
Ok(_) => HttpResponse::Ok().finish(),
Err(_) => HttpResponse::InternalServerError().finish(),
}
pub async fn post() -> HttpResponse {
HttpResponse::InternalServerError().finish()
}
21 changes: 5 additions & 16 deletions fplus-http-server/src/router/rkh.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
use actix_web::{get, http::header::ContentType, web, HttpResponse, post};
use actix_web::{get, http::header::ContentType, post, web, HttpResponse};
use mongodb::Client;
use std::sync::Mutex;

#[get("/rkh")]
pub async fn get(db_connection: web::Data<Mutex<Client>>) -> HttpResponse {
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()),
Err(_) => HttpResponse::InternalServerError().finish(),
}
pub async fn get() -> HttpResponse {
HttpResponse::InternalServerError().finish()
}

#[post("/rkh")]
pub async fn post(
db_connection: web::Data<Mutex<Client>>,
rkh: web::Json<fplus_database::core::collections::rkh::RootKeyHolder>,
) -> HttpResponse {
match fplus_database::core::collections::rkh::insert(db_connection, rkh.into_inner()).await {
Ok(_) => HttpResponse::Ok().finish(),
Err(_) => HttpResponse::InternalServerError().finish(),
}
pub async fn post() -> HttpResponse {
HttpResponse::InternalServerError().finish()
}

0 comments on commit 5d93e09

Please sign in to comment.