|
1 | 1 | const assert = require('assert'); |
2 | 2 | const async = require('async'); |
| 3 | +const { |
| 4 | + CreateBucketCommand, |
| 5 | + DeleteBucketCommand, |
| 6 | + PutBucketVersioningCommand, |
| 7 | + PutObjectCommand, |
| 8 | +} = require('@aws-sdk/client-s3'); |
3 | 9 | const BucketUtility = require('../aws-node-sdk/lib/utility/bucket-util'); |
4 | 10 | const { removeAllVersions } = require('../aws-node-sdk/lib/utility/versioning-util'); |
5 | 11 | const { makeBackbeatRequest, updateMetadata } = require('./utils'); |
6 | 12 | const { config } = require('../../../lib/Config'); |
7 | 13 |
|
8 | 14 | const testBucket = 'bucket-for-list-lifecycle-current-tests'; |
9 | 15 |
|
10 | | -const bucketUtil = new BucketUtility('default', { signatureVersion: 'v4' }); |
| 16 | +const bucketUtil = new BucketUtility('default', {}); |
11 | 17 | const s3 = bucketUtil.s3; |
12 | | -const credentials = { |
13 | | - accessKey: s3.config.credentials.accessKeyId, |
14 | | - secretKey: s3.config.credentials.secretAccessKey, |
15 | | -}; |
16 | 18 |
|
17 | | -// for S3C it is dc-1, in Integration it's node1.scality.com, otherwise us-east-1 |
18 | | -const s3Hostname = s3.endpoint.hostname; |
19 | | -const location1 = config.restEndpoints[s3Hostname] || config.restEndpoints.localhost; |
20 | | -const location2 = 'us-east-2'; |
| 19 | +async function getCredentials() { |
| 20 | + const creds = await s3.config.credentials(); |
| 21 | + console.log('credential retrieved', creds); |
| 22 | + return credentials = { |
| 23 | + accessKey: creds.accessKeyId, |
| 24 | + secretKey: creds.secretAccessKey, |
| 25 | + }; |
| 26 | +} |
| 27 | + |
| 28 | +async function getS3Hostname() { |
| 29 | + const s3Hostname = await s3.config.endpoint(); |
| 30 | + return s3Hostname.hostname; |
| 31 | +} |
21 | 32 |
|
22 | 33 | describe('excludedDataStoreName', () => { |
23 | 34 | const expectedVersions = []; |
| 35 | + let credentials; |
| 36 | + let s3Hostname; |
| 37 | + let location1; |
| 38 | + let location2; |
24 | 39 |
|
25 | 40 | before(done => async.series([ |
26 | | - next => s3.createBucket({ Bucket: testBucket }, next), |
27 | | - next => s3.putBucketVersioning({ |
28 | | - Bucket: testBucket, |
29 | | - VersioningConfiguration: { Status: 'Enabled' }, |
30 | | - }, next), |
31 | | - next => s3.putObject({ Bucket: testBucket, Key: 'key0' }, (err, data) => { |
32 | | - expectedVersions.push(data.VersionId); |
33 | | - return next(err); |
34 | | - }), |
35 | | - next => s3.putObject({ Bucket: testBucket, Key: 'key0' }, (err, data) => { |
36 | | - if (err) { |
37 | | - return next(err); |
38 | | - } |
39 | | - const versionId = data.VersionId; |
40 | | - return updateMetadata( |
41 | | - { bucket: testBucket, objectKey: 'key0', versionId, authCredentials: credentials }, |
42 | | - { dataStoreName: location2 }, |
43 | | - next); |
44 | | - }), |
45 | | - next => s3.putObject({ Bucket: testBucket, Key: 'key0' }, (err, data) => { |
46 | | - expectedVersions.push(data.VersionId); |
47 | | - return next(err); |
48 | | - }), |
49 | | - next => s3.putObject({ Bucket: testBucket, Key: 'key0' }, next), |
50 | | - next => s3.putObject({ Bucket: testBucket, Key: 'key1' }, (err, data) => { |
51 | | - if (err) { |
52 | | - return next(err); |
53 | | - } |
54 | | - const versionId = data.VersionId; |
55 | | - return updateMetadata( |
56 | | - { bucket: testBucket, objectKey: 'key1', versionId, authCredentials: credentials }, |
57 | | - { dataStoreName: location2 }, |
58 | | - next); |
59 | | - }), |
60 | | - next => s3.putObject({ Bucket: testBucket, Key: 'key2' }, next), |
| 41 | + next => { |
| 42 | + getCredentials() |
| 43 | + .then(creds => { |
| 44 | + credentials = creds; |
| 45 | + next(); |
| 46 | + }) |
| 47 | + .catch(next); |
| 48 | + }, |
| 49 | + next => { |
| 50 | + getS3Hostname() |
| 51 | + .then(hostname => { |
| 52 | + s3Hostname = hostname; |
| 53 | + location1 = config.restEndpoints[s3Hostname] || config.restEndpoints.localhost; |
| 54 | + location2 = 'us-east-2'; |
| 55 | + next(); |
| 56 | + }) |
| 57 | + .catch(next); |
| 58 | + }, |
| 59 | + next => { |
| 60 | + s3.send(new CreateBucketCommand({ Bucket: testBucket })) |
| 61 | + .then(() => next()) |
| 62 | + .catch(next); |
| 63 | + }, |
| 64 | + next => { |
| 65 | + s3.send(new PutBucketVersioningCommand({ |
| 66 | + Bucket: testBucket, |
| 67 | + VersioningConfiguration: { Status: 'Enabled' }, |
| 68 | + })) |
| 69 | + .then(() => next()) |
| 70 | + .catch(next); |
| 71 | + }, |
| 72 | + next => { |
| 73 | + s3.send(new PutObjectCommand({ Bucket: testBucket, Key: 'key0' })) |
| 74 | + .then(data => { |
| 75 | + expectedVersions.push(data.VersionId); |
| 76 | + next(); |
| 77 | + }) |
| 78 | + .catch(next); |
| 79 | + }, |
| 80 | + next => { |
| 81 | + s3.send(new PutObjectCommand({ Bucket: testBucket, Key: 'key0' })) |
| 82 | + .then(data => { |
| 83 | + const versionId = data.VersionId; |
| 84 | + return updateMetadata( |
| 85 | + { bucket: testBucket, objectKey: 'key0', versionId, authCredentials: credentials }, |
| 86 | + { dataStoreName: location2 }, |
| 87 | + next); |
| 88 | + }) |
| 89 | + .catch(next); |
| 90 | + }, |
| 91 | + next => { |
| 92 | + s3.send(new PutObjectCommand({ Bucket: testBucket, Key: 'key0' })) |
| 93 | + .then(data => { |
| 94 | + console.log('we are here2'); |
| 95 | + expectedVersions.push(data.VersionId); |
| 96 | + next(); |
| 97 | + }) |
| 98 | + .catch(next); |
| 99 | + }, |
| 100 | + next => { |
| 101 | + s3.send(new PutObjectCommand({ Bucket: testBucket, Key: 'key0' })) |
| 102 | + .then(() => next()) |
| 103 | + .catch(next); |
| 104 | + }, |
| 105 | + next => { |
| 106 | + s3.send(new PutObjectCommand({ Bucket: testBucket, Key: 'key1' })) |
| 107 | + .then(data => { |
| 108 | + console.log('we are here'); |
| 109 | + const versionId = data.VersionId; |
| 110 | + return updateMetadata( |
| 111 | + { bucket: testBucket, objectKey: 'key1', versionId, authCredentials: credentials }, |
| 112 | + { dataStoreName: location2 }, |
| 113 | + next); |
| 114 | + }) |
| 115 | + .catch(next); |
| 116 | + }, |
| 117 | + next => { |
| 118 | + s3.send(new PutObjectCommand({ Bucket: testBucket, Key: 'key2' })) |
| 119 | + .then(() => next()) |
| 120 | + .catch(next); |
| 121 | + }, |
61 | 122 | ], done)); |
62 | 123 |
|
63 | | - after(done => async.series([ |
64 | | - next => removeAllVersions({ Bucket: testBucket }, next), |
65 | | - next => s3.deleteBucket({ Bucket: testBucket }, next), |
66 | | - ], done)); |
| 124 | + after(async () => { |
| 125 | + await removeAllVersions({ Bucket: testBucket }); |
| 126 | + await s3.send(new DeleteBucketCommand({ Bucket: testBucket })); |
| 127 | + }); |
67 | 128 |
|
68 | 129 | it('should return error when listing current versions if excluded-data-store-name is not in config', done => { |
69 | 130 | makeBackbeatRequest({ |
@@ -280,3 +341,4 @@ describe('excludedDataStoreName', () => { |
280 | 341 | }); |
281 | 342 | }); |
282 | 343 | }); |
| 344 | + |
0 commit comments