diff options
author | Alex Auvolat <alex@adnab.me> | 2022-05-13 15:21:32 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-05-13 15:21:32 +0200 |
commit | 7a5d329e49cc7018cbfa14d37589f51860f66cf0 (patch) | |
tree | 50be9a5eea1b2415bb541aff0c8cb33c0f47b8e4 /src/model/helper/bucket.rs | |
parent | f82b938033f1a01a136315b5f37ecb89b78bca0c (diff) | |
download | garage-7a5d329e49cc7018cbfa14d37589f51860f66cf0.tar.gz garage-7a5d329e49cc7018cbfa14d37589f51860f66cf0.zip |
More error refactoring
Diffstat (limited to 'src/model/helper/bucket.rs')
-rw-r--r-- | src/model/helper/bucket.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/model/helper/bucket.rs b/src/model/helper/bucket.rs index 788bf3a6..2f1c6ae9 100644 --- a/src/model/helper/bucket.rs +++ b/src/model/helper/bucket.rs @@ -6,6 +6,7 @@ use garage_util::time::*; use crate::bucket_alias_table::*; use crate::bucket_table::*; +use crate::key_table::*; use crate::garage::Garage; use crate::helper::error::*; use crate::helper::key::KeyHelper; @@ -49,6 +50,27 @@ impl<'a> BucketHelper<'a> { } } + #[allow(clippy::ptr_arg)] + pub async fn resolve_bucket( + &self, + bucket_name: &String, + api_key: &Key, + ) -> Result<Uuid, Error> { + let api_key_params = api_key + .state + .as_option() + .ok_or_message("Key should not be deleted at this point")?; + + if let Some(Some(bucket_id)) = api_key_params.local_aliases.get(bucket_name) { + Ok(*bucket_id) + } else { + Ok(self. + resolve_global_bucket_name(bucket_name) + .await? + .ok_or_else(|| Error::NoSuchBucket(bucket_name.to_string()))?) + } + } + /// Returns a Bucket if it is present in bucket table, /// even if it is in deleted state. Querying a non-existing /// bucket ID returns an internal error. |