diff options
author | Alex Auvolat <alex@adnab.me> | 2021-12-15 18:36:15 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-01-04 12:45:51 +0100 |
commit | 53f71b3a57b3c1828292e26b7865d31e9bec44d6 (patch) | |
tree | b874fa38a3680b7ba153d34a711f4ebff6884c00 /src/model | |
parent | 5b1117e582db16cc5aa50840a685875cbd5501f4 (diff) | |
download | garage-53f71b3a57b3c1828292e26b7865d31e9bec44d6.tar.gz garage-53f71b3a57b3c1828292e26b7865d31e9bec44d6.zip |
Implement bucket alias and bucket unalias
Diffstat (limited to 'src/model')
-rw-r--r-- | src/model/bucket_helper.rs | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/model/bucket_helper.rs b/src/model/bucket_helper.rs index e0720b4e..c1280afa 100644 --- a/src/model/bucket_helper.rs +++ b/src/model/bucket_helper.rs @@ -14,13 +14,27 @@ impl<'a> BucketHelper<'a> { &self, bucket_name: &String, ) -> Result<Option<Uuid>, Error> { - Ok(self - .0 - .bucket_alias_table - .get(&EmptyKey, bucket_name) - .await? - .map(|x| x.state.get().as_option().map(|x| x.bucket_id)) - .flatten()) + let hexbucket = hex::decode(bucket_name.as_str()) + .ok() + .map(|by| Uuid::try_from(&by)) + .flatten(); + if let Some(bucket_id) = hexbucket { + Ok(self + .0 + .bucket_table + .get(&bucket_id, &EmptyKey) + .await? + .filter(|x| !x.state.is_deleted()) + .map(|_| bucket_id)) + } else { + Ok(self + .0 + .bucket_alias_table + .get(&EmptyKey, bucket_name) + .await? + .map(|x| x.state.get().as_option().map(|x| x.bucket_id)) + .flatten()) + } } #[allow(clippy::ptr_arg)] |