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