From 8452da6da8a3cc34fb27ee2075954a7758cead61 Mon Sep 17 00:00:00 2001 From: holly sparkles Date: Sat, 29 Jul 2023 13:49:13 +0200 Subject: [PATCH] feat: add searching for ssh key folders --- src/bwutil.rs | 13 +++++++++++++ src/main.rs | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/bwutil.rs b/src/bwutil.rs index 398089e..6815858 100644 --- a/src/bwutil.rs +++ b/src/bwutil.rs @@ -46,6 +46,19 @@ pub fn get_session_token() -> Result { Ok(token) } +/// Search Bitwarden for folders matching `folder_name` and return the results. +pub fn exec_folder_search(session: &str, folder_name: &str) -> Result> { + let folders: Output = exec_interactive_command("bw", + ["list", "folders", "--search", &folder_name, "--session", &session].to_vec()); + let result: String = String::from_utf8_lossy(&folders.stdout).to_string(); + if result.is_empty() { + Err(anyhow!("Could not authenticate.")) + } + else { + Ok(serde_json::from_str(&result).with_context(|| "Could not deserialize folder search results.")?) + } +} + /// Execute an interactive command. /// /// The resulting output will be returned as `Output`. This is a modified version of: diff --git a/src/main.rs b/src/main.rs index f732812..1d6ba4e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,7 +37,8 @@ fn main() -> Result<()> { let session_token: String = check_session_token(&args)?; if !session_token.is_empty() { - todo!() + let result = bwutil::exec_folder_search(&session_token, &args.folder)?; + println!("{:#?}", result); } Ok(()) -- libgit2 1.7.2