Skip to content

Commit d8c0704

Browse files
authored
chore: migrate aws-sdk from v2 to v3 (#5941)
* chore: replace aws-sdk v2 with @aws-sdk/client-s3 v3 * chore: migrate generate-addons.js to aws-sdk v3 with async/await * f
1 parent 4c3c1b1 commit d8c0704

3 files changed

Lines changed: 1593 additions & 650 deletions

File tree

bin/generate-addons.js

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const fs = require("fs");
22
const path = require("path");
33
const semverCompare = require('semver/functions/rcompare')
4-
const AWS = require('aws-sdk');
4+
const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3');
55
const installerVersions = require("../web/src/installers/versions");
66

77
const ID = process.env.AWS_ACCESS_KEY_ID;
@@ -10,35 +10,31 @@ const BUCKET_NAME = process.env.S3_BUCKET;
1010
const FOLDER = process.env.DIST_FOLDER;
1111
const VERSION_TAG = process.env.VERSION_TAG;
1212

13-
const s3 = new AWS.S3({
14-
accessKeyId: ID,
15-
secretAccessKey: SECRET
13+
const s3Client = new S3Client({
14+
region: 'us-east-1',
15+
credentials: { accessKeyId: ID, secretAccessKey: SECRET }
1616
});
1717

18-
const uploadFile = (file) => {
18+
const uploadFile = async (file) => {
1919
const fileName = file.split("/")[1];
2020
const fileContent = fs.readFileSync(file);
2121

2222
let params = {
2323
Bucket: BUCKET_NAME,
24-
Key: FOLDER + "/" + VERSION_TAG + "/" + fileName,
24+
Key: FOLDER + "/" + VERSION_TAG + "/" + fileName,
2525
Body: fileContent
2626
};
27-
s3.upload(params, (err, data) => {
28-
if (err) throw err;
29-
console.log("\x1b[32m%s\x1b[0m", "Successfully uploaded " + fileName + " to " + data.Location);
30-
});
27+
await s3Client.send(new PutObjectCommand(params));
28+
console.log("\x1b[32m%s\x1b[0m", "Successfully uploaded " + fileName + " to " + params.Key);
3129

3230
params = {
3331
Bucket: BUCKET_NAME,
34-
Key: FOLDER + "/" + fileName,
32+
Key: FOLDER + "/" + fileName,
3533
Body: fileContent
3634
};
37-
s3.upload(params, (err, data) => {
38-
if (err) throw err;
39-
console.log("\x1b[32m%s\x1b[0m", "Successfully uploaded " + fileName + " to " + data.Location);
40-
});
41-
}
35+
await s3Client.send(new PutObjectCommand(params));
36+
console.log("\x1b[32m%s\x1b[0m", "Successfully uploaded " + fileName + " to " + params.Key);
37+
};
4238

4339
const preferredVersions = installerVersions.InstallerVersions;
4440
let addons = [];
@@ -118,20 +114,20 @@ fs.readdir(specDir, (err, files) => {
118114
}
119115

120116
// Write finalized JSON files
121-
fs.writeFile("./addons-gen.json", JSON.stringify(addonsFile), (err) => {
117+
fs.writeFile("./addons-gen.json", JSON.stringify(addonsFile), async (err) => {
122118
if (err) throw err;
123119
console.log("\x1b[34m%s\x1b[0m", "Add-ons generated:", addonsFile.addOns.length);
124120
console.log("\x1b[32m%s\x1b[0m", "Successfully generated addons-gen.json");
125121

126122
// Upload files to s3
127-
uploadFile("./addons-gen.json");
123+
await uploadFile("./addons-gen.json");
128124
});
129-
fs.writeFile("./supported-versions-gen.json", JSON.stringify(supportVersionsFile), (err) => {
125+
fs.writeFile("./supported-versions-gen.json", JSON.stringify(supportVersionsFile), async (err) => {
130126
if (err) throw err;
131127
console.log("\x1b[32m%s\x1b[0m", "Successfully generated supported-versions-gen.json");
132128

133129
// Upload files to s3
134-
uploadFile("./supported-versions-gen.json");
130+
await uploadFile("./supported-versions-gen.json");
135131
});
136132

137133
});

0 commit comments

Comments
 (0)