From c5f46d676b4a05789788554a0723f553225fd632 Mon Sep 17 00:00:00 2001 From: Ian Letourneau Date: Tue, 9 Sep 2025 20:33:39 -0400 Subject: [PATCH] fix(secrets): use Inquire::Editor instead of regular text --- Cargo.lock | 1 + Cargo.toml | 15 +++++++++++---- harmony_secret/src/lib.rs | 22 +++++++++++++++++++--- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2af94a0..e8f0f37 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3124,6 +3124,7 @@ dependencies = [ "fxhash", "newline-converter", "once_cell", + "tempfile", "unicode-segmentation", "unicode-width 0.1.14", ] diff --git a/Cargo.toml b/Cargo.toml index d92c0e7..2d9657d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,8 @@ members = [ "harmony_composer", "harmony_inventory_agent", "harmony_secret_derive", - "harmony_secret", "adr/agent_discovery/mdns", + "harmony_secret", + "adr/agent_discovery/mdns", ] [workspace.package] @@ -50,7 +51,7 @@ k8s-openapi = { version = "0.25", features = ["v1_30"] } serde_yaml = "0.9" serde-value = "0.7" http = "1.2" -inquire = "0.7" +inquire = { version = "0.7", features = ["editor"] } convert_case = "0.8" chrono = "0.4" similar = "2" @@ -66,5 +67,11 @@ thiserror = "2.0.14" serde = { version = "1.0.209", features = ["derive", "rc"] } serde_json = "1.0.127" askama = "0.14" -sqlx = { version = "0.8", features = ["runtime-tokio", "sqlite" ] } -reqwest = { version = "0.12", features = ["blocking", "stream", "rustls-tls", "http2", "json"], default-features = false } +sqlx = { version = "0.8", features = ["runtime-tokio", "sqlite"] } +reqwest = { version = "0.12", features = [ + "blocking", + "stream", + "rustls-tls", + "http2", + "json", +], default-features = false } diff --git a/harmony_secret/src/lib.rs b/harmony_secret/src/lib.rs index a4f636f..eab0d59 100644 --- a/harmony_secret/src/lib.rs +++ b/harmony_secret/src/lib.rs @@ -120,10 +120,26 @@ impl SecretManager { let ns = &manager.namespace; let key = T::KEY; - let secret_json = inquire::Text::new(&format!( - "Secret not found for {} {}, paste the JSON here :", - ns, key + let secret_json = inquire::Editor::new(&format!( + "Secret not found for {ns} {key}, paste the JSON here :", )) + .with_formatter(&|data| { + let char_count = data.chars().count(); + if char_count == 0 { + String::from("") + } else if char_count <= 20 { + data.into() + } else { + let mut substr: String = data.chars().take(17).collect(); + substr.push_str("..."); + substr + } + }) + .with_render_config( + inquire::ui::RenderConfig::default().with_canceled_prompt_indicator( + inquire::ui::Styled::new("").with_fg(inquire::ui::Color::DarkYellow), + ), + ) .prompt() .map_err(|e| { SecretStoreError::Store(format!("Failed to prompt secret {ns} {key} : {e}").into())