* Bucket Put Notification - Create or update bucket notification 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)
| 17 | */ |
| 18 | |
| 19 | function bucketPutNotification(authInfo, request, log, callback) { |
| 20 | log.debug('processing request', { method: 'bucketPutNotification' }); |
| 21 | |
| 22 | const { bucketName } = request; |
| 23 | const metadataValParams = { |
| 24 | authInfo, |
| 25 | bucketName, |
| 26 | requestType: request.apiMethods || 'bucketPutNotification', |
| 27 | request, |
| 28 | }; |
| 29 | |
| 30 | return async.waterfall([ |
| 31 | next => parseXML(request.post, log, next), |
| 32 | (parsedXml, next) => { |
| 33 | const notificationConfig = getNotificationConfiguration(parsedXml); |
| 34 | const notifConfig = notificationConfig.error ? undefined : notificationConfig; |
| 35 | process.nextTick(() => next(notificationConfig.error, notifConfig)); |
| 36 | }, |
| 37 | (notifConfig, next) => standardMetadataValidateBucket(metadataValParams, request.actionImplicitDenies, log, |
| 38 | (err, bucket) => next(err, bucket, notifConfig)), |
| 39 | (bucket, notifConfig, next) => { |
| 40 | bucket.setNotificationConfiguration(notifConfig); |
| 41 | metadata.updateBucket(bucket.getName(), bucket, log, |
| 42 | err => next(err, bucket)); |
| 43 | }, |
| 44 | ], (err, bucket) => { |
| 45 | const corsHeaders = collectCorsHeaders(request.headers.origin, |
| 46 | request.method, bucket); |
| 47 | if (err) { |
| 48 | log.trace('error processing request', { error: err, |
| 49 | method: 'bucketPutNotification' }); |
| 50 | return callback(err, corsHeaders); |
| 51 | } |
| 52 | pushMetric('putBucketNotification', log, { |
| 53 | authInfo, |
| 54 | bucket: bucketName, |
| 55 | }); |
| 56 | return callback(null, corsHeaders); |
| 57 | }); |
| 58 | } |
| 59 | |
| 60 | module.exports = bucketPutNotification; |
no test coverage detected