MCPcopy
hub / github.com/scality/cloudserver / bucketPutReplication

Function bucketPutReplication

lib/api/bucketPutReplication.js:27–88  ·  view source on GitHub ↗

* bucketPutReplication - Create or update bucket replication 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)

Source from the content-addressed store, hash-verified

25 * @return {undefined}
26 */
27function bucketPutReplication(authInfo, request, log, callback) {
28 log.debug('processing request', { method: 'bucketPutReplication' });
29 const { bucketName, post, headers, method } = request;
30 const metadataValParams = {
31 authInfo,
32 bucketName,
33 requestType: request.apiMethods || 'bucketPutReplication',
34 request,
35 };
36
37 return waterfall([
38 // Validate the request XML and return the replication configuration.
39 next => getReplicationConfiguration(post, log, next),
40 // Check bucket user privileges and ensure versioning is 'Enabled'.
41 (config, next) =>
42 // TODO: Validate that destination bucket exists and has versioning.
43 standardMetadataValidateBucket(metadataValParams, request.actionImplicitDenies, log, (err, bucket) => {
44 if (err) {
45 return next(err);
46 }
47 // Replication requires that versioning is 'Enabled' unless it
48 // is an NFS bucket.
49 if (!bucket.isNFS() && !bucket.isVersioningEnabled(bucket)) {
50 return next(versioningNotEnabledError);
51 }
52 return next(null, config, bucket);
53 }),
54 // Set the replication configuration and update the bucket metadata.
55 (config, bucket, next) => {
56 // validate there's a preferred read location in case the
57 // bucket location is a transient source
58 if (!validateConfiguration(config, bucket)) {
59 const msg = 'Replication configuration lacks a preferred ' +
60 'read location';
61 log.error(msg, { bucketName: bucket.getName() });
62 return next(errorInstances.ValidationError
63 .customizeDescription(msg));
64 }
65 bucket.setReplicationConfiguration(config);
66 return metadata.updateBucket(bucket.getName(), bucket, log, err =>
67 next(err, bucket));
68 },
69 ], (err, bucket) => {
70 const corsHeaders = collectCorsHeaders(headers.origin, method, bucket);
71 if (err) {
72 log.trace('error processing request', {
73 error: err,
74 method: 'bucketPutReplication',
75 });
76 monitoring.promMetrics(
77 'PUT', bucketName, err.code, 'putBucketReplication');
78 return callback(err, corsHeaders);
79 }
80 pushMetric('putBucketReplication', log, {
81 authInfo,
82 bucket: bucketName,
83 });
84 monitoring.promMetrics(

Callers 2

Calls 7

collectCorsHeadersFunction · 0.85
pushMetricFunction · 0.85
debugMethod · 0.80
errorMethod · 0.80
traceMethod · 0.80

Tested by

no test coverage detected