diff options
author | Alex Auvolat <alex@adnab.me> | 2021-12-16 11:47:58 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-01-04 12:45:52 +0100 |
commit | 0bbb6673e7ce703e470a3c2aad620ee5f009bc84 (patch) | |
tree | 844e95b50e2bc129403b679a6c5d63ff82940ad6 /src/model/key_table.rs | |
parent | 53f71b3a57b3c1828292e26b7865d31e9bec44d6 (diff) | |
download | garage-0bbb6673e7ce703e470a3c2aad620ee5f009bc84.tar.gz garage-0bbb6673e7ce703e470a3c2aad620ee5f009bc84.zip |
Model changes
Diffstat (limited to 'src/model/key_table.rs')
-rw-r--r-- | src/model/key_table.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/model/key_table.rs b/src/model/key_table.rs index e87f5949..469dbd49 100644 --- a/src/model/key_table.rs +++ b/src/model/key_table.rs @@ -27,6 +27,7 @@ pub struct Key { /// Configuration for a key #[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] pub struct KeyParams { + pub allow_create_bucket: crdt::Lww<bool>, pub authorized_buckets: crdt::Map<Uuid, BucketKeyPerm>, pub local_aliases: crdt::LwwMap<String, crdt::Deletable<Uuid>>, } @@ -34,6 +35,7 @@ pub struct KeyParams { impl KeyParams { pub fn new() -> Self { KeyParams { + allow_create_bucket: crdt::Lww::new(false), authorized_buckets: crdt::Map::new(), local_aliases: crdt::LwwMap::new(), } @@ -48,6 +50,7 @@ impl Default for KeyParams { impl Crdt for KeyParams { fn merge(&mut self, o: &Self) { + self.allow_create_bucket.merge(&o.allow_create_bucket); self.authorized_buckets.merge(&o.authorized_buckets); self.local_aliases.merge(&o.local_aliases); } @@ -111,6 +114,19 @@ impl Key { false } } + + /// Check if `Key` is owner of bucket + pub fn allow_owner(&self, bucket: &Uuid) -> bool { + if let crdt::Deletable::Present(params) = &self.state { + params + .authorized_buckets + .get(bucket) + .map(|x| x.allow_owner) + .unwrap_or(false) + } else { + false + } + } } impl Entry<EmptyKey, String> for Key { |