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

Function _createEncryptedBucket

lib/kms/utilities.js:8–65  ·  view source on GitHub ↗
(host,
                                port,
                                bucketName,
                                accessKey,
                                secretKey,
                                verbose, ssl,
                                locationConstraint)

Source from the content-addressed store, hash-verified

6const logger = require('../utilities/logger');
7
8function _createEncryptedBucket(host,
9 port,
10 bucketName,
11 accessKey,
12 secretKey,
13 verbose, ssl,
14 locationConstraint) {
15 const options = {
16 host,
17 port,
18 method: 'PUT',
19 path: `/${bucketName}/`,
20 headers: {
21 'x-amz-scal-server-side-encryption': 'AES256',
22 },
23 rejectUnauthorized: false,
24 };
25 const transport = ssl ? https : http;
26 const request = transport.request(options, response => {
27 if (verbose) {
28 logger.info('response status code', {
29 statusCode: response.statusCode,
30 });
31 logger.info('response headers', { headers: response.headers });
32 }
33 const body = [];
34 response.setEncoding('utf8');
35 response.on('data', chunk => body.push(chunk));
36 response.on('end', () => {
37 if (response.statusCode >= 200 && response.statusCode < 300) {
38 logger.info('Success', {
39 statusCode: response.statusCode,
40 body: verbose ? body.join('') : undefined,
41 });
42 process.exit(0);
43 } else {
44 logger.error('request failed with HTTP Status ', {
45 statusCode: response.statusCode,
46 body: body.join(''),
47 });
48 process.exit(1);
49 }
50 });
51 });
52
53 auth.client.generateV4Headers(request, '', accessKey, secretKey, 's3');
54 if (verbose) {
55 logger.info('request headers', { headers: request.getHeaders() });
56 }
57 if (locationConstraint) {
58 const createBucketConfiguration = '<CreateBucketConfiguration ' +
59 'xmlns="http://s3.amazonaws.com/doc/2006-03-01/">' +
60 `<LocationConstraint>${locationConstraint}</LocationConstraint>` +
61 '</CreateBucketConfiguration >';
62 request.write(createBucketConfiguration);
63 }
64 request.end();
65}

Callers 1

createEncryptedBucketFunction · 0.85

Calls 4

infoMethod · 0.80
errorMethod · 0.80
writeMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected