aboutsummaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
authorAlex <alex@adnab.me>2021-01-15 17:49:49 +0100
committerAlex <alex@adnab.me>2021-01-15 17:49:49 +0100
commit97494b4a190cb16986b743ba1446968a6c180c6e (patch)
tree81edd9c3fab766e83ba8d8bba962aa68e1b911c3 /src/model
parent8956db2a81c3700b62c5208cff2ca4b0b124c328 (diff)
parent851893a3f299da9eeb0ef3c745be1f30164fd6cf (diff)
downloadgarage-97494b4a190cb16986b743ba1446968a6c180c6e.tar.gz
garage-97494b4a190cb16986b743ba1446968a6c180c6e.zip
Merge pull request 'Support website publishing' (#7) from feature/website into master
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/7
Diffstat (limited to 'src/model')
-rw-r--r--src/model/bucket_table.rs47
1 files changed, 40 insertions, 7 deletions
diff --git a/src/model/bucket_table.rs b/src/model/bucket_table.rs
index 11f103ff..a101555f 100644
--- a/src/model/bucket_table.rs
+++ b/src/model/bucket_table.rs
@@ -13,6 +13,11 @@ use crate::key_table::PermissionSet;
// We use them to perform migrations.
use model010::bucket_table as prev;
+/// A bucket is a collection of objects
+///
+/// Its parameters are not directly accessible as:
+/// - It must be possible to merge paramaters, hence the use of a LWW CRDT.
+/// - 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
@@ -24,27 +29,49 @@ pub struct Bucket {
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
pub enum BucketState {
Deleted,
- Present(crdt::LWWMap<String, PermissionSet>),
+ Present(BucketParams),
}
impl CRDT for BucketState {
fn merge(&mut self, o: &Self) {
match o {
BucketState::Deleted => *self = BucketState::Deleted,
- BucketState::Present(other_ak) => {
- if let BucketState::Present(ak) = self {
- ak.merge(other_ak);
+ BucketState::Present(other_params) => {
+ if let BucketState::Present(params) = self {
+ params.merge(other_params);
}
}
}
}
}
+#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
+pub struct BucketParams {
+ pub authorized_keys: crdt::LWWMap<String, PermissionSet>,
+ pub website: crdt::LWW<bool>,
+}
+
+impl CRDT for BucketParams {
+ fn merge(&mut self, o: &Self) {
+ self.authorized_keys.merge(&o.authorized_keys);
+ self.website.merge(&o.website);
+ }
+}
+
+impl BucketParams {
+ pub fn new() -> Self {
+ BucketParams {
+ authorized_keys: crdt::LWWMap::new(),
+ website: crdt::LWW::new(false),
+ }
+ }
+}
+
impl Bucket {
pub fn new(name: String) -> Self {
Bucket {
name,
- state: crdt::LWW::new(BucketState::Present(crdt::LWWMap::new())),
+ state: crdt::LWW::new(BucketState::Present(BucketParams::new())),
}
}
pub fn is_deleted(&self) -> bool {
@@ -53,7 +80,7 @@ impl Bucket {
pub fn authorized_keys(&self) -> &[(String, u64, PermissionSet)] {
match self.state.get() {
BucketState::Deleted => &[],
- BucketState::Present(ak) => ak.items(),
+ BucketState::Present(state) => state.authorized_keys.items(),
}
}
}
@@ -110,9 +137,15 @@ impl TableSchema for BucketTable {
},
));
}
+
+ let params = BucketParams {
+ authorized_keys: keys,
+ website: crdt::LWW::new(false),
+ };
+
Some(Bucket {
name: old.name,
- state: crdt::LWW::migrate_from_raw(old.timestamp, BucketState::Present(keys)),
+ state: crdt::LWW::migrate_from_raw(old.timestamp, BucketState::Present(params)),
})
}
}