aboutsummaryrefslogtreecommitdiffstats
path: root/src/actions.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2020-04-18 04:24:26 -0400
committerJesse Luehrs <doy@tozt.net>2020-04-18 04:30:04 -0400
commit3765d4f2edc5933f61fd46ab130e366774556cf5 (patch)
tree930ce485993d46dd1e13f00fae00930521c0ef39 /src/actions.rs
parentb3c69bf88d973af04433d450a659ef1581d813e2 (diff)
downloadrbw-3765d4f2edc5933f61fd46ab130e366774556cf5.tar.gz
rbw-3765d4f2edc5933f61fd46ab130e366774556cf5.zip
implement remove
Diffstat (limited to 'src/actions.rs')
-rw-r--r--src/actions.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/actions.rs b/src/actions.rs
index ad99b5f..60cc61d 100644
--- a/src/actions.rs
+++ b/src/actions.rs
@@ -102,6 +102,30 @@ fn add_once(
Ok(())
}
+pub fn remove(
+ access_token: &str,
+ refresh_token: &str,
+ id: &str,
+) -> Result<Option<String>> {
+ match remove_once(access_token, id) {
+ Ok(()) => Ok(None),
+ Err(crate::error::Error::RequestUnauthorized) => {
+ let access_token = exchange_refresh_token(refresh_token)?;
+ remove_once(&access_token, id)?;
+ Ok(Some(access_token))
+ }
+ Err(e) => Err(e),
+ }
+}
+
+fn remove_once(access_token: &str, id: &str) -> Result<()> {
+ let config = crate::config::Config::load()?;
+ let client =
+ crate::api::Client::new(&config.base_url(), &config.identity_url());
+ client.remove(access_token, id)?;
+ Ok(())
+}
+
fn exchange_refresh_token(refresh_token: &str) -> Result<String> {
let config = crate::config::Config::load()?;
let client =