diff options
author | Quentin <quentin@deuxfleurs.fr> | 2020-12-15 12:48:24 +0100 |
---|---|---|
committer | Quentin <quentin@deuxfleurs.fr> | 2020-12-15 12:48:24 +0100 |
commit | 3bc4d57a0f4a600c788a3c7ff51d633d1b7e6f09 (patch) | |
tree | 68e6651a31d167723229b3843bf195470a11a8c2 /src | |
parent | a3566e49da406db9499a58a754af725a54d332af (diff) | |
download | garage-3bc4d57a0f4a600c788a3c7ff51d633d1b7e6f09.tar.gz garage-3bc4d57a0f4a600c788a3c7ff51d633d1b7e6f09.zip |
First implementation of the CLI
Diffstat (limited to 'src')
-rw-r--r-- | src/garage/admin_rpc.rs | 47 | ||||
-rw-r--r-- | src/model/bucket_table.rs | 8 |
2 files changed, 23 insertions, 32 deletions
diff --git a/src/garage/admin_rpc.rs b/src/garage/admin_rpc.rs index 1e363677..602e0b09 100644 --- a/src/garage/admin_rpc.rs +++ b/src/garage/admin_rpc.rs @@ -156,37 +156,28 @@ impl AdminRpcHandler { ))) } BucketOperation::Website(query) => { - let bucket = self.get_existing_bucket(&query.bucket).await?; - if query.allow && query.deny { - return Err(Error::Message(format!("Website can not be both allowed and denied on a bucket"))); + let mut bucket = self.get_existing_bucket(&query.bucket).await?; + + if !(query.allow ^ query.deny) { + return Err(Error::Message(format!( + "You must specify exactly one flag, either --allow or --deny" + ))); } - /* - if query.allow || query.deny { - let exposed = query.allow; - if let BucketState::Present(state) = bucket.state.get_mut() { - let ak = state.authorized_keys; - let old_ak = ak.take_and_clear(); - ak.merge(&old_ak.update_mutator( - key_id.to_string(), - PermissionSet { - allow_read, - allow_write, - }, - )); + + if let BucketState::Present(state) = bucket.state.get_mut() { + state.website.update(query.allow); + let msg = if query.allow { + format!("Website access allowed for {}", &query.bucket) } else { - return Err(Error::Message(format!( - "Bucket is deleted in update_bucket_key" - ))); - } - } + format!("Website access denied for {}", &query.bucket) + }; - let msg = if bucket.exposed { - "Bucket is exposed as a website." + Ok(AdminRPC::Ok(msg.to_string())) } else { - "Bucket is not exposed." - };*/ - - Ok(AdminRPC::Ok(/*msg*/"".to_string())) + return Err(Error::Message(format!( + "Bucket is deleted in update_bucket_key" + ))); + } } } } @@ -270,7 +261,7 @@ impl AdminRpcHandler { .unwrap_or(Err(Error::BadRPC(format!("Key {} does not exist", id)))) } - /// Update **bucket table** to inform of the new linked key + /// Update **bucket table** to inform of the new linked key async fn update_bucket_key( &self, mut bucket: Bucket, diff --git a/src/model/bucket_table.rs b/src/model/bucket_table.rs index 609490cb..78b0416f 100644 --- a/src/model/bucket_table.rs +++ b/src/model/bucket_table.rs @@ -45,7 +45,7 @@ impl CRDT for BucketState { #[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] pub struct BucketParams { pub authorized_keys: crdt::LWWMap<String, PermissionSet>, - pub website: crdt::LWW<bool> + pub website: crdt::LWW<bool>, } impl CRDT for BucketParams { @@ -59,7 +59,7 @@ impl BucketParams { pub fn new() -> Self { BucketParams { authorized_keys: crdt::LWWMap::new(), - website: crdt::LWW::new(false) + website: crdt::LWW::new(false), } } } @@ -134,10 +134,10 @@ impl TableSchema for BucketTable { }, )); } - + let params = BucketParams { authorized_keys: keys, - website: crdt::LWW::new(false) + website: crdt::LWW::new(false), }; Some(Bucket { |