aboutsummaryrefslogtreecommitdiff
path: root/src/api/admin
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/admin')
-rw-r--r--src/api/admin/bucket.rs4
-rw-r--r--src/api/admin/cluster.rs2
-rw-r--r--src/api/admin/error.rs5
-rw-r--r--src/api/admin/key.rs2
-rw-r--r--src/api/admin/mod.rs11
5 files changed, 4 insertions, 20 deletions
diff --git a/src/api/admin/bucket.rs b/src/api/admin/bucket.rs
index db1fda0f..b226c015 100644
--- a/src/api/admin/bucket.rs
+++ b/src/api/admin/bucket.rs
@@ -18,7 +18,7 @@ use garage_model::s3::object_table::ObjectFilter;
use crate::admin::error::*;
use crate::admin::key::ApiBucketKeyPerm;
-use crate::admin::parse_json_body;
+use crate::helpers::parse_json_body;
pub async fn handle_list_buckets(garage: &Arc<Garage>) -> Result<Response<Body>, Error> {
let buckets = garage
@@ -333,7 +333,7 @@ pub async fn handle_delete_bucket(
)
.await?;
if !objects.is_empty() {
- return Err(Error::bad_request("Bucket is not empty"));
+ return Err(Error::BucketNotEmpty);
}
// --- done checking, now commit ---
diff --git a/src/api/admin/cluster.rs b/src/api/admin/cluster.rs
index db4d968d..91d99d8a 100644
--- a/src/api/admin/cluster.rs
+++ b/src/api/admin/cluster.rs
@@ -14,7 +14,7 @@ use garage_rpc::layout::*;
use garage_model::garage::Garage;
use crate::admin::error::*;
-use crate::admin::parse_json_body;
+use crate::helpers::parse_json_body;
pub async fn handle_get_cluster_status(garage: &Arc<Garage>) -> Result<Response<Body>, Error> {
let res = GetClusterStatusResponse {
diff --git a/src/api/admin/error.rs b/src/api/admin/error.rs
index 1f49fed5..1d68dc69 100644
--- a/src/api/admin/error.rs
+++ b/src/api/admin/error.rs
@@ -40,10 +40,6 @@ pub enum Error {
/// Bucket name is not valid according to AWS S3 specs
#[error(display = "Invalid bucket name")]
InvalidBucketName,
-
- /// The client sent a request for an action not supported by garage
- #[error(display = "Unimplemented action: {}", _0)]
- NotImplemented(String),
}
impl<T> From<T> for Error
@@ -75,7 +71,6 @@ impl ApiError for Error {
Error::NoSuchAccessKey | Error::NoSuchBucket => StatusCode::NOT_FOUND,
Error::BucketNotEmpty | Error::BucketAlreadyExists => StatusCode::CONFLICT,
Error::Forbidden(_) => StatusCode::FORBIDDEN,
- Error::NotImplemented(_) => StatusCode::NOT_IMPLEMENTED,
Error::InvalidBucketName => StatusCode::BAD_REQUEST,
}
}
diff --git a/src/api/admin/key.rs b/src/api/admin/key.rs
index e5f25601..8060bf1a 100644
--- a/src/api/admin/key.rs
+++ b/src/api/admin/key.rs
@@ -12,7 +12,7 @@ use garage_model::garage::Garage;
use garage_model::key_table::*;
use crate::admin::error::*;
-use crate::admin::parse_json_body;
+use crate::helpers::parse_json_body;
pub async fn handle_list_keys(garage: &Arc<Garage>) -> Result<Response<Body>, Error> {
let res = garage
diff --git a/src/api/admin/mod.rs b/src/api/admin/mod.rs
index 73700e6e..c4857c10 100644
--- a/src/api/admin/mod.rs
+++ b/src/api/admin/mod.rs
@@ -5,14 +5,3 @@ mod router;
mod bucket;
mod cluster;
mod key;
-
-use hyper::{Body, Request};
-use serde::Deserialize;
-
-use error::*;
-
-pub async fn parse_json_body<T: for<'de> Deserialize<'de>>(req: Request<Body>) -> Result<T, Error> {
- let body = hyper::body::to_bytes(req.into_body()).await?;
- let resp: T = serde_json::from_slice(&body).ok_or_bad_request("Invalid JSON")?;
- Ok(resp)
-}