-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelpers.js
62 lines (55 loc) · 1.66 KB
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const aws = require("aws-sdk");
const child_process = require("child_process")
function getEcr(action, settings) {
return new aws.ECR({
region: handleAutoComplete(action.params.region),
accessKeyId: action.params.accessKeyId || settings.accessKeyId,
secretAccessKey: action.params.secretAccessKey || settings.secretAccessKey
});
}
function getEc2(params, settings) {
return new aws.EC2({
region: handleAutoComplete(params.region),
accessKeyId: params.accessKeyId || settings.accessKeyId,
secretAccessKey: params.secretAccessKey || settings.secretAccessKey
});
}
function getLightsail(params, settings) {
return new aws.Lightsail({
region: handleAutoComplete(params.region),
accessKeyId: params.accessKeyId || settings.accessKeyId,
secretAccessKey: params.secretAccessKey || settings.secretAccessKey
});
}
async function executeCmd(command) {
return new Promise((resolve, reject) => {
child_process.exec(command, (error, stdout, stderr) => {
if (error) {
return reject(error);
}
if (stderr) {
console.log(`stderr: ${stderr}`);
}
return resolve(stdout);
});
})
}
function operationCallback(resolve, reject) {
return function (err, result) {
if (err) reject(err);
else resolve(result);
}
}
function handleAutoComplete(param) {
if (param && typeof (param) === "object" && param.hasOwnProperty("id")) {
return param.id;
}
return param;
}
module.exports = {
getEcr,
getEc2,
getLightsail,
executeCmd,
operationCallback
};