aboutsummaryrefslogtreecommitdiff
path: root/src/garage/admin.rs
diff options
context:
space:
mode:
authorAlex <alex@adnab.me>2022-11-04 15:51:16 +0000
committerAlex <alex@adnab.me>2022-11-04 15:51:16 +0000
commit0d279918b7681d9d71cde85c90d1da75026fd7bf (patch)
treeb96e5830c8a40d25988e0e496a52eba4c71454c5 /src/garage/admin.rs
parent043246c575d1ae85c7f375ef577b8fef6940a6d5 (diff)
parente03d9062f7f21dd0493dd82a7dcf82f2cd035943 (diff)
downloadgarage-0d279918b7681d9d71cde85c90d1da75026fd7bf.tar.gz
garage-0d279918b7681d9d71cde85c90d1da75026fd7bf.zip
Merge pull request 'Improvements to CLI' (#410) from cleanup-uploads-command into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/410
Diffstat (limited to 'src/garage/admin.rs')
-rw-r--r--src/garage/admin.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/garage/admin.rs b/src/garage/admin.rs
index 802a8261..e973cfe7 100644
--- a/src/garage/admin.rs
+++ b/src/garage/admin.rs
@@ -85,6 +85,9 @@ impl AdminRpcHandler {
BucketOperation::Deny(query) => self.handle_bucket_deny(query).await,
BucketOperation::Website(query) => self.handle_bucket_website(query).await,
BucketOperation::SetQuotas(query) => self.handle_bucket_set_quotas(query).await,
+ BucketOperation::CleanupIncompleteUploads(query) => {
+ self.handle_bucket_cleanup_incomplete_uploads(query).await
+ }
}
}
@@ -512,6 +515,42 @@ impl AdminRpcHandler {
)))
}
+ async fn handle_bucket_cleanup_incomplete_uploads(
+ &self,
+ query: &CleanupIncompleteUploadsOpt,
+ ) -> Result<AdminRpc, Error> {
+ let mut bucket_ids = vec![];
+ for b in query.buckets.iter() {
+ bucket_ids.push(
+ self.garage
+ .bucket_helper()
+ .resolve_global_bucket_name(b)
+ .await?
+ .ok_or_bad_request(format!("Bucket not found: {}", b))?,
+ );
+ }
+
+ let duration = parse_duration::parse::parse(&query.older_than)
+ .ok_or_bad_request("Invalid duration passed for --older-than parameter")?;
+
+ let mut ret = String::new();
+ for bucket in bucket_ids {
+ let count = self
+ .garage
+ .bucket_helper()
+ .cleanup_incomplete_uploads(&bucket, duration)
+ .await?;
+ writeln!(
+ &mut ret,
+ "Bucket {:?}: {} incomplete uploads aborted",
+ bucket, count
+ )
+ .unwrap();
+ }
+
+ Ok(AdminRpc::Ok(ret))
+ }
+
async fn handle_key_cmd(&self, cmd: &KeyOperation) -> Result<AdminRpc, Error> {
match cmd {
KeyOperation::List => self.handle_list_keys().await,