diff options
author | Jesse Luehrs <doy@tozt.net> | 2020-04-18 05:18:45 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2020-04-18 05:18:45 -0400 |
commit | 50ab8aabcec26d07f4b4d9652dbceac1b89a6b22 (patch) | |
tree | eadd12b800d47e721f0941d39a6826dbdb4d6353 /src/actions.rs | |
parent | 017f1b04df0701e21e7cb44e3e4f6fc505d95638 (diff) | |
download | rbw-50ab8aabcec26d07f4b4d9652dbceac1b89a6b22.tar.gz rbw-50ab8aabcec26d07f4b4d9652dbceac1b89a6b22.zip |
implement edit command
Diffstat (limited to 'src/actions.rs')
-rw-r--r-- | src/actions.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/actions.rs b/src/actions.rs index 60cc61d..634fa9a 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -102,6 +102,41 @@ fn add_once( Ok(()) } +pub fn edit( + access_token: &str, + refresh_token: &str, + id: &str, + name: &str, + username: Option<&str>, + password: Option<&str>, + notes: Option<&str>, +) -> Result<Option<String>> { + match edit_once(access_token, id, name, username, password, notes) { + Ok(()) => Ok(None), + Err(crate::error::Error::RequestUnauthorized) => { + let access_token = exchange_refresh_token(refresh_token)?; + edit_once(&access_token, id, name, username, password, notes)?; + Ok(Some(access_token)) + } + Err(e) => Err(e), + } +} + +fn edit_once( + access_token: &str, + id: &str, + name: &str, + username: Option<&str>, + password: Option<&str>, + notes: Option<&str>, +) -> Result<()> { + let config = crate::config::Config::load()?; + let client = + crate::api::Client::new(&config.base_url(), &config.identity_url()); + client.edit(access_token, id, name, username, password, notes)?; + Ok(()) +} + pub fn remove( access_token: &str, refresh_token: &str, |