-
Couldn't load subscription status.
- Fork 252
Improvement/cldsrv 724 sur utapi tests #5950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
benzekrimaha
wants to merge
8
commits into
development/9.1
Choose a base branch
from
improvement/CLDSRV-724-sur-utapi-tests
base: development/9.1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7043630
utilities adaptation to comply with sdk migration
benzekrimaha b8fd513
SUR tests sdk migration
benzekrimaha c16b799
UTAPI tests sdk migration
benzekrimaha 1b3237e
dependencies install
benzekrimaha adb7ac5
post reviews fixups
benzekrimaha 4f9b629
fixup post reviews
benzekrimaha 9ab1750
Merge remote-tracking branch 'origin/development/9.1' into HEAD
benzekrimaha 165b47b
yarn lint fix
benzekrimaha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -1,81 +1,87 @@ | ||||
| const AWS = require('aws-sdk'); | ||||
| AWS.config.logger = console; | ||||
| const { S3 } = require('aws-sdk'); | ||||
| const { | ||||
| S3Client, | ||||
| HeadBucketCommand, | ||||
| CreateBucketCommand, | ||||
| DeleteBucketCommand, | ||||
| ListObjectVersionsCommand, | ||||
| DeleteObjectCommand, | ||||
| ListBucketsCommand, | ||||
| } = require('@aws-sdk/client-s3'); | ||||
| const projectFixture = require('../fixtures/project'); | ||||
| const getConfig = require('../../test/support/config'); | ||||
|
|
||||
| class BucketUtility { | ||||
| constructor(profile = 'default', config = {}) { | ||||
| constructor(profile = 'default', config = {}, unauthenticated = false) { | ||||
| const s3Config = getConfig(profile, config); | ||||
|
|
||||
| this.s3 = new S3(s3Config); | ||||
| this.s3.config.setPromisesDependency(Promise); | ||||
| this.s3.config.update({ | ||||
| maxRetries: 0, | ||||
| }); | ||||
| if (unauthenticated) { | ||||
| this.s3 = new S3Client({ | ||||
| ...s3Config, | ||||
| maxAttempts: 0, | ||||
| credentials: { accessKeyId: '', secretAccessKey: '' }, | ||||
| forcePathStyle: true, | ||||
| signer: { sign: async request => request }, | ||||
| }); | ||||
| } | ||||
| else { | ||||
| this.s3 = new S3Client({ | ||||
| ...s3Config, | ||||
| maxAttempts: 0, | ||||
| }); | ||||
| } | ||||
| } | ||||
|
|
||||
| bucketExists(bucketName) { | ||||
| return this.s3 | ||||
| .headBucket({ Bucket: bucketName }) | ||||
| .promise() | ||||
| return this.s3.send(new HeadBucketCommand({ Bucket: bucketName })) | ||||
| .then(() => true) | ||||
| .catch(err => { | ||||
| if (err.code === 'NotFound') { | ||||
| if (err.name === 'NotFound') { | ||||
| return false; | ||||
| } | ||||
| throw err; | ||||
| }); | ||||
| } | ||||
|
|
||||
| createOne(bucketName) { | ||||
| return this.s3 | ||||
| .createBucket({ Bucket: bucketName }) | ||||
| .promise() | ||||
| .then(() => bucketName); | ||||
| return this.s3.send(new CreateBucketCommand({ Bucket: bucketName })) | ||||
| .then(() => bucketName) | ||||
| .catch(err => { | ||||
| throw err; | ||||
| }); | ||||
| } | ||||
|
|
||||
| createOneWithLock(bucketName) { | ||||
| return this.s3 | ||||
| .createBucket({ | ||||
| Bucket: bucketName, | ||||
| ObjectLockEnabledForBucket: true, | ||||
| }) | ||||
| .promise() | ||||
| .then(() => bucketName); | ||||
| return this.s3.send(new CreateBucketCommand({ | ||||
| Bucket: bucketName, | ||||
| ObjectLockEnabledForBucket: true, | ||||
| })).then(() => bucketName); | ||||
| } | ||||
|
|
||||
| createMany(bucketNames) { | ||||
| const promises = bucketNames.map(bucketName => | ||||
| this.createOne(bucketName), | ||||
| ); | ||||
|
|
||||
| return Promise.all(promises); | ||||
| } | ||||
|
|
||||
| createRandom(nBuckets = 1) { | ||||
| if (nBuckets === 1) { | ||||
| const bucketName = projectFixture.generateBucketName(); | ||||
|
|
||||
| return this.createOne(bucketName); | ||||
| } | ||||
|
|
||||
| const bucketNames = projectFixture | ||||
| .generateManyBucketNames(nBuckets) | ||||
| .sort(() => 0.5 - Math.random()); // Simply shuffle array | ||||
|
|
||||
| .sort(() => 0.5 - Math.random()); | ||||
| return this.createMany(bucketNames); | ||||
| } | ||||
|
|
||||
| deleteOne(bucketName) { | ||||
| return this.s3.deleteBucket({ Bucket: bucketName }).promise(); | ||||
| return this.s3.send(new DeleteBucketCommand({ Bucket: bucketName })); | ||||
| } | ||||
|
|
||||
| deleteMany(bucketNames) { | ||||
| const promises = bucketNames.map(bucketName => | ||||
| this.deleteOne(bucketName), | ||||
| ); | ||||
|
|
||||
| return Promise.all(promises); | ||||
| } | ||||
|
|
||||
|
|
@@ -84,68 +90,57 @@ class BucketUtility { | |||
| * @param bucketName | ||||
| * @returns {Promise.<T>} | ||||
| */ | ||||
|
|
||||
| async empty(bucketName, BypassGovernanceRetention = false) { | ||||
| empty(bucketName, BypassGovernanceRetention = false) { | ||||
| const param = { | ||||
| Bucket: bucketName, | ||||
| }; | ||||
|
|
||||
| const listedObjects = await this.s3.listObjectVersions(param).promise(); | ||||
|
|
||||
| for (const version of listedObjects.Versions) { | ||||
| if (version.Key.endsWith('/')) { | ||||
| continue; | ||||
| } | ||||
|
|
||||
| await this.s3 | ||||
| .deleteObject({ | ||||
| Bucket: bucketName, | ||||
| Key: version.Key, | ||||
| VersionId: version.VersionId, | ||||
| ...(BypassGovernanceRetention && { | ||||
| BypassGovernanceRetention, | ||||
| }), | ||||
| }) | ||||
| .promise(); | ||||
| } | ||||
|
|
||||
| for (const version of listedObjects.Versions) { | ||||
| if (!version.Key.endsWith('/')) { | ||||
| continue; | ||||
| } | ||||
|
|
||||
| await this.s3 | ||||
| .deleteObject({ | ||||
| Bucket: bucketName, | ||||
| Key: version.Key, | ||||
| VersionId: version.VersionId, | ||||
| ...(BypassGovernanceRetention && { | ||||
| BypassGovernanceRetention, | ||||
| }), | ||||
| }) | ||||
| .promise(); | ||||
| } | ||||
|
|
||||
| for (const marker of listedObjects.DeleteMarkers) { | ||||
| await this.s3 | ||||
| .deleteObject({ | ||||
| Bucket: bucketName, | ||||
| Key: marker.Key, | ||||
| VersionId: marker.VersionId, | ||||
| ...(BypassGovernanceRetention && { | ||||
| BypassGovernanceRetention, | ||||
| }), | ||||
| }) | ||||
| .promise(); | ||||
| } | ||||
| return this.s3.send(new ListObjectVersionsCommand(param)) | ||||
| .then(data => Promise.all( | ||||
| (data.Versions || []) | ||||
| .filter(object => !object.Key.endsWith('/')) | ||||
| .map(object => | ||||
| this.s3.send(new DeleteObjectCommand({ | ||||
| Bucket: bucketName, | ||||
| Key: object.Key, | ||||
| VersionId: object.VersionId, | ||||
| ...(BypassGovernanceRetention && { BypassGovernanceRetention }), | ||||
| })).then(() => object) | ||||
| ) | ||||
| .concat((data.Versions || []) | ||||
| .filter(object => object.Key.endsWith('/')) | ||||
| .map(object => | ||||
| this.s3.send(new DeleteObjectCommand({ | ||||
| Bucket: bucketName, | ||||
| Key: object.Key, | ||||
| VersionId: object.VersionId, | ||||
| ...(BypassGovernanceRetention && { BypassGovernanceRetention }), | ||||
| })) | ||||
| .then(() => object) | ||||
| ) | ||||
| ) | ||||
| .concat((data.DeleteMarkers || []) | ||||
| .map(object => | ||||
| this.s3.send(new DeleteObjectCommand({ | ||||
| Bucket: bucketName, | ||||
| Key: object.Key, | ||||
| VersionId: object.VersionId, | ||||
| ...(BypassGovernanceRetention && { BypassGovernanceRetention }), | ||||
| })) | ||||
| .then(() => object) | ||||
| ) | ||||
| ) | ||||
| ) | ||||
| ); | ||||
| } | ||||
|
|
||||
| emptyMany(bucketNames) { | ||||
| const promises = bucketNames.map(bucketName => this.empty(bucketName)); | ||||
|
|
||||
| const promises = bucketNames.map( | ||||
| bucketName => this.empty(bucketName) | ||||
| ); | ||||
| return Promise.all(promises); | ||||
| } | ||||
|
|
||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| emptyIfExists(bucketName) { | ||||
benzekrimaha marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
| return this.bucketExists(bucketName).then(exists => { | ||||
| if (exists) { | ||||
|
|
@@ -154,20 +149,19 @@ class BucketUtility { | |||
| return undefined; | ||||
| }); | ||||
| } | ||||
|
|
||||
| emptyManyIfExists(bucketNames) { | ||||
| const promises = bucketNames.map(bucketName => | ||||
| this.emptyIfExists(bucketName), | ||||
| ); | ||||
|
|
||||
| return Promise.all(promises); | ||||
| } | ||||
|
|
||||
| getOwner() { | ||||
| return this.s3 | ||||
| .listBuckets() | ||||
| .promise() | ||||
| .then(data => data.Owner); | ||||
| return this.s3.send(new ListBucketsCommand({})) | ||||
| .then(data => data.Owner) | ||||
| .catch(err => { | ||||
| throw err; | ||||
| }); | ||||
| } | ||||
| } | ||||
|
|
||||
|
|
||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.