* POST Object restore process * * @param {MetadataWrapper} metadata - metadata wrapper * @param {object} mdUtils - utility object to treat metadata * @param {AuthInfo} userInfo - Instance of AuthInfo class with requester's info * @param {IncomingMessage} request - request info * @param {object
(metadata, mdUtils, userInfo, request, log, callback)
| 34 | * @return {undefined} |
| 35 | */ |
| 36 | function objectRestore(metadata, mdUtils, userInfo, request, log, callback) { |
| 37 | const METHOD = 'objectRestore'; |
| 38 | |
| 39 | const { bucketName, objectKey } = request; |
| 40 | |
| 41 | log.debug('processing request', { method: METHOD }); |
| 42 | |
| 43 | const decodedVidResult = decodeVersionId(request.query); |
| 44 | if (decodedVidResult instanceof Error) { |
| 45 | log.trace('invalid versionId query', |
| 46 | { |
| 47 | method: METHOD, |
| 48 | versionId: request.query.versionId, |
| 49 | error: decodedVidResult, |
| 50 | }); |
| 51 | return process.nextTick(() => callback(decodedVidResult)); |
| 52 | } |
| 53 | |
| 54 | let isObjectRestored = false; |
| 55 | |
| 56 | const mdValueParams = { |
| 57 | authInfo: userInfo, |
| 58 | bucketName, |
| 59 | objectKey, |
| 60 | versionId: decodedVidResult, |
| 61 | requestType: request.apiMethods || 'restoreObject', |
| 62 | /** |
| 63 | * Restoring an object might not cause any impact on |
| 64 | * the storage, if the object is already restored: in |
| 65 | * this case, the duration is extended. We disable the |
| 66 | * quota evaluation and trigger it manually. |
| 67 | */ |
| 68 | checkQuota: false, |
| 69 | request, |
| 70 | }; |
| 71 | |
| 72 | return async.waterfall([ |
| 73 | // get metadata of bucket and object |
| 74 | function validateBucketAndObject(next) { |
| 75 | return mdUtils.standardMetadataValidateBucketAndObj(mdValueParams, request.actionImplicitDenies, |
| 76 | log, (err, bucketMD, objectMD) => { |
| 77 | if (err) { |
| 78 | log.trace('request authorization failed', { method: METHOD, error: err }); |
| 79 | return next(err); |
| 80 | } |
| 81 | // Call back error if object metadata could not be obtained |
| 82 | if (!objectMD) { |
| 83 | const err = decodedVidResult ? errors.NoSuchVersion : errors.NoSuchKey; |
| 84 | log.trace('error no object metadata found', { method: METHOD, error: err }); |
| 85 | return next(err, bucketMD); |
| 86 | } |
| 87 | // If object metadata is delete marker, |
| 88 | // call back NoSuchKey or MethodNotAllowed depending on specifying versionId |
| 89 | if (objectMD.isDeleteMarker) { |
| 90 | let err = errorInstances.NoSuchKey; |
| 91 | if (decodedVidResult) { |
| 92 | err = errorInstances.MethodNotAllowed; |
| 93 | } |
nothing calls this directly
no test coverage detected