* Checks whether to proceed with a request based on the bucket flags * and sends a request to invisibly delete the bucket if applicable * @param {object} bucket - bucket metadata * @param {string} requestType - type of api request * @return {boolean} true if the bucket should be shielded, false
(bucket, requestType)
| 9 | * @return {boolean} true if the bucket should be shielded, false otherwise |
| 10 | */ |
| 11 | function bucketShield(bucket, requestType) { |
| 12 | const invisiblyDeleteRequests = constants.bucketOwnerActions.concat( |
| 13 | [ |
| 14 | 'bucketGet', |
| 15 | 'bucketHead', |
| 16 | 'bucketGetACL', |
| 17 | 'objectGet', |
| 18 | 'objectGetACL', |
| 19 | 'objectHead', |
| 20 | 'objectPutACL', |
| 21 | 'objectDelete', |
| 22 | ]); |
| 23 | if (invisiblyDeleteRequests.indexOf(requestType) > -1 && |
| 24 | bucket.hasDeletedFlag()) { |
| 25 | invisiblyDelete(bucket.getName(), bucket.getOwner()); |
| 26 | return true; |
| 27 | } |
| 28 | // If request is initiateMultipartUpload (requestType objectPut), |
| 29 | // objectPut, bucketPutACL or bucketDelete, proceed with request. |
| 30 | // Otherwise return an error to the client |
| 31 | if ((bucket.hasDeletedFlag() || bucket.hasTransientFlag()) && |
| 32 | (requestType !== 'objectPut' && |
| 33 | requestType !== 'initiateMultipartUpload' && |
| 34 | requestType !== 'objectPutPart' && |
| 35 | requestType !== 'completeMultipartUpload' && |
| 36 | requestType !== 'bucketPutACL' && |
| 37 | requestType !== 'bucketDelete')) { |
| 38 | return true; |
| 39 | } |
| 40 | return false; |
| 41 | } |
| 42 | |
| 43 | module.exports = bucketShield; |
no test coverage detected