* bucketPutPolicy - create or update a bucket policy * @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 * @return {undefined}
(authInfo, request, log, callback)
| 29 | * @return {undefined} |
| 30 | */ |
| 31 | function bucketPutPolicy(authInfo, request, log, callback) { |
| 32 | log.debug('processing request', { method: 'bucketPutPolicy' }); |
| 33 | |
| 34 | const { bucketName } = request; |
| 35 | const metadataValParams = { |
| 36 | authInfo, |
| 37 | bucketName, |
| 38 | requestType: request.apiMethods || 'bucketPutPolicy', |
| 39 | request, |
| 40 | }; |
| 41 | |
| 42 | return async.waterfall([ |
| 43 | next => { |
| 44 | const bucketPolicy = new BucketPolicy(request.post); |
| 45 | // if there was an error getting bucket policy, |
| 46 | // returned policyObj will contain 'error' key |
| 47 | process.nextTick(() => { |
| 48 | const policyObj = bucketPolicy.getBucketPolicy(); |
| 49 | if (_checkNotImplementedPolicy(request.post)) { |
| 50 | const err = errorInstances.NotImplemented.customizeDescription( |
| 51 | 'Bucket policy contains element not yet implemented'); |
| 52 | return next(err); |
| 53 | } |
| 54 | if (policyObj.error) { |
| 55 | const err = errorInstances.MalformedPolicy.customizeDescription( |
| 56 | policyObj.error.description); |
| 57 | return next(err); |
| 58 | } |
| 59 | return next(null, policyObj); |
| 60 | }); |
| 61 | }, |
| 62 | (bucketPolicy, next) => { |
| 63 | process.nextTick(() => { |
| 64 | if (!validatePolicyResource(bucketName, bucketPolicy)) { |
| 65 | return next(errorInstances.MalformedPolicy.customizeDescription( |
| 66 | 'Policy has invalid resource')); |
| 67 | } |
| 68 | return next(validatePolicyConditions(bucketPolicy), bucketPolicy); |
| 69 | }); |
| 70 | }, |
| 71 | (bucketPolicy, next) => standardMetadataValidateBucket(metadataValParams, request.actionImplicitDenies, log, |
| 72 | (err, bucket) => { |
| 73 | if (err) { |
| 74 | return next(err, bucket); |
| 75 | } |
| 76 | return next(null, bucket, bucketPolicy); |
| 77 | }), |
| 78 | (bucket, bucketPolicy, next) => { |
| 79 | bucket.setBucketPolicy(bucketPolicy); |
| 80 | metadata.updateBucket(bucket.getName(), bucket, log, |
| 81 | err => next(err, bucket)); |
| 82 | }, |
| 83 | ], (err, bucket) => { |
| 84 | const corsHeaders = collectCorsHeaders(request.headers.origin, |
| 85 | request.method, bucket); |
| 86 | if (err) { |
| 87 | log.trace('error processing request', |
| 88 | { error: err, method: 'bucketPutPolicy' }); |
no test coverage detected