* Bucket Put Object Lock - Create or update bucket object lock configuration * @param {AuthInfo} authInfo - Instance of AuthInfo class with requester's info * @param {object} request - http request object * @param {object} log - Werelogs logger * @param {function} callback - callback to server
(authInfo, request, log, callback)
| 20 | */ |
| 21 | |
| 22 | function bucketPutObjectLock(authInfo, request, log, callback) { |
| 23 | log.debug('processing request', { method: 'bucketPutObjectLock' }); |
| 24 | |
| 25 | const bucketName = request.bucketName; |
| 26 | const metadataValParams = { |
| 27 | authInfo, |
| 28 | bucketName, |
| 29 | requestType: request.apiMethods || 'bucketPutObjectLock', |
| 30 | request, |
| 31 | }; |
| 32 | return waterfall([ |
| 33 | next => parseXML(request.post, log, next), |
| 34 | (parsedXml, next) => { |
| 35 | const lockConfigClass = new ObjectLockConfiguration(parsedXml); |
| 36 | // if there was an error getting object lock configuration, |
| 37 | // returned configObj will contain 'error' key |
| 38 | process.nextTick(() => { |
| 39 | const configObj = lockConfigClass. |
| 40 | getValidatedObjectLockConfiguration(); |
| 41 | return next(configObj.error || null, configObj); |
| 42 | }); |
| 43 | }, |
| 44 | (objectLockConfig, next) => standardMetadataValidateBucket(metadataValParams, request.actionImplicitDenies, |
| 45 | log, (err, bucket) => { |
| 46 | if (err) { |
| 47 | return next(err, bucket); |
| 48 | } |
| 49 | return next(null, bucket, objectLockConfig); |
| 50 | }), |
| 51 | (bucket, objectLockConfig, next) => { |
| 52 | const isObjectLockEnabled = bucket.isObjectLockEnabled(); |
| 53 | process.nextTick(() => { |
| 54 | if (!isObjectLockEnabled) { |
| 55 | return next(errorInstances.InvalidBucketState.customizeDescription( |
| 56 | 'Object Lock configuration cannot be enabled on ' + |
| 57 | 'existing buckets'), bucket); |
| 58 | } |
| 59 | return next(null, bucket, objectLockConfig); |
| 60 | }); |
| 61 | }, |
| 62 | (bucket, objectLockConfig, next) => { |
| 63 | bucket.setObjectLockConfiguration(objectLockConfig); |
| 64 | metadata.updateBucket(bucket.getName(), bucket, log, err => |
| 65 | next(err, bucket)); |
| 66 | }, |
| 67 | ], (err, bucket) => { |
| 68 | const corsHeaders = collectCorsHeaders(request.headers.origin, |
| 69 | request.method, bucket); |
| 70 | if (err) { |
| 71 | log.trace('error processing request', { error: err, |
| 72 | method: 'bucketPutObjectLock' }); |
| 73 | return callback(err, corsHeaders); |
| 74 | } |
| 75 | pushMetric('putBucketObjectLock', log, { |
| 76 | authInfo, |
| 77 | bucket: bucketName, |
| 78 | }); |
| 79 | return callback(null, corsHeaders); |
no test coverage detected