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

Function bucketPutLifecycle

lib/api/bucketPutLifecycle.js:23–80  ·  view source on GitHub ↗

* Bucket Put Lifecycle - Create or update bucket lifecycle 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 * @r

(authInfo, request, log, callback)

Source from the content-addressed store, hash-verified

21 */
22
23function bucketPutLifecycle(authInfo, request, log, callback) {
24 log.debug('processing request', { method: 'bucketPutLifecycle' });
25
26 const { bucketName } = request;
27 const metadataValParams = {
28 authInfo,
29 bucketName,
30 requestType: request.apiMethods || 'bucketPutLifecycle',
31 request,
32 };
33 return waterfall([
34 next => parseXML(request.post, log, next),
35 (parsedXml, next) => {
36 const lcConfigClass =
37 new LifecycleConfiguration(parsedXml, config);
38 // if there was an error getting lifecycle configuration,
39 // returned configObj will contain 'error' key
40 process.nextTick(() => {
41 const configObj = lcConfigClass.getLifecycleConfiguration();
42 if (configObj.error) {
43 return next(configObj.error);
44 }
45 return next(null, configObj);
46 });
47 },
48 (lcConfig, next) => standardMetadataValidateBucket(metadataValParams, request.actionImplicitDenies, log,
49 (err, bucket) => {
50 if (err) {
51 return next(err, bucket);
52 }
53 return next(null, bucket, lcConfig);
54 }),
55 (bucket, lcConfig, next) => {
56 if (!bucket.getUid()) {
57 bucket.setUid(uuid());
58 }
59 bucket.setLifecycleConfiguration(lcConfig);
60 metadata.updateBucket(bucket.getName(), bucket, log, err =>
61 next(err, bucket));
62 },
63 ], (err, bucket) => {
64 const corsHeaders = collectCorsHeaders(request.headers.origin,
65 request.method, bucket);
66 if (err) {
67 log.trace('error processing request', { error: err,
68 method: 'bucketPutLifecycle' });
69 monitoring.promMetrics(
70 'PUT', bucketName, err.code, 'putBucketLifecycle');
71 return callback(err, corsHeaders);
72 }
73 pushMetric('putBucketLifecycle', log, {
74 authInfo,
75 bucket: bucketName,
76 });
77 monitoring.promMetrics('PUT', bucketName, '200', 'putBucketLifecycle');
78 return callback(null, corsHeaders);
79 });
80}

Callers 3

Calls 6

parseXMLFunction · 0.85
collectCorsHeadersFunction · 0.85
pushMetricFunction · 0.85
debugMethod · 0.80
traceMethod · 0.80

Tested by

no test coverage detected