aboutsummaryrefslogtreecommitdiff
path: root/src/api/api_server.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-01-05 15:56:48 +0100
committerAlex Auvolat <alex@adnab.me>2022-01-05 15:56:48 +0100
commit8395030e4891ae48ca30428318e8d435c157f74f (patch)
treeecbaac13a70971eb6b2d11df65bdb5f28f441484 /src/api/api_server.rs
parent9431090b1eb9006b12395fb22700b0def7fd1f59 (diff)
downloadgarage-8395030e4891ae48ca30428318e8d435c157f74f.tar.gz
garage-8395030e4891ae48ca30428318e8d435c157f74f.zip
Implement CreateBucket
Diffstat (limited to 'src/api/api_server.rs')
-rw-r--r--src/api/api_server.rs21
1 files changed, 7 insertions, 14 deletions
diff --git a/src/api/api_server.rs b/src/api/api_server.rs
index f5ebed37..db5da8cc 100644
--- a/src/api/api_server.rs
+++ b/src/api/api_server.rs
@@ -108,6 +108,11 @@ async fn handler_inner(garage: Arc<Garage>, req: Request<Body>) -> Result<Respon
let endpoint = Endpoint::from_request(&req, bucket.map(ToOwned::to_owned))?;
+ // Special code path for CreateBucket API endpoint
+ if let Endpoint::CreateBucket { bucket } = endpoint {
+ return handle_create_bucket(&garage, req, content_sha256, api_key, bucket).await;
+ }
+
let bucket_name = match endpoint.get_bucket() {
None => return handle_request_without_bucket(garage, req, api_key, endpoint).await,
Some(bucket) => bucket.to_string(),
@@ -188,19 +193,7 @@ async fn handler_inner(garage: Arc<Garage>, req: Request<Body>) -> Result<Respon
)
.await
}
- Endpoint::CreateBucket { bucket } => {
- debug!(
- "Body: {}",
- std::str::from_utf8(&hyper::body::to_bytes(req.into_body()).await?)
- .unwrap_or("<invalid utf8>")
- );
- let empty_body: Body = Body::from(vec![]);
- let response = Response::builder()
- .header("Location", format!("/{}", bucket))
- .body(empty_body)
- .unwrap();
- Ok(response)
- }
+ Endpoint::CreateBucket { .. } => unreachable!(),
Endpoint::HeadBucket { .. } => {
let empty_body: Body = Body::from(vec![]);
let response = Response::builder().body(empty_body).unwrap();
@@ -303,7 +296,7 @@ async fn resolve_bucket(
let api_key_params = api_key
.state
.as_option()
- .ok_or_else(|| Error::Forbidden("Operation is not allowed for this key.".to_string()))?;
+ .ok_or_internal_error("Key should not be deleted at this point")?;
if let Some(Some(bucket_id)) = api_key_params.local_aliases.get(bucket_name) {
Ok(*bucket_id)