mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-08-13 07:46:51 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user