diff --git a/Cargo.lock b/Cargo.lock index 9f4df85..d6458bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1064,7 +1064,7 @@ dependencies = [ [[package]] name = "khm" -version = "0.8.1" +version = "0.6.1" dependencies = [ "actix-web", "base64 0.21.7", diff --git a/Cargo.toml b/Cargo.toml index c13ae76..7fb3486 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "khm" -version = "0.6.1" +version = "0.6.2" edition = "2021" authors = ["AB "] diff --git a/src/client.rs b/src/client.rs index 1910144..78d3006 100644 --- a/src/client.rs +++ b/src/client.rs @@ -193,9 +193,12 @@ pub async fn run_client(args: crate::Args) -> std::io::Result<()> { }; let host = args.host.expect("host is required in client mode"); - info!("Client mode: Sending keys to server at {}", host); + let flow = args.flow.expect("flow is required in client mode"); + let url = format!("{}/{}", host, flow); - if let Err(e) = send_keys_to_server(&host, keys, &args.basic_auth).await { + info!("Client mode: Sending keys to server at {}", url); + + if let Err(e) = send_keys_to_server(&url, keys, &args.basic_auth).await { error!("Failed to send keys to server: {}", e); return Err(io::Error::new( io::ErrorKind::Other, @@ -205,7 +208,7 @@ pub async fn run_client(args: crate::Args) -> std::io::Result<()> { if args.in_place { info!("Client mode: In-place update is enabled. Fetching keys from server."); - let server_keys = match get_keys_from_server(&host, &args.basic_auth).await { + let server_keys = match get_keys_from_server(&url, &args.basic_auth).await { Ok(keys) => keys, Err(e) => { error!("Failed to get keys from server: {}", e); diff --git a/src/db.rs b/src/db.rs index 9ba4fa2..735ce3a 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1,5 +1,5 @@ use crate::server::SshKey; -use log::{error, info, warn}; +use log::{error, info}; use std::collections::HashMap; use std::collections::HashSet; use tokio_postgres::tls::NoTlsStream; diff --git a/src/main.rs b/src/main.rs index de83045..a0857da 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,7 +22,7 @@ use log::{error, info}; khm --server --ip 0.0.0.0 --port 1337 --db-host psql.psql.svc --db-name khm --db-user admin --db-password --flows work,home\n\ \n\ Running in client mode to send diff and sync ~/.ssh/known_hosts with remote flow `work` in place:\n\ - khm --host https://khm.example.com/work --known-hosts ~/.ssh/known_hosts --in-place\n\ + khm --host https://khm.example.com --flow work --known-hosts ~/.ssh/known_hosts --in-place\n\ \n\ " )] @@ -96,10 +96,18 @@ struct Args { #[arg( long, required_if_eq("server", "false"), - help = "Client mode: Full host address of the server to connect to. Like https://khm.example.com/" + help = "Client mode: Full host address of the server to connect to. Like https://khm.example.com" )] host: Option, + /// Flow name to use on the server + #[arg( + long, + required_if_eq("server", "false"), + help = "Client mode: Flow name to use on the server" + )] + flow: Option, + /// Path to the known_hosts file (default: ~/.ssh/known_hosts) #[arg( long, @@ -121,9 +129,9 @@ async fn main() -> std::io::Result<()> { let args = Args::parse(); // Check if we have the minimum required arguments - if !args.server && args.host.is_none() { + if !args.server && (args.host.is_none() || args.flow.is_none()) { // Neither server mode nor client mode properly configured - eprintln!("Error: You must specify either server mode (--server) or client mode (--host)"); + eprintln!("Error: You must specify either server mode (--server) or client mode (--host and --flow)"); eprintln!(); eprintln!("Examples:"); eprintln!( @@ -131,7 +139,7 @@ async fn main() -> std::io::Result<()> { env!("CARGO_PKG_NAME") ); eprintln!( - " Client mode: {} --host https://khm.example.com/work", + " Client mode: {} --host https://khm.example.com --flow work", env!("CARGO_PKG_NAME") ); eprintln!();