Implement error 409 BucketAlreadyOwnedByYou (#1352)

Fix for Deuxfleurs/garage#1322

Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/1352
Co-authored-by: Roman Ivanov <xatikopro@gmail.com>
Co-committed-by: Roman Ivanov <xatikopro@gmail.com>
This commit is contained in:
Roman Ivanov
2026-02-18 11:20:24 +00:00
committed by Alex
parent 2803c73045
commit ce1ea79bf1
2 changed files with 13 additions and 4 deletions
+5 -3
View File
@@ -198,12 +198,14 @@ pub async fn handle_create_bucket(
.await?;
if let Some(bucket) = existing_bucket {
// Check we have write or owner permission on the bucket,
// in that case it's fine, return 200 OK, bucket exists;
// otherwise return a forbidden error.
// According to https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateBucket.html
// in such case we have to return 409 BucketAlreadyOwnedByYou if request was sent
// by bucket owner and 409 BucketAlreadyExists otherwise.
let kp = api_key.bucket_permissions(&bucket.id);
if !(kp.allow_write || kp.allow_owner) {
return Err(CommonError::BucketAlreadyExists.into());
} else {
return Err(CommonError::BucketAlreadyOwnedByYou.into());
}
} else {
// Check user is allowed to create bucket