mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-08-24 11:36:31 +00:00
New model for buckets
This commit is contained in:
+18
-9
@@ -7,9 +7,10 @@ use serde::{Deserialize, Serialize};
|
||||
use crate::error::*;
|
||||
use crate::s3_xml::{xmlns_tag, IntValue, Value};
|
||||
use crate::signature::verify_signed_content;
|
||||
use garage_model::bucket_table::BucketState;
|
||||
|
||||
use garage_model::garage::Garage;
|
||||
use garage_table::*;
|
||||
use garage_util::crdt;
|
||||
use garage_util::data::Hash;
|
||||
|
||||
pub async fn handle_delete_website(
|
||||
@@ -17,14 +18,18 @@ pub async fn handle_delete_website(
|
||||
bucket: String,
|
||||
) -> Result<Response<Body>, Error> {
|
||||
let mut bucket = garage
|
||||
.bucket_table
|
||||
.bucket_alias_table
|
||||
.get(&EmptyKey, &bucket)
|
||||
.await?
|
||||
.ok_or(Error::NotFound)?;
|
||||
|
||||
if let BucketState::Present(state) = bucket.state.get_mut() {
|
||||
state.website.update(false);
|
||||
garage.bucket_table.insert(&bucket).await?;
|
||||
if let crdt::Deletable::Present(state) = bucket.state.get_mut() {
|
||||
let mut new_param = state.clone();
|
||||
new_param.website_access = false;
|
||||
bucket.state.update(crdt::Deletable::present(new_param));
|
||||
garage.bucket_alias_table.insert(&bucket).await?;
|
||||
} else {
|
||||
unreachable!();
|
||||
}
|
||||
|
||||
Ok(Response::builder()
|
||||
@@ -43,7 +48,7 @@ pub async fn handle_put_website(
|
||||
verify_signed_content(content_sha256, &body[..])?;
|
||||
|
||||
let mut bucket = garage
|
||||
.bucket_table
|
||||
.bucket_alias_table
|
||||
.get(&EmptyKey, &bucket)
|
||||
.await?
|
||||
.ok_or(Error::NotFound)?;
|
||||
@@ -51,9 +56,13 @@ pub async fn handle_put_website(
|
||||
let conf: WebsiteConfiguration = from_reader(&body as &[u8])?;
|
||||
conf.validate()?;
|
||||
|
||||
if let BucketState::Present(state) = bucket.state.get_mut() {
|
||||
state.website.update(true);
|
||||
garage.bucket_table.insert(&bucket).await?;
|
||||
if let crdt::Deletable::Present(state) = bucket.state.get() {
|
||||
let mut new_param = state.clone();
|
||||
new_param.website_access = true;
|
||||
bucket.state.update(crdt::Deletable::present(new_param));
|
||||
garage.bucket_alias_table.insert(&bucket).await?;
|
||||
} else {
|
||||
unreachable!();
|
||||
}
|
||||
|
||||
Ok(Response::builder()
|
||||
|
||||
Reference in New Issue
Block a user