aboutsummaryrefslogtreecommitdiff
path: root/src/web
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2021-12-14 13:55:11 +0100
committerAlex Auvolat <alex@adnab.me>2022-01-04 12:45:46 +0100
commit5b1117e582db16cc5aa50840a685875cbd5501f4 (patch)
tree06fec47bf56cb08cb51334454dc15f98352c98f2 /src/web
parent8f6026de5ecd44cbe0fc0bcd47638a1ece860439 (diff)
downloadgarage-5b1117e582db16cc5aa50840a685875cbd5501f4.tar.gz
garage-5b1117e582db16cc5aa50840a685875cbd5501f4.zip
New model for buckets
Diffstat (limited to 'src/web')
-rw-r--r--src/web/Cargo.toml10
-rw-r--r--src/web/web_server.rs33
2 files changed, 25 insertions, 18 deletions
diff --git a/src/web/Cargo.toml b/src/web/Cargo.toml
index 72701c90..54211f5d 100644
--- a/src/web/Cargo.toml
+++ b/src/web/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "garage_web"
-version = "0.5.0"
+version = "0.6.0"
authors = ["Alex Auvolat <alex@adnab.me>", "Quentin Dufour <quentin@dufour.io>"]
edition = "2018"
license = "AGPL-3.0"
@@ -14,10 +14,10 @@ path = "lib.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-garage_api = { version = "0.5.0", path = "../api" }
-garage_model = { version = "0.5.0", path = "../model" }
-garage_util = { version = "0.5.0", path = "../util" }
-garage_table = { version = "0.5.0", path = "../table" }
+garage_api = { version = "0.6.0", path = "../api" }
+garage_model = { version = "0.6.0", path = "../model" }
+garage_util = { version = "0.6.0", path = "../util" }
+garage_table = { version = "0.6.0", path = "../table" }
err-derive = "0.3"
log = "0.4"
diff --git a/src/web/web_server.rs b/src/web/web_server.rs
index 4a603c05..5eb25e93 100644
--- a/src/web/web_server.rs
+++ b/src/web/web_server.rs
@@ -12,7 +12,6 @@ use hyper::{
use crate::error::*;
use garage_api::helpers::{authority_to_host, host_to_bucket};
use garage_api::s3_get::{handle_get, handle_head};
-use garage_model::bucket_table::*;
use garage_model::garage::Garage;
use garage_table::*;
use garage_util::error::Error as GarageError;
@@ -77,31 +76,39 @@ async fn serve_file(garage: Arc<Garage>, req: Request<Body>) -> Result<Response<
// Get bucket
let host = authority_to_host(authority)?;
let root = &garage.config.s3_web.root_domain;
- let bucket = host_to_bucket(&host, root).unwrap_or(&host);
- // Check bucket is exposed as a website
- let bucket_desc = garage
+ let bucket_name = host_to_bucket(&host, root).unwrap_or(&host);
+ let bucket_id = garage
+ .bucket_alias_table
+ .get(&EmptyKey, &bucket_name.to_string())
+ .await?
+ .map(|x| x.state.take().into_option())
+ .flatten()
+ .filter(|param| param.website_access)
+ .map(|param| param.bucket_id)
+ .ok_or(Error::NotFound)?;
+
+ // Sanity check: check bucket isn't deleted
+ garage
.bucket_table
- .get(&EmptyKey, &bucket.to_string())
+ .get(&bucket_id, &EmptyKey)
.await?
.filter(|b| !b.is_deleted())
.ok_or(Error::NotFound)?;
- match bucket_desc.state.get() {
- BucketState::Present(params) if *params.website.get() => Ok(()),
- _ => Err(Error::NotFound),
- }?;
-
// Get path
let path = req.uri().path().to_string();
let index = &garage.config.s3_web.index;
let key = path_to_key(&path, index)?;
- info!("Selected bucket: \"{}\", selected key: \"{}\"", bucket, key);
+ info!(
+ "Selected bucket: \"{}\" {:?}, selected key: \"{}\"",
+ bucket_name, bucket_id, key
+ );
let res = match *req.method() {
- Method::HEAD => handle_head(garage, &req, bucket, &key).await?,
- Method::GET => handle_get(garage, &req, bucket, &key).await?,
+ Method::HEAD => handle_head(garage, &req, bucket_id, &key).await?,
+ Method::GET => handle_get(garage, &req, bucket_id, &key).await?,
_ => return Err(Error::BadRequest("HTTP method not supported".to_string())),
};