* objectDeleteInternal - DELETE an object from a bucket * @param {AuthInfo} authInfo - requester's infos * @param {object} request - request object given by router, * includes normalized headers * @param {Logger} log - werelogs request instance * @param {boolean} isExp
(authInfo, request, log, isExpiration, cb)
| 29 | * @return {undefined} |
| 30 | */ |
| 31 | function objectDeleteInternal(authInfo, request, log, isExpiration, cb) { |
| 32 | log.debug('processing request', { method: 'objectDeleteInternal' }); |
| 33 | if (authInfo.isRequesterPublicUser()) { |
| 34 | log.debug('operation not available for public user'); |
| 35 | monitoring.promMetrics( |
| 36 | 'DELETE', request.bucketName, 403, 'deleteObject'); |
| 37 | return cb(errors.AccessDenied); |
| 38 | } |
| 39 | const bucketName = request.bucketName; |
| 40 | const objectKey = request.objectKey; |
| 41 | |
| 42 | const decodedVidResult = decodeVersionId(request.query); |
| 43 | if (decodedVidResult instanceof Error) { |
| 44 | log.trace('invalid versionId query', { |
| 45 | versionId: request.query.versionId, |
| 46 | error: decodedVidResult, |
| 47 | }); |
| 48 | return cb(decodedVidResult); |
| 49 | } |
| 50 | const reqVersionId = decodedVidResult; |
| 51 | const hasGovernanceBypass = hasGovernanceBypassHeader(request.headers); |
| 52 | |
| 53 | const valParams = { |
| 54 | authInfo, |
| 55 | bucketName, |
| 56 | objectKey, |
| 57 | versionId: reqVersionId, |
| 58 | requestType: request.apiMethods || 'objectDelete', |
| 59 | request, |
| 60 | }; |
| 61 | |
| 62 | const canonicalID = authInfo.getCanonicalID(); |
| 63 | return async.waterfall([ |
| 64 | function validateBucketAndObj(next) { |
| 65 | return standardMetadataValidateBucketAndObj(valParams, request.actionImplicitDenies, log, |
| 66 | (err, bucketMD, objMD) => { |
| 67 | if (err) { |
| 68 | return next(err, bucketMD); |
| 69 | } |
| 70 | |
| 71 | const versioningCfg = bucketMD.getVersioningConfiguration(); |
| 72 | if (!objMD) { |
| 73 | if (!versioningCfg) { |
| 74 | return next(errors.NoSuchKey, bucketMD); |
| 75 | } |
| 76 | // AWS does not return an error when trying to delete a |
| 77 | // specific version that does not exist. We skip to the end |
| 78 | // of the waterfall here. |
| 79 | if (reqVersionId) { |
| 80 | log.debug('trying to delete specific version ' + |
| 81 | ' that does not exist'); |
| 82 | return next(errors.NoSuchVersion, bucketMD); |
| 83 | } |
| 84 | // To adhere to AWS behavior, create a delete marker even |
| 85 | // if trying to delete an object that does not exist when |
| 86 | // versioning has been configured |
| 87 | return next(null, bucketMD, objMD); |
| 88 | } |
no test coverage detected