aboutsummaryrefslogtreecommitdiff
path: root/src/model/bucket_table.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-01-04 18:59:17 +0100
committerAlex Auvolat <alex@adnab.me>2022-01-04 18:59:17 +0100
commit677ab60cc117677bf53dc4887a6ff1c094e17cd0 (patch)
treedeed8c5e3a0e22fa0d1d987d4ca1313fd5c54fb7 /src/model/bucket_table.rs
parentdf35feba18787cac06b2a87e3426752fb78da2d5 (diff)
downloadgarage-677ab60cc117677bf53dc4887a6ff1c094e17cd0.tar.gz
garage-677ab60cc117677bf53dc4887a6ff1c094e17cd0.zip
Small changes in key model and refactoringnew-buckets
Diffstat (limited to 'src/model/bucket_table.rs')
-rw-r--r--src/model/bucket_table.rs29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/model/bucket_table.rs b/src/model/bucket_table.rs
index d687e774..db7cec18 100644
--- a/src/model/bucket_table.rs
+++ b/src/model/bucket_table.rs
@@ -97,27 +97,32 @@ impl Bucket {
self.state.is_deleted()
}
+ /// Returns an option representing the parameters (None if in deleted state)
+ pub fn params(&self) -> Option<&BucketParams> {
+ self.state.as_option()
+ }
+
+ /// Mutable version of `.params()`
+ pub fn params_mut(&mut self) -> Option<&mut BucketParams> {
+ self.state.as_option_mut()
+ }
+
/// Return the list of authorized keys, when each was updated, and the permission associated to
/// the key
pub fn authorized_keys(&self) -> &[(String, BucketKeyPerm)] {
- match &self.state {
- crdt::Deletable::Deleted => &[],
- crdt::Deletable::Present(state) => state.authorized_keys.items(),
- }
+ self.params()
+ .map(|s| s.authorized_keys.items())
+ .unwrap_or(&[])
}
pub fn aliases(&self) -> &[(String, u64, bool)] {
- match &self.state {
- crdt::Deletable::Deleted => &[],
- crdt::Deletable::Present(state) => state.aliases.items(),
- }
+ self.params().map(|s| s.aliases.items()).unwrap_or(&[])
}
pub fn local_aliases(&self) -> &[((String, String), u64, bool)] {
- match &self.state {
- crdt::Deletable::Deleted => &[],
- crdt::Deletable::Present(state) => state.local_aliases.items(),
- }
+ self.params()
+ .map(|s| s.local_aliases.items())
+ .unwrap_or(&[])
}
}