aboutsummaryrefslogtreecommitdiff
path: root/src/api_server.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/api_server.rs')
-rw-r--r--src/api_server.rs33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/api_server.rs b/src/api_server.rs
index 153991b2..53c3e176 100644
--- a/src/api_server.rs
+++ b/src/api_server.rs
@@ -23,7 +23,7 @@ type BodyType = Box<dyn HttpBody<Data = Bytes, Error = Error> + Send + Unpin>;
pub async fn run_api_server(
garage: Arc<Garage>,
shutdown_signal: impl Future<Output = ()>,
-) -> Result<(), hyper::Error> {
+) -> Result<(), Error> {
let addr = ([0, 0, 0, 0], garage.system.config.api_port).into();
let service = make_service_fn(|conn: &AddrStream| {
@@ -42,7 +42,8 @@ pub async fn run_api_server(
let graceful = server.with_graceful_shutdown(shutdown_signal);
println!("API server listening on http://{}", addr);
- graceful.await
+ graceful.await?;
+ Ok(())
}
async fn handler(
@@ -92,6 +93,13 @@ async fn handler_inner(
version_uuid
)))))
}
+ &Method::DELETE => {
+ let version_uuid = handle_delete(garage, &bucket, &key).await?;
+ Ok(Response::new(Box::new(BytesBody::from(format!(
+ "{:?}\n",
+ version_uuid
+ )))))
+ }
_ => Err(Error::BadRequest(format!("Invalid method"))),
}
}
@@ -257,6 +265,27 @@ impl BodyChunker {
}
}
+async fn handle_delete(garage: Arc<Garage>, bucket: &str, key: &str) -> Result<UUID, Error> {
+ let version_uuid = gen_uuid();
+
+ let mut object = Object {
+ bucket: bucket.into(),
+ key: key.into(),
+ versions: Vec::new(),
+ };
+ object.versions.push(Box::new(ObjectVersion {
+ uuid: version_uuid.clone(),
+ timestamp: now_msec(),
+ mime_type: "application/x-delete-marker".into(),
+ size: 0,
+ is_complete: true,
+ data: ObjectVersionData::DeleteMarker,
+ }));
+
+ garage.object_table.insert(&object).await?;
+ return Ok(version_uuid);
+}
+
async fn handle_get(
garage: Arc<Garage>,
bucket: &str,