-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from filecoin-project/cli/rkh-validation
add validate rkh gh handle
- Loading branch information
Showing
40 changed files
with
263 additions
and
142 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
[workspace] | ||
|
||
members = [ | ||
"lib", | ||
"http-server", | ||
"fplus", | ||
"database" | ||
"fplus-lib", | ||
"fplus-http-server", | ||
"fplus-cli", | ||
"fplus-database" | ||
] | ||
|
||
resolver = "2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use clap::{arg, Command}; | ||
use validators::{validate_trigger, validate_proposal}; | ||
|
||
use crate::validators::validate_approval; | ||
|
||
pub mod validators; | ||
|
||
fn cli() -> Command { | ||
Command::new("filplus") | ||
.about("Fil+ CLI - Management tool for fil+ applications") | ||
.subcommand_required(true) | ||
.arg_required_else_help(true) | ||
.subcommand( | ||
Command::new("validate-trigger") | ||
.about("Validates triggering an application") | ||
.arg(arg!(<PR_NUMBER> "Pull Request Number")) | ||
.arg(arg!(<RKH_GITHUB_HANDLE> "Github handle of Root Key Holder")) | ||
.arg_required_else_help(true), | ||
) | ||
.subcommand( | ||
Command::new("validate-proposal") | ||
.about("Validates proposing an application") | ||
.arg(arg!(<PR_NUMBER> "Pull Request Number")) | ||
.arg(arg!(<Notary_GITHUB_HANDLE> "Github handle of Notary")) | ||
.arg_required_else_help(true), | ||
) | ||
.subcommand( | ||
Command::new("validate-approval") | ||
.about("Validates approving an application") | ||
.arg(arg!(<PR_NUMBER> "Pull Request Number")) | ||
.arg_required_else_help(true), | ||
) | ||
} | ||
|
||
#[actix_web::main] | ||
async fn main() -> std::io::Result<()> { | ||
let matches = cli().get_matches(); | ||
|
||
Ok(match matches.subcommand() { | ||
Some(("validate-trigger", sub_matches)) => { | ||
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 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; | ||
} | ||
Some(("validate-approval", sub_matches)) => { | ||
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; | ||
println!("Validated approval {}", pull_request_number); | ||
} | ||
_ => { | ||
println!("No subcommand was used"); | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
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_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 = | ||
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<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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
http-server/src/router/application.rs → fplus-http-server/src/router/application.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
http-server/src/router/blockchain.rs → fplus-http-server/src/router/blockchain.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.