diff options
author | Alex Auvolat <alex@adnab.me> | 2022-01-06 11:36:17 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-01-13 14:23:52 +0100 |
commit | 3ea8ca1b9e8d0eb09d4d47869da1aca4c8dadade (patch) | |
tree | 7cec4744eebeacc6ed39d12f7fde10cf60e14b50 /src/api | |
parent | f7349f40050dfb5dc4f4f49df5732686c8d846ba (diff) | |
download | garage-3ea8ca1b9e8d0eb09d4d47869da1aca4c8dadade.tar.gz garage-3ea8ca1b9e8d0eb09d4d47869da1aca4c8dadade.zip |
Implement GetBucketWebsite
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/api_server.rs | 1 | ||||
-rw-r--r-- | src/api/s3_website.rs | 73 |
2 files changed, 55 insertions, 19 deletions
diff --git a/src/api/api_server.rs b/src/api/api_server.rs index a38a3c5b..ea1990d9 100644 --- a/src/api/api_server.rs +++ b/src/api/api_server.rs @@ -305,6 +305,7 @@ async fn handler_inner(garage: Arc<Garage>, req: Request<Body>) -> Result<Respon Endpoint::DeleteObjects { .. } => { handle_delete_objects(garage, bucket_id, req, content_sha256).await } + Endpoint::GetBucketWebsite { .. } => handle_get_website(garage, bucket_id).await, Endpoint::PutBucketWebsite { .. } => { handle_put_website(garage, bucket_id, req, content_sha256).await } diff --git a/src/api/s3_website.rs b/src/api/s3_website.rs index 85d7c261..fcf8cba3 100644 --- a/src/api/s3_website.rs +++ b/src/api/s3_website.rs @@ -11,30 +11,66 @@ use crate::signature::verify_signed_content; use garage_model::bucket_table::*; use garage_model::garage::Garage; use garage_table::*; -use garage_util::crdt; use garage_util::data::*; -pub async fn handle_delete_website( +pub async fn handle_get_website( garage: Arc<Garage>, bucket_id: Uuid, ) -> Result<Response<Body>, Error> { - let mut bucket = garage + let bucket = garage .bucket_table .get(&EmptyKey, &bucket_id) .await? .ok_or(Error::NoSuchBucket)?; - if let crdt::Deletable::Present(param) = &mut bucket.state { - param.website_config.update(None); - garage.bucket_table.insert(&bucket).await?; + let param = bucket + .params() + .ok_or_internal_error("Bucket should not be deleted at this point")?; + + if let Some(website) = param.website_config.get() { + let wc = WebsiteConfiguration { + xmlns: (), + error_document: website.error_document.as_ref().map(|v| Key { + key: Value(v.to_string()), + }), + index_document: Some(Suffix { + suffix: Value(website.index_document.to_string()), + }), + redirect_all_requests_to: None, + routing_rules: None, + }; + let xml = quick_xml::se::to_string(&wc)?; + Ok(Response::builder() + .status(StatusCode::OK) + .header(http::header::CONTENT_TYPE, "application/xml") + .body(Body::from(xml))?) } else { - unreachable!(); + Ok(Response::builder() + .status(StatusCode::NO_CONTENT) + .body(Body::empty())?) } +} + +pub async fn handle_delete_website( + garage: Arc<Garage>, + bucket_id: Uuid, +) -> Result<Response<Body>, Error> { + let mut bucket = garage + .bucket_table + .get(&EmptyKey, &bucket_id) + .await? + .ok_or(Error::NoSuchBucket)?; + + let param = bucket + .params_mut() + .ok_or_internal_error("Bucket should not be deleted at this point")?; + + param.website_config.update(None); + garage.bucket_table.insert(&bucket).await?; Ok(Response::builder() .status(StatusCode::NO_CONTENT) - .body(Body::from(vec![])) - .unwrap()) + .body(Body::empty())?) } pub async fn handle_put_website( @@ -52,22 +88,21 @@ pub async fn handle_put_website( .await? .ok_or(Error::NoSuchBucket)?; + let param = bucket + .params_mut() + .ok_or_internal_error("Bucket should not be deleted at this point")?; + let conf: WebsiteConfiguration = from_reader(&body as &[u8])?; conf.validate()?; - if let crdt::Deletable::Present(param) = &mut bucket.state { - param - .website_config - .update(Some(conf.into_garage_website_config()?)); - garage.bucket_table.insert(&bucket).await?; - } else { - unreachable!(); - } + param + .website_config + .update(Some(conf.into_garage_website_config()?)); + garage.bucket_table.insert(&bucket).await?; Ok(Response::builder() .status(StatusCode::OK) - .body(Body::from(vec![])) - .unwrap()) + .body(Body::empty())?) } #[derive(Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)] |