1 Commits

Author SHA1 Message Date
A B
26acbf75ac Fix cross-flow keys 2025-05-11 23:44:18 +00:00
3 changed files with 6 additions and 8 deletions

2
Cargo.lock generated
View File

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

View File

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

View File

@ -35,8 +35,6 @@ pub fn is_valid_ssh_key(key: &str) -> bool {
|| ed25519_re.is_match(key) || ed25519_re.is_match(key)
} }
// Note: Removed unused functions insert_key_if_not_exists and insert_flow_key
pub async fn get_keys_from_db(client: &Client) -> Result<Vec<Flow>, tokio_postgres::Error> { pub async fn get_keys_from_db(client: &Client) -> Result<Vec<Flow>, tokio_postgres::Error> {
let rows = client.query( let rows = client.query(
"SELECT k.host, k.key, f.name FROM public.keys k INNER JOIN public.flows f ON k.key_id = f.key_id", "SELECT k.host, k.key, f.name FROM public.keys k INNER JOIN public.flows f ON k.key_id = f.key_id",
@ -185,9 +183,9 @@ pub async fn add_keys(
} }
}; };
// If there are no new keys, no need to update flow associations // Always try to associate all keys with the flow, regardless of whether they're new or existing
if key_stats.inserted > 0 { if !key_stats.key_id_map.is_empty() {
// Extract only key IDs from statistics // Extract all key IDs from statistics, both new and existing
let key_ids: Vec<i32> = key_stats.key_id_map.iter().map(|(_, id)| *id).collect(); let key_ids: Vec<i32> = key_stats.key_id_map.iter().map(|(_, id)| *id).collect();
// Batch insert key-flow associations // Batch insert key-flow associations
@ -209,7 +207,7 @@ pub async fn add_keys(
); );
} else { } else {
info!( info!(
"No new keys to associate from client '{}' with flow '{}'", "No keys to associate from client '{}' with flow '{}'",
client_hostname, flow_id_str client_hostname, flow_id_str
); );
} }