aboutsummaryrefslogtreecommitdiff
path: root/src/model/bucket_helper.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-01-03 13:58:05 +0100
committerAlex Auvolat <alex@adnab.me>2022-01-04 12:52:46 +0100
commitbeeef4758e5ec0d521179a799a3237c2c0368911 (patch)
treeeb2734647b3c6e62cef64a5f2b533ac694252c29 /src/model/bucket_helper.rs
parentd8ab5bdc3e20759e5ba8a6844393757da3539372 (diff)
downloadgarage-beeef4758e5ec0d521179a799a3237c2c0368911.tar.gz
garage-beeef4758e5ec0d521179a799a3237c2c0368911.zip
Some movement of helper code and refactoring of error handling
Diffstat (limited to 'src/model/bucket_helper.rs')
-rw-r--r--src/model/bucket_helper.rs63
1 files changed, 0 insertions, 63 deletions
diff --git a/src/model/bucket_helper.rs b/src/model/bucket_helper.rs
deleted file mode 100644
index b55ebc4b..00000000
--- a/src/model/bucket_helper.rs
+++ /dev/null
@@ -1,63 +0,0 @@
-use garage_util::data::*;
-use garage_util::error::*;
-
-use garage_table::util::EmptyKey;
-
-use crate::bucket_table::Bucket;
-use crate::garage::Garage;
-
-pub struct BucketHelper<'a>(pub(crate) &'a Garage);
-
-impl<'a> BucketHelper<'a> {
- #[allow(clippy::ptr_arg)]
- pub async fn resolve_global_bucket_name(
- &self,
- bucket_name: &String,
- ) -> Result<Option<Uuid>, Error> {
- // Bucket names in Garage are aliases, true bucket identifiers
- // are 32-byte UUIDs. This function resolves bucket names into
- // their full identifier by looking up in the bucket_alias_table.
- // This function also allows buckets to be identified by their
- // full UUID (hex-encoded). Here, if the name to be resolved is a
- // hex string of the correct length, it is directly parsed as a bucket
- // identifier which is returned. There is no risk of this conflicting
- // with an actual bucket name: bucket names are max 63 chars long by
- // the AWS spec, and hex-encoded UUIDs are 64 chars long.
- 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())
- }
- }
-
- pub async fn get_existing_bucket(&self, bucket_id: Uuid) -> Result<Bucket, Error> {
- self.0
- .bucket_table
- .get(&bucket_id, &EmptyKey)
- .await?
- .filter(|b| !b.is_deleted())
- .map(Ok)
- .unwrap_or_else(|| {
- Err(Error::BadRpc(format!(
- "Bucket {:?} does not exist",
- bucket_id
- )))
- })
- }
-}