diff options
author | Alex Auvolat <alex@adnab.me> | 2022-05-13 19:36:17 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-05-13 19:36:17 +0200 |
commit | 8033bdb0b4577133cff7d4d90a811ed8f3e13365 (patch) | |
tree | 5f4abf43f18322c64db68787d91a227aa4421b97 /src/api/admin/key.rs | |
parent | 5a535788fc0a69950bbfdc6f189597c5e37a6e3b (diff) | |
download | garage-8033bdb0b4577133cff7d4d90a811ed8f3e13365.tar.gz garage-8033bdb0b4577133cff7d4d90a811ed8f3e13365.zip |
More precisions in errors & small refactoring
Diffstat (limited to 'src/api/admin/key.rs')
-rw-r--r-- | src/api/admin/key.rs | 25 |
1 files changed, 6 insertions, 19 deletions
diff --git a/src/api/admin/key.rs b/src/api/admin/key.rs index 8060bf1a..1e910d52 100644 --- a/src/api/admin/key.rs +++ b/src/api/admin/key.rs @@ -50,17 +50,12 @@ pub async fn handle_get_key_info( search: Option<String>, ) -> Result<Response<Body>, Error> { let key = if let Some(id) = id { - garage - .key_table - .get(&EmptyKey, &id) - .await? - .ok_or(Error::NoSuchAccessKey)? + garage.key_helper().get_existing_key(&id).await? } else if let Some(search) = search { garage .key_helper() .get_existing_matching_key(&search) - .await - .map_err(|_| Error::NoSuchAccessKey)? + .await? } else { unreachable!(); }; @@ -92,13 +87,9 @@ pub async fn handle_update_key( ) -> Result<Response<Body>, Error> { let req = parse_json_body::<UpdateKeyRequest>(req).await?; - let mut key = garage - .key_table - .get(&EmptyKey, &id) - .await? - .ok_or(Error::NoSuchAccessKey)?; + let mut key = garage.key_helper().get_existing_key(&id).await?; - let key_state = key.state.as_option_mut().ok_or(Error::NoSuchAccessKey)?; + let key_state = key.state.as_option_mut().unwrap(); if let Some(new_name) = req.name { key_state.name.update(new_name); @@ -127,13 +118,9 @@ struct UpdateKeyRequest { } pub async fn handle_delete_key(garage: &Arc<Garage>, id: String) -> Result<Response<Body>, Error> { - let mut key = garage - .key_table - .get(&EmptyKey, &id) - .await? - .ok_or(Error::NoSuchAccessKey)?; + let mut key = garage.key_helper().get_existing_key(&id).await?; - key.state.as_option().ok_or(Error::NoSuchAccessKey)?; + key.state.as_option().unwrap(); garage.key_helper().delete_key(&mut key).await?; |