From 0402e161b1a3b69af3cc8ede2fcaf1c4855b601b Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 18 Apr 2020 02:34:58 -0400 Subject: support adding entries with notes --- src/api.rs | 11 ++++------- src/bin/rbw/commands.rs | 12 +++++++----- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/api.rs b/src/api.rs index b5502e6..7ff0a8c 100644 --- a/src/api.rs +++ b/src/api.rs @@ -150,6 +150,8 @@ pub struct Cipher { pub name: String, #[serde(rename = "Login")] pub login: Login, + #[serde(rename = "Notes")] + pub notes: Option, } #[derive(serde::Serialize, serde::Deserialize, Debug)] @@ -250,18 +252,13 @@ impl Client { } } - pub fn add( - &self, - access_token: &str, - cipher: &Cipher, - // TODO: note - ) -> Result<()> { + pub fn add(&self, access_token: &str, cipher: &Cipher) -> Result<()> { let req = CiphersPostReq { ty: 1, folder_id: None, organization_id: None, name: cipher.name.clone(), - notes: None, + notes: cipher.notes.clone(), favorite: false, login: CiphersPostReqLogin { uri: None, diff --git a/src/bin/rbw/commands.rs b/src/bin/rbw/commands.rs index a42e796..3e2f241 100644 --- a/src/bin/rbw/commands.rs +++ b/src/bin/rbw/commands.rs @@ -148,18 +148,18 @@ pub fn add(name: &str, username: Option<&str>) -> anyhow::Result<()> { let password = lines.next().unwrap(); let password = crate::actions::encrypt(password)?; - let mut note: String = lines + let mut notes: String = lines .skip_while(|line| *line == "") .filter(|line| !line.starts_with('#')) .map(|line| format!("{}\n", line)) .collect(); - while note.ends_with('\n') { - note.pop(); + while notes.ends_with('\n') { + notes.pop(); } - let note = if note == "" { + let notes = if notes == "" { None } else { - Some(crate::actions::encrypt(¬e)?) + Some(crate::actions::encrypt(¬es)?) }; let cipher = rbw::api::Cipher { @@ -168,6 +168,7 @@ pub fn add(name: &str, username: Option<&str>) -> anyhow::Result<()> { username, password: Some(password), }, + notes, }; let res = rbw::actions::add(&access_token, &cipher); @@ -222,6 +223,7 @@ pub fn generate( username, password: Some(password), }, + notes: None, }; let res = rbw::actions::add(&access_token, &cipher); -- cgit v1.2.3-54-g00ecf