Complete skeleton dispatcher
- Complete the dispatcher for the 'introducer' and 'local' command. This is currently only a skeleton. - The 'introducer list' command is added.
This commit is contained in:
+52
-3
@@ -24,7 +24,7 @@ pub struct CliArgs {
|
||||
pub enum HuskSubcommands {
|
||||
Daemon(DaemonCommand),
|
||||
Introducer(IntroducerCommand),
|
||||
Local,
|
||||
Local(LocalCommand),
|
||||
}
|
||||
|
||||
// Daemon subcommands
|
||||
@@ -62,10 +62,10 @@ pub enum DaemonSubcommand {
|
||||
)]
|
||||
pub struct IntroducerCommand {
|
||||
#[clap(subcommand)]
|
||||
pub subcommand: IntroducerSubcommands,
|
||||
pub subcommand: IntroducerSubcommand,
|
||||
}
|
||||
#[derive(Debug, Subcommand)]
|
||||
pub enum IntroducerSubcommands {
|
||||
pub enum IntroducerSubcommand {
|
||||
Add(IntroducerAddCommand),
|
||||
Remove(IntroducerRemoveCommand),
|
||||
List
|
||||
@@ -105,3 +105,52 @@ pub struct IntroducerRemoveCommand {
|
||||
)]
|
||||
pub cert: String,
|
||||
}
|
||||
|
||||
// Local subcommands
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(
|
||||
name = "local",
|
||||
about = "Manage manually added certificates.",
|
||||
subcommand_required = true,
|
||||
arg_required_else_help = true,
|
||||
disable_colored_help = true,
|
||||
disable_version_flag = true,
|
||||
)]
|
||||
pub struct LocalCommand {
|
||||
#[clap(subcommand)]
|
||||
pub subcommand: LocalSubcommand,
|
||||
}
|
||||
#[derive(Debug, Subcommand)]
|
||||
pub enum LocalSubcommand {
|
||||
Add(LocalAddCommand),
|
||||
Remove(LocalRemoveCommand),
|
||||
List
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(
|
||||
name = "local_add",
|
||||
about = "Add an authenticated certificate.",
|
||||
)]
|
||||
pub struct LocalAddCommand {
|
||||
#[clap(
|
||||
long = "cert",
|
||||
help = "Certificate to add."
|
||||
)]
|
||||
pub cert: String,
|
||||
}
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(
|
||||
name = "local_remove",
|
||||
about = "Certificate to remove.",
|
||||
)]
|
||||
pub struct LocalRemoveCommand {
|
||||
#[clap(
|
||||
long = "cert",
|
||||
help = "Certificate to removed."
|
||||
)]
|
||||
pub cert: String,
|
||||
}
|
||||
|
||||
|
||||
+8
-1
@@ -5,6 +5,8 @@ use crate::cli::cli_args::{CliArgs, HuskSubcommands};
|
||||
use crate::config::HuskConfigContainer;
|
||||
|
||||
pub mod daemon;
|
||||
pub mod introducer;
|
||||
pub mod local;
|
||||
|
||||
pub async fn dispatch(cli: CliArgs, config: HuskConfigContainer) -> Result<()> {
|
||||
|
||||
@@ -12,7 +14,12 @@ pub async fn dispatch(cli: CliArgs, config: HuskConfigContainer) -> Result<()> {
|
||||
HuskSubcommands::Daemon(subcmd) => {
|
||||
commands::daemon::dispatch(subcmd, config).await?;
|
||||
},
|
||||
_ => { println!("something else"); }
|
||||
HuskSubcommands::Introducer(subcmd) => {
|
||||
commands::introducer::dispatch(subcmd, config).await?;
|
||||
},
|
||||
HuskSubcommands::Local(subcmd) => {
|
||||
commands::local::dispatch(subcmd, config).await?;
|
||||
},
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::cli::cli_args::{IntroducerCommand, IntroducerSubcommand};
|
||||
use crate::config::HuskConfigContainer;
|
||||
use crate::types::husk_context::HuskContext;
|
||||
use crate::crypto;
|
||||
|
||||
pub mod add;
|
||||
pub mod remove;
|
||||
|
||||
pub async fn dispatch(cmd: IntroducerCommand, config: HuskConfigContainer) -> Result<()> {
|
||||
match cmd.subcommand {
|
||||
IntroducerSubcommand::Add(add_cmd) => {
|
||||
add::dispatch(add_cmd, &config).await?;
|
||||
},
|
||||
IntroducerSubcommand::Remove(rm_cmd) => {
|
||||
remove::dispatch(rm_cmd, &config).await?;
|
||||
},
|
||||
IntroducerSubcommand::List => {
|
||||
println!("list");
|
||||
let context = HuskContext::new(&config.into())?;
|
||||
|
||||
for introducer in crypto::get_introducers(
|
||||
&context.cert_store,
|
||||
&context.policy,
|
||||
context.local_trust_root.fingerprint()) {
|
||||
|
||||
println!("{}", introducer);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::cli::cli_args::IntroducerAddCommand;
|
||||
use crate::config::HuskConfigContainer;
|
||||
|
||||
pub async fn dispatch(cmd: IntroducerAddCommand, _config: &HuskConfigContainer) -> Result<()> {
|
||||
println!("add");
|
||||
println!(" {:?}", cmd.cert);
|
||||
println!(" {:?}", cmd.domains);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::cli::cli_args::IntroducerRemoveCommand;
|
||||
use crate::config::HuskConfigContainer;
|
||||
|
||||
pub async fn dispatch(cmd: IntroducerRemoveCommand, _config: &HuskConfigContainer) -> Result<()> {
|
||||
println!("remove");
|
||||
println!(" {:?}", cmd.cert);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::cli::cli_args::{LocalCommand, LocalSubcommand};
|
||||
use crate::config::HuskConfigContainer;
|
||||
|
||||
pub mod add;
|
||||
pub mod remove;
|
||||
|
||||
pub async fn dispatch(cmd: LocalCommand, config: HuskConfigContainer) -> Result<()> {
|
||||
match cmd.subcommand {
|
||||
LocalSubcommand::Add(add_cmd) => {
|
||||
add::dispatch(add_cmd, &config).await?;
|
||||
},
|
||||
LocalSubcommand::Remove(rm_cmd) => {
|
||||
remove::dispatch(rm_cmd, &config).await?;
|
||||
},
|
||||
LocalSubcommand::List => {
|
||||
println!("list");
|
||||
},
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::cli::cli_args::LocalAddCommand;
|
||||
use crate::config::HuskConfigContainer;
|
||||
|
||||
pub async fn dispatch(cmd: LocalAddCommand, _config: &HuskConfigContainer) -> Result<()> {
|
||||
println!("add");
|
||||
println!(" {:?}", cmd.cert);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::cli::cli_args::LocalRemoveCommand;
|
||||
use crate::config::HuskConfigContainer;
|
||||
|
||||
pub async fn dispatch(cmd: LocalRemoveCommand, _config: &HuskConfigContainer) -> Result<()> {
|
||||
println!("remove");
|
||||
println!(" {:?}", cmd.cert);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -15,7 +15,6 @@ use indymilter::{
|
||||
Callbacks,
|
||||
Context,
|
||||
EomContext,
|
||||
Macros,
|
||||
NegotiateContext,
|
||||
ProtoOpts,
|
||||
SocketInfo,
|
||||
@@ -248,8 +247,9 @@ impl Daemon {
|
||||
Status::Continue
|
||||
}
|
||||
|
||||
/*
|
||||
fn print_macros(macros: &Macros) {
|
||||
println!(" macros: {:?}", macros.to_hash_map());
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
+3
-7
@@ -42,12 +42,8 @@ async fn main() {
|
||||
|
||||
let config_container: HuskConfigContainer = Arc::new(Mutex::new(husk_config));
|
||||
|
||||
match commands::dispatch(args, config_container).await {
|
||||
Ok(_) => {
|
||||
println!("exiting...");
|
||||
},
|
||||
Err(e) => {
|
||||
println!("exit with {:?}", e);
|
||||
}
|
||||
if let Err(e) = commands::dispatch(args, config_container).await {
|
||||
eprintln!("exit with {:?}", e);
|
||||
// XXX: actually return an error code
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,3 +56,17 @@ impl Introducer {
|
||||
}
|
||||
}
|
||||
|
||||
use std::fmt::{Display, Formatter};
|
||||
impl Display for Introducer {
|
||||
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
let uids = self.cert.userids()
|
||||
.map(|u| String::from_utf8_lossy(u.userid().value()).to_string())
|
||||
.collect::<Vec<String>>()
|
||||
.join(", ");
|
||||
write!(f, "Introducer: {}\n", self.cert.fingerprint())?;
|
||||
write!(f, " UserIDs: {}", uids)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user