64 lines
2.0 KiB
Rust
64 lines
2.0 KiB
Rust
mod client;
|
|
|
|
use std::path::PathBuf;
|
|
use clap::{Parser, Subcommand};
|
|
use libbonknet::cert::*;
|
|
use tracing::{info};
|
|
use libbonknet::clientmsg::FromClientCommand;
|
|
use crate::client::BonkClient;
|
|
|
|
#[derive(Parser, Debug)]
|
|
#[command(version, about)]
|
|
struct Cli {
|
|
#[command(subcommand)]
|
|
command: Commands,
|
|
}
|
|
|
|
#[derive(Subcommand, Debug)]
|
|
enum Commands {
|
|
/// connect via ssh to the given remote_id.
|
|
Ssh {
|
|
remote_id: String,
|
|
},
|
|
/// send a file from source to remote. This command uses scp syntax and must contain wildcards to work (see examples).
|
|
Scp {
|
|
remote_id: String,
|
|
source: PathBuf,
|
|
dest: PathBuf,
|
|
},
|
|
/// get a list of all the servers connected to the broker.
|
|
Serverlist {
|
|
pattern: Option<String>,
|
|
},
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> std::io::Result<()> {
|
|
// Tracing Subscriber
|
|
let subscriber = tracing_subscriber::FmtSubscriber::new();
|
|
tracing::subscriber::set_global_default(subscriber).unwrap();
|
|
// CLI parsing
|
|
let cli = Cli::parse();
|
|
// Load Identity files
|
|
let client_ident = LeafCertPair::load_from_file("certs_pem/client.pem").unwrap();
|
|
let broker_root = BrokerRootCerts::load_from_file("certs_pem/broker_root_ca_cert.pem").unwrap();
|
|
let tlsconfig = client_ident.to_tlsclientconfig(&broker_root);
|
|
// Execute command
|
|
match &cli.command {
|
|
Commands::Ssh { remote_id } => {
|
|
info!("Run SSH on {remote_id}");
|
|
unimplemented!()
|
|
}
|
|
Commands::Scp { remote_id, source, dest } => {
|
|
info!("Run SCP on {} moving {} to {}", remote_id, source.display(), dest.display());
|
|
unimplemented!()
|
|
}
|
|
Commands::Serverlist { pattern } => {
|
|
info!("Run Clientlist with pattern {:?}", pattern);
|
|
let mut client = BonkClient::connect(tlsconfig, "localhost", 2541).await.unwrap();
|
|
let reply = client.send(&FromClientCommand::ServerList).await.unwrap();
|
|
info!("Reply: {:?}", reply);
|
|
}
|
|
}
|
|
Ok(())
|
|
} |