Fixed client mode flow args

This commit is contained in:
Ultradesu
2025-07-19 15:51:17 +03:00
parent 45ac3fca51
commit 1eccc0e0f7
5 changed files with 22 additions and 11 deletions

2
Cargo.lock generated
View File

@@ -1064,7 +1064,7 @@ dependencies = [
[[package]]
name = "khm"
version = "0.8.1"
version = "0.6.1"
dependencies = [
"actix-web",
"base64 0.21.7",

View File

@@ -1,6 +1,6 @@
[package]
name = "khm"
version = "0.6.1"
version = "0.6.2"
edition = "2021"
authors = ["AB <ab@hexor.cy>"]

View File

@@ -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);

View File

@@ -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;

View File

@@ -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 <SECRET> --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/<FLOW_NAME>"
help = "Client mode: Full host address of the server to connect to. Like https://khm.example.com"
)]
host: Option<String>,
/// 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<String>,
/// 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!();