cloudmason 0.0.1 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/CODEOWNERS +1 -0
- package/.github/workflows/main.yml +27 -27
- package/README.md +377 -25
- package/build.js +20 -20
- package/commands/delete.js +67 -28
- package/commands/helpers/cf.js +181 -117
- package/commands/helpers/common.js +82 -0
- package/commands/helpers/ec2.js +154 -40
- package/commands/helpers/params.js +231 -178
- package/commands/helpers/s3.js +186 -67
- package/commands/helpers/stacks/asg.yaml +420 -224
- package/commands/helpers/stacks/infra.yaml +102 -106
- package/commands/helpers/stacks.js +25 -25
- package/commands/index.html +22 -0
- package/commands/init_org.js +54 -61
- package/commands/inspect.js +40 -0
- package/commands/launch_app.js +80 -57
- package/commands/list_apps.js +21 -21
- package/commands/new_app.js +44 -50
- package/commands/new_instance.js +133 -186
- package/commands/reset_stack.js +27 -27
- package/commands/starter.js +21 -0
- package/commands/starters/asg_node/index.js +62 -0
- package/commands/starters/asg_node/mason.txt +1 -0
- package/commands/starters/asg_node/modules/appConfig.js +131 -0
- package/commands/starters/asg_node/package-lock.json +5877 -0
- package/commands/starters/asg_node/package.json +23 -0
- package/commands/starters/asg_node/public/css/favicon-16x16.png +0 -0
- package/commands/starters/asg_node/public/css/fonts/Lato-Bold.ttf +0 -0
- package/commands/starters/asg_node/public/css/fonts/Lato-Regular.ttf +0 -0
- package/commands/starters/asg_node/public/css/fonts/Montserrat-Var.ttf +0 -0
- package/commands/starters/asg_node/public/css/fonts/OpenSans.ttf +0 -0
- package/commands/starters/asg_node/public/css/fonts/bpmn.woff2 +0 -0
- package/commands/starters/asg_node/public/css/fonts/fonts.css +17 -0
- package/commands/starters/asg_node/public/css/index.css +9 -0
- package/commands/starters/asg_node/public/index.html +15 -0
- package/commands/starters/asg_node/public/js/index.js +5 -0
- package/commands/starters/asg_node/start.sh +4 -0
- package/commands/update_app.js +235 -272
- package/commands/update_stack.js +27 -0
- package/commands/utils.js +32 -32
- package/main.js +262 -220
- package/package.json +1 -28
- package/test.bat +16 -9
- package/commands/delete_app.js +0 -28
- package/commands/helpers/stacks/asg_draft.json +0 -321
package/commands/helpers/s3.js
CHANGED
|
@@ -1,68 +1,187 @@
|
|
|
1
|
-
const { S3Client,PutObjectCommand,CopyObjectCommand,HeadObjectCommand } = require("@aws-sdk/client-s3");
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
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
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
1
|
+
const { S3Client,PutObjectCommand,CopyObjectCommand,HeadObjectCommand,DeleteObjectsCommand,ListObjectsV2Command,GetObjectCommand,ListObjectVersionsCommand,DeleteObjectCommand } = require("@aws-sdk/client-s3");
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
exports.uploadInfraFile = async function(fileKey,localPath){
|
|
7
|
+
const s3Path = fileKey;
|
|
8
|
+
if (!fs.existsSync(localPath)){
|
|
9
|
+
throw new Error('File does not exist:' + localPath)
|
|
10
|
+
}
|
|
11
|
+
const fileStream = fs.createReadStream(localPath);
|
|
12
|
+
// Upload Stack
|
|
13
|
+
const client = new S3Client({region: process.env.orgRegion});
|
|
14
|
+
const input = {
|
|
15
|
+
Body: fileStream,
|
|
16
|
+
Bucket: process.env.orgBucket,
|
|
17
|
+
Key: s3Path.toLowerCase()
|
|
18
|
+
};
|
|
19
|
+
const poCommand = new PutObjectCommand(input);
|
|
20
|
+
const poResponse = await client.send(poCommand);
|
|
21
|
+
return poResponse;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
exports.uploadInfraText = async function(fileKey,fileText){
|
|
25
|
+
// Upload Stack
|
|
26
|
+
const client = new S3Client({region: process.env.orgRegion});
|
|
27
|
+
const input = {
|
|
28
|
+
Body: fileText,
|
|
29
|
+
Bucket: process.env.orgBucket,
|
|
30
|
+
Key: fileKey.toLowerCase()
|
|
31
|
+
};
|
|
32
|
+
const poCommand = new PutObjectCommand(input);
|
|
33
|
+
const poResponse = await client.send(poCommand);
|
|
34
|
+
return poResponse;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
exports.infraFileExists = async function(fileKey){
|
|
38
|
+
const client = new S3Client({region: process.env.orgRegion});
|
|
39
|
+
|
|
40
|
+
const input = {
|
|
41
|
+
Bucket: process.env.orgBucket,
|
|
42
|
+
Key: fileKey.toLowerCase()
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const command = new HeadObjectCommand(input)
|
|
46
|
+
try{
|
|
47
|
+
const response = await client.send(command);
|
|
48
|
+
return true;
|
|
49
|
+
} catch (e){
|
|
50
|
+
if (/NotFound/.test(e)){
|
|
51
|
+
return false;
|
|
52
|
+
} else {
|
|
53
|
+
console.log('Uncaught Error:',e)
|
|
54
|
+
throw e;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
exports.copyInfraFile = async function(srcKey,destKey){
|
|
61
|
+
const client = new S3Client({ region: process.env.orgRegion });
|
|
62
|
+
const params = {
|
|
63
|
+
Bucket: process.env.orgBucket,
|
|
64
|
+
CopySource: `${process.env.orgBucket}/${srcKey}`,
|
|
65
|
+
Key: destKey.toLowerCase(),
|
|
66
|
+
};
|
|
67
|
+
await client.send(new CopyObjectCommand(params));
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
exports.emptyBucket = async function(bucketName,region){
|
|
72
|
+
await emptyS3Bucket(bucketName,region)
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
exports.deleteAppFolder = async function(appName){
|
|
77
|
+
await deleteFolder(
|
|
78
|
+
process.env.orgBucket,
|
|
79
|
+
`apps/${appName.toLowerCase()}/`,
|
|
80
|
+
process.env.orgRegion
|
|
81
|
+
)
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
exports.readFiles = async function(bucketName,prefix,region){
|
|
86
|
+
const s3Client= new S3Client({region});
|
|
87
|
+
const Content = [];
|
|
88
|
+
const listCommand = new ListObjectsV2Command({
|
|
89
|
+
Bucket: bucketName,
|
|
90
|
+
Prefix: prefix,
|
|
91
|
+
MaxKeys: 50
|
|
92
|
+
});
|
|
93
|
+
const listResponse = await s3Client.send(listCommand);
|
|
94
|
+
|
|
95
|
+
if (!listResponse.Contents) { return []}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
const proms = listResponse.Contents.map(object=>{
|
|
99
|
+
return s3Client.send(new GetObjectCommand({
|
|
100
|
+
Bucket: bucketName,
|
|
101
|
+
Key: object.Key,
|
|
102
|
+
})).then(r=>{
|
|
103
|
+
return streamToString(r.Body).then(fileContent=>{
|
|
104
|
+
Content.push({
|
|
105
|
+
Key: object.Key,
|
|
106
|
+
FileName: object.Key.replace(prefix + '/',''),
|
|
107
|
+
Content: fileContent,
|
|
108
|
+
LastModified: object.LastModified
|
|
109
|
+
});
|
|
110
|
+
})
|
|
111
|
+
});
|
|
112
|
+
})
|
|
113
|
+
await Promise.all(proms);
|
|
114
|
+
return Content.sort((a,b)=>{ return new Date(a.LastModified) - new Date(b.LastModified) });
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
///////////
|
|
119
|
+
|
|
120
|
+
async function deleteFolder(bucketName, prefix, region){
|
|
121
|
+
const client = new S3Client({ region });
|
|
122
|
+
const listParams = {
|
|
123
|
+
Bucket: bucketName,
|
|
124
|
+
Prefix: prefix
|
|
125
|
+
};
|
|
126
|
+
const listedObjects = await client.send(new ListObjectsV2Command(listParams));
|
|
127
|
+
|
|
128
|
+
if (!listedObjects.Contents || listedObjects.Contents.length === 0) return;
|
|
129
|
+
|
|
130
|
+
// Array to hold all keys to delete
|
|
131
|
+
const deleteKeys = listedObjects.Contents.map(({ Key }) => ({ Key }));
|
|
132
|
+
|
|
133
|
+
// Delete objects
|
|
134
|
+
const deleteParams = {
|
|
135
|
+
Bucket: bucketName,
|
|
136
|
+
Delete: { Objects: deleteKeys }
|
|
137
|
+
};
|
|
138
|
+
await client.send(new DeleteObjectsCommand(deleteParams));
|
|
139
|
+
|
|
140
|
+
// In case of pagination (more than 1000 objects), recursively handle the next batch
|
|
141
|
+
if (listedObjects.IsTruncated) await deleteFolder(bucketName, prefix, region);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
async function emptyS3Bucket(bucketName, region) {
|
|
146
|
+
const s3Client= new S3Client({region});
|
|
147
|
+
|
|
148
|
+
// List all object versions
|
|
149
|
+
const listedObjectVersions = await s3Client.send(new ListObjectVersionsCommand({ Bucket: bucketName }));
|
|
150
|
+
if (listedObjectVersions.Versions || listedObjectVersions.DeleteMarkers) {
|
|
151
|
+
const objectsToDelete = [
|
|
152
|
+
...listedObjectVersions.Versions.map(v => ({ Key: v.Key, VersionId: v.VersionId })),
|
|
153
|
+
...listedObjectVersions.DeleteMarkers.map(dm => ({ Key: dm.Key, VersionId: dm.VersionId }))
|
|
154
|
+
];
|
|
155
|
+
|
|
156
|
+
for (const object of objectsToDelete) {
|
|
157
|
+
await s3Client.send(new DeleteObjectCommand({
|
|
158
|
+
Bucket: bucketName,
|
|
159
|
+
Key: object.Key,
|
|
160
|
+
VersionId: object.VersionId
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// List all objects
|
|
166
|
+
const listedObjects = await s3Client.send(new ListObjectsV2Command({ Bucket: bucketName }));
|
|
167
|
+
if (!listedObjects.Contents || listedObjects.Contents.length === 0) return;
|
|
168
|
+
|
|
169
|
+
// Delete all objects
|
|
170
|
+
const deleteParams = {
|
|
171
|
+
Bucket: bucketName,
|
|
172
|
+
Delete: { Objects: listedObjects.Contents.map(({ Key }) => ({ Key })) }
|
|
173
|
+
};
|
|
174
|
+
await s3Client.send(new DeleteObjectsCommand(deleteParams));
|
|
175
|
+
|
|
176
|
+
// Recursively call the function if the bucket is not empty
|
|
177
|
+
if (listedObjects.IsTruncated) await emptyS3Bucket(bucketName);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async function streamToString(stream) {
|
|
181
|
+
return new Promise((resolve, reject) => {
|
|
182
|
+
const chunks = [];
|
|
183
|
+
stream.on('data', (chunk) => chunks.push(chunk));
|
|
184
|
+
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
|
|
185
|
+
stream.on('error', reject);
|
|
186
|
+
});
|
|
68
187
|
}
|