From e92c52eb6522a140cdced40bc047149dc638bfa4 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 17 May 2022 17:02:38 +0200 Subject: [PATCH] refactor --- src/api/admin/bucket.rs | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/src/api/admin/bucket.rs b/src/api/admin/bucket.rs index 2c21edee..2124f2c2 100644 --- a/src/api/admin/bucket.rs +++ b/src/api/admin/bucket.rs @@ -103,18 +103,18 @@ pub async fn handle_get_bucket_info( } }; + bucket_info_results(garage, bucket_id).await +} + +async fn bucket_info_results( + garage: &Arc, + bucket_id: Uuid, +) -> Result, Error> { let bucket = garage .bucket_helper() .get_existing_bucket(bucket_id) .await?; - bucket_info_results(garage, bucket).await -} - -async fn bucket_info_results( - garage: &Arc, - bucket: Bucket, -) -> Result, Error> { let mut relevant_keys = HashMap::new(); for (k, _) in bucket .state @@ -299,12 +299,7 @@ pub async fn handle_create_bucket( } } - let bucket = garage - .bucket_table - .get(&EmptyKey, &bucket.id) - .await? - .ok_or_internal_error("Bucket should now exist but doesn't")?; - bucket_info_results(garage, bucket).await + bucket_info_results(garage, bucket.id).await } #[derive(Deserialize)] @@ -425,12 +420,7 @@ pub async fn handle_bucket_change_key_perm( .set_bucket_key_permissions(bucket.id, &key.key_id, perm) .await?; - let bucket = garage - .bucket_table - .get(&EmptyKey, &bucket.id) - .await? - .ok_or_internal_error("Bucket should now exist but doesn't")?; - bucket_info_results(garage, bucket).await + bucket_info_results(garage, bucket.id).await } #[derive(Deserialize)]