mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-08-17 09:07:48 +00:00
Model changes
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user