diff options
Diffstat (limited to 'src/model')
-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. |