cloudmason 0.0.1 → 1.0.2
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 +373 -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
|
@@ -1,178 +1,231 @@
|
|
|
1
|
-
const { SSMClient, GetParameterCommand,PutParameterCommand,GetParametersByPathCommand } = require("@aws-sdk/client-ssm");
|
|
2
|
-
|
|
3
|
-
// ORG PARAMS
|
|
4
|
-
exports.getOrgConfig = async function(){
|
|
5
|
-
if (!process.env.orgRegion){ throw new Error('Region not set') }
|
|
6
|
-
const ssmClient = new SSMClient({ region: process.env.orgRegion }); // Set your preferred region
|
|
7
|
-
const pathPrefix = "/infra/";
|
|
8
|
-
const parameters = [];
|
|
9
|
-
let nextToken;
|
|
10
|
-
|
|
11
|
-
do {
|
|
12
|
-
const response = await ssmClient.send(new GetParametersByPathCommand({
|
|
13
|
-
Path: pathPrefix,
|
|
14
|
-
NextToken: nextToken
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
|
-
if (response.Parameters) {
|
|
18
|
-
parameters.push(...response.Parameters);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
nextToken = response.NextToken;
|
|
22
|
-
|
|
23
|
-
} while (nextToken);
|
|
24
|
-
const params = {}
|
|
25
|
-
parameters.forEach(p=>{
|
|
26
|
-
const k = p.Name.split('/')[p.Name.split('/').length-1]
|
|
27
|
-
params[k] = p.Value
|
|
28
|
-
})
|
|
29
|
-
return params;
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
//
|
|
96
|
-
exports.
|
|
97
|
-
if (!process.env.orgRegion){ throw new Error('Region not set') }
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
const
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
1
|
+
const { SSMClient, GetParameterCommand,PutParameterCommand,GetParametersByPathCommand,DeleteParameterCommand } = require("@aws-sdk/client-ssm");
|
|
2
|
+
|
|
3
|
+
// ORG PARAMS
|
|
4
|
+
exports.getOrgConfig = async function(){
|
|
5
|
+
if (!process.env.orgRegion){ throw new Error('Region not set') }
|
|
6
|
+
const ssmClient = new SSMClient({ region: process.env.orgRegion }); // Set your preferred region
|
|
7
|
+
const pathPrefix = "/infra/";
|
|
8
|
+
const parameters = [];
|
|
9
|
+
let nextToken;
|
|
10
|
+
|
|
11
|
+
do {
|
|
12
|
+
const response = await ssmClient.send(new GetParametersByPathCommand({
|
|
13
|
+
Path: pathPrefix,
|
|
14
|
+
NextToken: nextToken
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
if (response.Parameters) {
|
|
18
|
+
parameters.push(...response.Parameters);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
nextToken = response.NextToken;
|
|
22
|
+
|
|
23
|
+
} while (nextToken);
|
|
24
|
+
const params = {}
|
|
25
|
+
parameters.forEach(p=>{
|
|
26
|
+
const k = p.Name.split('/')[p.Name.split('/').length-1]
|
|
27
|
+
params[k] = p.Value
|
|
28
|
+
})
|
|
29
|
+
return params;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
exports.getOrgBucket = async function(){
|
|
33
|
+
const bucket = await readParam('/infra/infraBucket',process.env.orgRegion)
|
|
34
|
+
return bucket;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// APP PARAMS
|
|
38
|
+
exports.listApps = async function(){
|
|
39
|
+
if (!process.env.orgRegion){ throw new Error('Region not set') }
|
|
40
|
+
|
|
41
|
+
const ssmClient = new SSMClient({ region: process.env.orgRegion }); // Set your preferred region
|
|
42
|
+
const pathPrefix = "/infra/apps/";
|
|
43
|
+
const parameters = [];
|
|
44
|
+
let nextToken;
|
|
45
|
+
|
|
46
|
+
do {
|
|
47
|
+
const response = await ssmClient.send(new GetParametersByPathCommand({
|
|
48
|
+
Path: pathPrefix,
|
|
49
|
+
NextToken: nextToken
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
if (response.Parameters) {
|
|
53
|
+
parameters.push(...response.Parameters);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
nextToken = response.NextToken;
|
|
57
|
+
|
|
58
|
+
} while (nextToken);
|
|
59
|
+
const params = parameters.map(p=>{ return JSON.parse(p.Value) })
|
|
60
|
+
return params;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
exports.getApp = async function(appName){
|
|
64
|
+
if (!process.env.orgRegion){ throw new Error('Region not set') }
|
|
65
|
+
const app = await readParam(
|
|
66
|
+
`/infra/apps/${appName.toLowerCase()}`,
|
|
67
|
+
process.env.orgRegion
|
|
68
|
+
)
|
|
69
|
+
return app ? JSON.parse(app) : null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
exports.addApp = async function(appName,appType,stackKey,nodeV,pyV){
|
|
73
|
+
const appData = {
|
|
74
|
+
name: appName,
|
|
75
|
+
stack: appType,
|
|
76
|
+
nodeV: nodeV,
|
|
77
|
+
pyV: pyV,
|
|
78
|
+
stackKey: stackKey,
|
|
79
|
+
versions: {
|
|
80
|
+
// build,ami,updated
|
|
81
|
+
},
|
|
82
|
+
instances: []
|
|
83
|
+
}
|
|
84
|
+
const paramPath = `/infra/apps/${appName.toLowerCase()}`;
|
|
85
|
+
await writeParam(paramPath,JSON.stringify(appData),process.env.orgRegion);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
exports.deleteApp = async function(appName){
|
|
89
|
+
if (!process.env.orgRegion){ throw new Error('Region not set') }
|
|
90
|
+
const paramPath = `/infra/apps/${appName.toLowerCase()}`;
|
|
91
|
+
await deleteParam(paramPath,process.env.orgRegion);
|
|
92
|
+
return true
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// VERSION PARAMS
|
|
96
|
+
exports.updateAppV = async function(appName,version,vParams){
|
|
97
|
+
if (!process.env.orgRegion){ throw new Error('Region not set') }
|
|
98
|
+
if (!vParams.baseAMI_Name || !vParams.baseAMI_Id || !vParams.updated){ throw new Error('Missing version param' + vParams)}
|
|
99
|
+
const appKey = `/infra/apps/${appName.toLowerCase()}`
|
|
100
|
+
const appStr = await readParam(appKey,process.env.orgRegion);
|
|
101
|
+
const app = JSON.parse(appStr);
|
|
102
|
+
|
|
103
|
+
app.versions[version] = vParams;
|
|
104
|
+
await writeParam(appKey,JSON.stringify(app),process.env.orgRegion);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// INSTANCE PARAMS
|
|
108
|
+
exports.addInstance = async function(appName,instanceName,params){
|
|
109
|
+
if (!process.env.orgRegion){ throw new Error('Region not set') }
|
|
110
|
+
const appKey = `/infra/apps/${appName.toLowerCase()}`
|
|
111
|
+
const appStr = await readParam(appKey,process.env.orgRegion);
|
|
112
|
+
const app = JSON.parse(appStr);
|
|
113
|
+
|
|
114
|
+
const ei = app.instances.find(ins=>{ return ins.domain.toLowerCase() == instanceName.toLowerCase()});
|
|
115
|
+
if (ei){
|
|
116
|
+
throw new Error('Instance exists')
|
|
117
|
+
}
|
|
118
|
+
app.instances.push(params);
|
|
119
|
+
await writeParam(appKey,JSON.stringify(app),process.env.orgRegion)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
exports.updateInstanceV = async function(appName,instanceName,version,build,amiId,amiName){
|
|
123
|
+
if (!process.env.orgRegion){ throw new Error('Region not set') }
|
|
124
|
+
const appKey = `/infra/apps/${appName.toLowerCase()}`
|
|
125
|
+
const appStr = await readParam(appKey,process.env.orgRegion);
|
|
126
|
+
const app = JSON.parse(appStr);
|
|
127
|
+
const ei = app.instances.find(ins=>{ return ins.domain.toLowerCase() == instanceName.toLowerCase()});
|
|
128
|
+
if (!ei){ throw new Error('Instance not found') }
|
|
129
|
+
|
|
130
|
+
ei.version = version;
|
|
131
|
+
ei.build = build;
|
|
132
|
+
ei.lastDeployed = Date.now();
|
|
133
|
+
ei.amiName = amiName;
|
|
134
|
+
ei.cfParams.AmiId = amiId;
|
|
135
|
+
|
|
136
|
+
await writeParam(appKey,JSON.stringify(app),process.env.orgRegion)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// exports.editInstance = async function(appName,instanceName,version,stack,cfParams){
|
|
140
|
+
// if (!process.env.orgRegion){ throw new Error('Region not set') }
|
|
141
|
+
// const appKey = `/infra/apps/${appName.toLowerCase()}`
|
|
142
|
+
// const appStr = await readParam(appKey,process.env.orgRegion);
|
|
143
|
+
// const app = JSON.parse(appStr);
|
|
144
|
+
|
|
145
|
+
// const ei = app.instances.find(ins=>{ return ins.domain.toLowerCase() == instanceName.toLowerCase()});
|
|
146
|
+
// if (!ei){ throw new Error('Instance not found') }
|
|
147
|
+
// ei.version = version;
|
|
148
|
+
// ei.stack = stack;
|
|
149
|
+
// ei.cfParams = cfParams;
|
|
150
|
+
// ei.lastDeployed = Date.now();
|
|
151
|
+
// await writeParam(appKey,JSON.stringify(app),process.env.orgRegion)
|
|
152
|
+
// }
|
|
153
|
+
|
|
154
|
+
exports.deleteInstance = async function(appName,instanceName){
|
|
155
|
+
if (!process.env.orgRegion){ throw new Error('Region not set') }
|
|
156
|
+
const appKey = `/infra/apps/${appName.toLowerCase()}`
|
|
157
|
+
const appStr = await readParam(appKey,process.env.orgRegion);
|
|
158
|
+
const app = JSON.parse(appStr);
|
|
159
|
+
|
|
160
|
+
const ei = app.instances.find(ins=>{ return ins.domain.toLowerCase() == instanceName.toLowerCase()});
|
|
161
|
+
if (!ei){ throw new Error('Instance not found') }
|
|
162
|
+
app.instances = app.instances.filter(ins=>{ return ins.domain.toLowerCase() !== instanceName.toLowerCase()});
|
|
163
|
+
await writeParam(appKey,JSON.stringify(app),process.env.orgRegion)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
//////////////////////
|
|
171
|
+
async function writeParam(name,value,region){
|
|
172
|
+
const ssmClient = new SSMClient({ region }); // specify the appropriate AWS region
|
|
173
|
+
if (value.length > 1000){
|
|
174
|
+
console.log('WARNING: Long parameter ' + value.length + ': ' + name)
|
|
175
|
+
}
|
|
176
|
+
// Creating the command object with the parameter details
|
|
177
|
+
const command = new PutParameterCommand({
|
|
178
|
+
Name: name,
|
|
179
|
+
Value: value,
|
|
180
|
+
Type: 'String', // Specify the parameter type: 'String', 'StringList', or 'SecureString'
|
|
181
|
+
Overwrite: true, // Specify whether to overwrite an existing parameter
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
const response = await ssmClient.send(command);
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async function readParam(name,region){
|
|
189
|
+
const ssmClient = new SSMClient({ region });
|
|
190
|
+
|
|
191
|
+
// Create a command object with the parameter name
|
|
192
|
+
const command = new GetParameterCommand({
|
|
193
|
+
Name: name,
|
|
194
|
+
WithDecryption: true
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
try {
|
|
198
|
+
// Send the command to SSM and wait for the result
|
|
199
|
+
const response = await ssmClient.send(command);
|
|
200
|
+
return response.Parameter.Value;
|
|
201
|
+
} catch (error) {
|
|
202
|
+
// Handle any errors
|
|
203
|
+
if (/ParameterNotFound/.test(error)){
|
|
204
|
+
return null;
|
|
205
|
+
} else {
|
|
206
|
+
throw error;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
async function deleteParam(name,region){
|
|
212
|
+
const ssmClient = new SSMClient({ region });
|
|
213
|
+
|
|
214
|
+
// Create a command object with the parameter name
|
|
215
|
+
const command = new DeleteParameterCommand({
|
|
216
|
+
Name: name
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
try {
|
|
220
|
+
// Send the command to SSM and wait for the result
|
|
221
|
+
const response = await ssmClient.send(command);
|
|
222
|
+
return true;
|
|
223
|
+
} catch (error) {
|
|
224
|
+
// Handle any errors
|
|
225
|
+
if (/ParameterNotFound/.test(error)){
|
|
226
|
+
return null;
|
|
227
|
+
} else {
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|