aboutsummaryrefslogtreecommitdiff
path: root/src/api/admin
diff options
context:
space:
mode:
authorAlex Auvolat <lx@deuxfleurs.fr>2025-01-30 17:45:54 +0100
committerAlex Auvolat <lx@deuxfleurs.fr>2025-02-03 18:54:51 +0100
commitbdaf55ab3f866234bd5a7d585758265a88d2906a (patch)
treee5160b9cc4ca312c6c649989b80d4ba7e6490559 /src/api/admin
parente96014ca60331b50a5a67383589ba5b1c74018d0 (diff)
downloadgarage-bdaf55ab3f866234bd5a7d585758265a88d2906a.tar.gz
garage-bdaf55ab3f866234bd5a7d585758265a88d2906a.zip
cli_v2: migrate cleanupincompleteuploads to Admin API
admin api: add CleanupIncompleteUploads spec
Diffstat (limited to 'src/api/admin')
-rw-r--r--src/api/admin/api.rs14
-rw-r--r--src/api/admin/bucket.rs21
-rw-r--r--src/api/admin/router_v2.rs1
3 files changed, 36 insertions, 0 deletions
diff --git a/src/api/admin/api.rs b/src/api/admin/api.rs
index 99832564..44fc9fca 100644
--- a/src/api/admin/api.rs
+++ b/src/api/admin/api.rs
@@ -62,6 +62,7 @@ admin_endpoints![
CreateBucket,
UpdateBucket,
DeleteBucket,
+ CleanupIncompleteUploads,
// Operations on permissions for keys on buckets
AllowBucketKey,
@@ -497,6 +498,19 @@ pub struct DeleteBucketRequest {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeleteBucketResponse;
+// ---- CleanupIncompleteUploads ----
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct CleanupIncompleteUploadsRequest {
+ pub bucket_id: String,
+ pub older_than_secs: u64,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct CleanupIncompleteUploadsResponse {
+ pub uploads_deleted: u64,
+}
+
// **********************************************
// Operations on permissions for keys on buckets
// **********************************************
diff --git a/src/api/admin/bucket.rs b/src/api/admin/bucket.rs
index 123956ca..7b7c09e7 100644
--- a/src/api/admin/bucket.rs
+++ b/src/api/admin/bucket.rs
@@ -1,5 +1,6 @@
use std::collections::HashMap;
use std::sync::Arc;
+use std::time::Duration;
use async_trait::async_trait;
@@ -388,6 +389,26 @@ impl EndpointHandler for UpdateBucketRequest {
}
}
+#[async_trait]
+impl EndpointHandler for CleanupIncompleteUploadsRequest {
+ type Response = CleanupIncompleteUploadsResponse;
+
+ async fn handle(self, garage: &Arc<Garage>) -> Result<CleanupIncompleteUploadsResponse, Error> {
+ let duration = Duration::from_secs(self.older_than_secs);
+
+ let bucket_id = parse_bucket_id(&self.bucket_id)?;
+
+ let count = garage
+ .bucket_helper()
+ .cleanup_incomplete_uploads(&bucket_id, duration)
+ .await?;
+
+ Ok(CleanupIncompleteUploadsResponse {
+ uploads_deleted: count as u64,
+ })
+ }
+}
+
// ---- BUCKET/KEY PERMISSIONS ----
#[async_trait]
diff --git a/src/api/admin/router_v2.rs b/src/api/admin/router_v2.rs
index b36bca34..d1ccceb8 100644
--- a/src/api/admin/router_v2.rs
+++ b/src/api/admin/router_v2.rs
@@ -52,6 +52,7 @@ impl AdminApiRequest {
POST CreateBucket (body),
POST DeleteBucket (query::id),
POST UpdateBucket (body_field, query::id),
+ POST CleanupIncompleteUploads (body),
// Bucket-key permissions
POST AllowBucketKey (body),
POST DenyBucketKey (body),