aboutsummaryrefslogtreecommitdiff
path: root/src/model/bucket_table.rs
diff options
context:
space:
mode:
authorTrinity Pointard <trinity.pointard@gmail.com>2021-03-26 21:53:28 +0100
committerAlex Auvolat <alex@adnab.me>2021-04-27 16:37:10 +0200
commit67585a4ffab14ba7c4b7c6dca530c177059a91d9 (patch)
tree6fd0339f8d7f651553145a3c29decc56e29c23bd /src/model/bucket_table.rs
parentb4376108122bb09bd8cff562b718967d4332ffbe (diff)
downloadgarage-67585a4ffab14ba7c4b7c6dca530c177059a91d9.tar.gz
garage-67585a4ffab14ba7c4b7c6dca530c177059a91d9.zip
attempt at documenting model crate
Diffstat (limited to 'src/model/bucket_table.rs')
-rw-r--r--src/model/bucket_table.rs17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/model/bucket_table.rs b/src/model/bucket_table.rs
index 2ede4904..8198deb7 100644
--- a/src/model/bucket_table.rs
+++ b/src/model/bucket_table.rs
@@ -12,15 +12,18 @@ use crate::key_table::PermissionSet;
/// - A bucket has 2 states, Present or Deleted and parameters make sense only if present.
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
pub struct Bucket {
- // Primary key
+ /// Name of the bucket
pub name: String,
-
+ /// State, and configuration if not deleted, of the bucket
pub state: crdt::LWW<BucketState>,
}
+/// State of a bucket
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
pub enum BucketState {
+ /// The bucket is deleted
Deleted,
+ /// The bucket exists
Present(BucketParams),
}
@@ -37,9 +40,12 @@ impl CRDT for BucketState {
}
}
+/// Configuration for a bucket
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
pub struct BucketParams {
+ /// Map of key with access to the bucket, and what kind of access they give
pub authorized_keys: crdt::LWWMap<String, PermissionSet>,
+ /// Is the bucket served as http
pub website: crdt::LWW<bool>,
}
@@ -51,6 +57,7 @@ impl CRDT for BucketParams {
}
impl BucketParams {
+ /// Create a new default `BucketParams`
pub fn new() -> Self {
BucketParams {
authorized_keys: crdt::LWWMap::new(),
@@ -60,15 +67,21 @@ impl BucketParams {
}
impl Bucket {
+ /// Create a new bucket
pub fn new(name: String) -> Self {
Bucket {
name,
state: crdt::LWW::new(BucketState::Present(BucketParams::new())),
}
}
+
+ /// Query if bucket is deleted
pub fn is_deleted(&self) -> bool {
*self.state.get() == BucketState::Deleted
}
+
+ /// Return the list of authorized keys, when each was updated, and the permission associated to
+ /// the key
pub fn authorized_keys(&self) -> &[(String, u64, PermissionSet)] {
match self.state.get() {
BucketState::Deleted => &[],