aboutsummaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-01-05 15:56:48 +0100
committerAlex Auvolat <alex@adnab.me>2022-01-05 15:56:48 +0100
commit8395030e4891ae48ca30428318e8d435c157f74f (patch)
treeecbaac13a70971eb6b2d11df65bdb5f28f441484 /src/model
parent9431090b1eb9006b12395fb22700b0def7fd1f59 (diff)
downloadgarage-8395030e4891ae48ca30428318e8d435c157f74f.tar.gz
garage-8395030e4891ae48ca30428318e8d435c157f74f.zip
Implement CreateBucket
Diffstat (limited to 'src/model')
-rw-r--r--src/model/helper/bucket.rs6
-rw-r--r--src/model/permission.rs11
2 files changed, 13 insertions, 4 deletions
diff --git a/src/model/helper/bucket.rs b/src/model/helper/bucket.rs
index 6f171c8b..92b9f4cd 100644
--- a/src/model/helper/bucket.rs
+++ b/src/model/helper/bucket.rs
@@ -433,13 +433,11 @@ impl<'a> BucketHelper<'a> {
let mut bucket = self.get_internal_bucket(bucket_id).await?;
let mut key = self.get_internal_key(key_id).await?;
- let allow_any = perm.allow_read || perm.allow_write || perm.allow_owner;
-
if let Some(bstate) = bucket.state.as_option() {
if let Some(kp) = bstate.authorized_keys.get(key_id) {
perm.timestamp = increment_logical_clock_2(perm.timestamp, kp.timestamp);
}
- } else if allow_any {
+ } else if perm.is_any() {
return Err(Error::BadRequest(
"Trying to give permissions on a deleted bucket".into(),
));
@@ -449,7 +447,7 @@ impl<'a> BucketHelper<'a> {
if let Some(bp) = kstate.authorized_buckets.get(&bucket_id) {
perm.timestamp = increment_logical_clock_2(perm.timestamp, bp.timestamp);
}
- } else if allow_any {
+ } else if perm.is_any() {
return Err(Error::BadRequest(
"Trying to give permissions to a deleted key".into(),
));
diff --git a/src/model/permission.rs b/src/model/permission.rs
index 67527ed0..1eaddf00 100644
--- a/src/model/permission.rs
+++ b/src/model/permission.rs
@@ -27,6 +27,17 @@ impl BucketKeyPerm {
allow_write: false,
allow_owner: false,
};
+
+ pub const ALL_PERMISSIONS: Self = Self {
+ timestamp: 0,
+ allow_read: true,
+ allow_write: true,
+ allow_owner: true,
+ };
+
+ pub fn is_any(&self) -> bool {
+ self.allow_read || self.allow_write || self.allow_owner
+ }
}
impl Crdt for BucketKeyPerm {