From 77d005513f9a547129fee7c8760eff0bac30bd3c Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 3 May 2020 20:55:48 -0400 Subject: fix editing organization entries --- src/actions.rs | 6 ++++-- src/api.rs | 4 ++++ src/bin/rbw/commands.rs | 12 ++++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/actions.rs b/src/actions.rs index 736f43e..4f37e5b 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -149,19 +149,21 @@ pub fn edit( access_token: &str, refresh_token: &str, id: &str, + org_id: Option<&str>, name: &str, data: &crate::db::EntryData, notes: Option<&str>, history: &[crate::db::HistoryEntry], ) -> Result<(Option, ())> { with_exchange_refresh_token(access_token, refresh_token, |access_token| { - edit_once(access_token, id, name, data, notes, history) + edit_once(access_token, id, org_id, name, data, notes, history) }) } fn edit_once( access_token: &str, id: &str, + org_id: Option<&str>, name: &str, data: &crate::db::EntryData, notes: Option<&str>, @@ -170,7 +172,7 @@ fn edit_once( let config = crate::config::Config::load()?; let client = crate::api::Client::new(&config.base_url(), &config.identity_url()); - client.edit(access_token, id, name, data, notes, history)?; + client.edit(access_token, id, org_id, name, data, notes, history)?; Ok(()) } diff --git a/src/api.rs b/src/api.rs index 3eef840..73b970f 100644 --- a/src/api.rs +++ b/src/api.rs @@ -307,6 +307,8 @@ struct CiphersPostReq { struct CiphersPutReq { #[serde(rename = "type")] ty: u32, // XXX what are the valid types? + #[serde(rename = "organizationId")] + organization_id: Option, name: String, notes: Option, login: Option, @@ -594,6 +596,7 @@ impl Client { &self, access_token: &str, id: &str, + org_id: Option<&str>, name: &str, data: &crate::db::EntryData, notes: Option<&str>, @@ -601,6 +604,7 @@ impl Client { ) -> Result<()> { let mut req = CiphersPutReq { ty: 1, + organization_id: org_id.map(std::string::ToString::to_string), name: name.to_string(), notes: notes.map(std::string::ToString::to_string), login: None, diff --git a/src/bin/rbw/commands.rs b/src/bin/rbw/commands.rs index ab0fd21..fa4cc39 100644 --- a/src/bin/rbw/commands.rs +++ b/src/bin/rbw/commands.rs @@ -643,10 +643,17 @@ pub fn edit(name: &str, username: Option<&str>) -> anyhow::Result<()> { let (password, notes) = parse_editor(&contents); let password = password - .map(|password| crate::actions::encrypt(&password, None)) + .map(|password| { + crate::actions::encrypt( + &password, + entry.org_id.as_deref(), + ) + }) .transpose()?; let notes = notes - .map(|notes| crate::actions::encrypt(¬es, None)) + .map(|notes| { + crate::actions::encrypt(¬es, entry.org_id.as_deref()) + }) .transpose()?; let mut history = entry.history.clone(); let (entry_username, entry_password) = match &entry.data { @@ -680,6 +687,7 @@ pub fn edit(name: &str, username: Option<&str>) -> anyhow::Result<()> { &access_token, &refresh_token, &entry.id, + entry.org_id.as_deref(), &entry.name, &data, notes.as_deref(), -- cgit v1.2.3-54-g00ecf