MCPcopy Index your code
hub / github.com/scality/cloudserver / bucketPutWebsite

Function bucketPutWebsite

lib/api/bucketPutWebsite.js:22–73  ·  view source on GitHub ↗

* Bucket Put Website - Create bucket website 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 * @return {undefin

(authInfo, request, log, callback)

Source from the content-addressed store, hash-verified

20 * @return {undefined}
21 */
22function bucketPutWebsite(authInfo, request, log, callback) {
23 log.debug('processing request', { method: REQUEST_TYPE });
24 const bucketName = request.bucketName;
25 const metadataValParams = {
26 authInfo,
27 bucketName,
28 requestType: request.apiMethod || REQUEST_TYPE,
29 request,
30 };
31
32 if (!request.post) {
33 monitoring.promMetrics('PUT', bucketName, 400, METRICS_ACTION);
34 return callback(errors.MissingRequestBodyError);
35 }
36
37 return async.waterfall([
38 next => {
39 log.trace('parsing website configuration');
40 return parseWebsiteConfigXml(request.post, log, next);
41 },
42 (config, next) => standardMetadataValidateBucket(metadataValParams, request.actionImplicitDenies, log,
43 (err, bucket) => {
44 const corsHeaders = collectCorsHeaders(request.headers.origin, request.method, bucket);
45 if (err) {
46 monitoring.promMetrics('PUT', bucketName, err.code, METRICS_ACTION);
47 if (err?.is?.AccessDenied) {
48 return next(err, corsHeaders);
49 }
50 return next(err);
51 }
52
53 return next(null, bucket, config, corsHeaders);
54 }),
55 (bucket, config, corsHeaders, next) => {
56 log.trace('updating bucket website configuration in metadata');
57 bucket.setWebsiteConfiguration(config);
58 return metadata.updateBucket(bucketName, bucket, log, err => {
59 next(err, corsHeaders);
60 });
61 }
62 ], (err, corsHeaders) => {
63 if (err) {
64 log.trace('error processing request', { error: err, method: REQUEST_TYPE });
65 monitoring.promMetrics('PUT', bucketName, err.code, METRICS_ACTION);
66 return callback(err, corsHeaders);
67 }
68
69 pushMetric(METRICS_ACTION, log, { authInfo, bucket: bucketName });
70 monitoring.promMetrics('PUT', bucketName, '200', METRICS_ACTION);
71 return callback(null, corsHeaders);
72 });
73}
74
75module.exports = bucketPutWebsite;

Callers 5

_comparePutGetXmlFunction · 0.85
transientBucket.jsFile · 0.85

Calls 6

parseWebsiteConfigXmlFunction · 0.85
collectCorsHeadersFunction · 0.85
pushMetricFunction · 0.85
debugMethod · 0.80
traceMethod · 0.80

Tested by

no test coverage detected