Support website publishing #7

Merged
lx merged 61 commits from feature/website into master 2021-01-15 16:49:51 +00:00
2 changed files with 23 additions and 32 deletions
Showing only changes of commit 3bc4d57a0f - Show all commits

View file

@ -156,37 +156,28 @@ impl AdminRpcHandler {
))) )))
} }
BucketOperation::Website(query) => { BucketOperation::Website(query) => {
let bucket = self.get_existing_bucket(&query.bucket).await?; let mut 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"))); 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 { if let BucketState::Present(state) = bucket.state.get_mut() {
let exposed = query.allow; state.website.update(query.allow);
if let BucketState::Present(state) = bucket.state.get_mut() { let msg = if query.allow {
let ak = state.authorized_keys; format!("Website access allowed for {}", &query.bucket)
let old_ak = ak.take_and_clear();
ak.merge(&old_ak.update_mutator(
key_id.to_string(),
PermissionSet {
allow_read,
allow_write,
},
));
} else { } else {
return Err(Error::Message(format!( format!("Website access denied for {}", &query.bucket)
"Bucket is deleted in update_bucket_key" };
)));
}
}
let msg = if bucket.exposed { Ok(AdminRPC::Ok(msg.to_string()))
"Bucket is exposed as a website."
} else { } else {
"Bucket is not exposed." return Err(Error::Message(format!(
quentin marked this conversation as resolved
Review

Probably put unreachable!() in else branch ? Because get_existing_bucket does not return a bucket that is deleted. (I think so, this should be checked)

Probably put `unreachable!()` in else branch ? Because get_existing_bucket does not return a bucket that is deleted. (I think so, this should be checked)
Review

Checked.
Indeed, it does not return deleted buckets.

        async fn get_existing_bucket(&self, bucket: &String) -> Result<Bucket, Error> {
                self.garage
                        .bucket_table
                        .get(&EmptyKey, bucket)
                        .await?
                        .filter(|b| !b.is_deleted())
                        .map(Ok)
                        .unwrap_or(Err(Error::BadRPC(format!(
                                "Bucket {} does not exist",
                                bucket
                        ))))
        }
Checked. Indeed, it does not return deleted buckets. ```rust async fn get_existing_bucket(&self, bucket: &String) -> Result<Bucket, Error> { self.garage .bucket_table .get(&EmptyKey, bucket) .await? .filter(|b| !b.is_deleted()) .map(Ok) .unwrap_or(Err(Error::BadRPC(format!( "Bucket {} does not exist", bucket )))) } ```
};*/ "Bucket is deleted in update_bucket_key"
)));
quentin marked this conversation as resolved
Review

update_bucket_key ?

`update_bucket_key` ?
Ok(AdminRPC::Ok(/*msg*/"".to_string())) }
} }
} }
} }
@ -270,7 +261,7 @@ impl AdminRpcHandler {
.unwrap_or(Err(Error::BadRPC(format!("Key {} does not exist", id)))) .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( async fn update_bucket_key(
&self, &self,
mut bucket: Bucket, mut bucket: Bucket,

View file

@ -45,7 +45,7 @@ impl CRDT for BucketState {
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] #[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
pub struct BucketParams { pub struct BucketParams {
pub authorized_keys: crdt::LWWMap<String, PermissionSet>, pub authorized_keys: crdt::LWWMap<String, PermissionSet>,
pub website: crdt::LWW<bool> pub website: crdt::LWW<bool>,
} }
impl CRDT for BucketParams { impl CRDT for BucketParams {
@ -59,7 +59,7 @@ impl BucketParams {
pub fn new() -> Self { pub fn new() -> Self {
BucketParams { BucketParams {
authorized_keys: crdt::LWWMap::new(), 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 { let params = BucketParams {
authorized_keys: keys, authorized_keys: keys,
website: crdt::LWW::new(false) website: crdt::LWW::new(false),
}; };
Some(Bucket { Some(Bucket {