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
package/commands/utils.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const CF = require('./helpers/cf')
|
|
4
|
-
const AdmZip = require("adm-zip");
|
|
5
|
-
|
|
6
|
-
exports.checkValidCF = async function(args){
|
|
7
|
-
const stackPath = path.resolve(args.p);
|
|
8
|
-
console.log('Checking ', stackPath);
|
|
9
|
-
if (!fs.existsSync(stackPath)){
|
|
10
|
-
console.log('Invalid path');
|
|
11
|
-
return
|
|
12
|
-
}
|
|
13
|
-
const stackStr = fs.readFileSync(stackPath,'utf-8');
|
|
14
|
-
const result = await CF.validateStack(stackStr);
|
|
15
|
-
if (result.ok){
|
|
16
|
-
console.log('Template seems good')
|
|
17
|
-
} else {
|
|
18
|
-
console.log(result.data)
|
|
19
|
-
console.log('Is not good')
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
exports.zip = async function(args){
|
|
24
|
-
const inPath = path.resolve(args.p);
|
|
25
|
-
if (!fs.existsSync(inPath)){
|
|
26
|
-
console.log('Not a valid path ' + args.p);
|
|
27
|
-
return
|
|
28
|
-
}
|
|
29
|
-
const zip = new AdmZip();
|
|
30
|
-
zip.addLocalFolder(inPath);
|
|
31
|
-
const outPath = path.resolve(args.o)
|
|
32
|
-
zip.writeZip(outPath);
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const CF = require('./helpers/cf')
|
|
4
|
+
const AdmZip = require("adm-zip");
|
|
5
|
+
|
|
6
|
+
exports.checkValidCF = async function(args){
|
|
7
|
+
const stackPath = path.resolve(args.p);
|
|
8
|
+
console.log('Checking ', stackPath);
|
|
9
|
+
if (!fs.existsSync(stackPath)){
|
|
10
|
+
console.log('Invalid path');
|
|
11
|
+
return
|
|
12
|
+
}
|
|
13
|
+
const stackStr = fs.readFileSync(stackPath,'utf-8');
|
|
14
|
+
const result = await CF.validateStack(stackStr);
|
|
15
|
+
if (result.ok){
|
|
16
|
+
console.log('Template seems good')
|
|
17
|
+
} else {
|
|
18
|
+
console.log(result.data)
|
|
19
|
+
console.log('Is not good')
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
exports.zip = async function(args){
|
|
24
|
+
const inPath = path.resolve(args.p);
|
|
25
|
+
if (!fs.existsSync(inPath)){
|
|
26
|
+
console.log('Not a valid path ' + args.p);
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
const zip = new AdmZip();
|
|
30
|
+
zip.addLocalFolder(inPath);
|
|
31
|
+
const outPath = path.resolve(args.o)
|
|
32
|
+
zip.writeZip(outPath);
|
|
33
33
|
}
|
package/main.js
CHANGED
|
@@ -1,221 +1,263 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const path = require('path')
|
|
4
|
-
const fs = require('fs')
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
{n: '
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
{n: '
|
|
22
|
-
{n: '
|
|
23
|
-
{n: '
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
{n: '
|
|
32
|
-
{n: 'domain', desc: 'Domain to deploy instance behind', r: true},
|
|
33
|
-
{n: 'region', desc: 'Region to deploy instance in', r: true}
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
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
|
-
return
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
function
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const path = require('path')
|
|
4
|
+
const fs = require('fs')
|
|
5
|
+
|
|
6
|
+
const Params = require('./commands/helpers/params');
|
|
7
|
+
|
|
8
|
+
const Commands = {
|
|
9
|
+
'init-org': {
|
|
10
|
+
desc: "Set up a new organization",
|
|
11
|
+
exec: require('./commands/init_org').main,
|
|
12
|
+
args: [
|
|
13
|
+
{n: 'name', desc: 'Unique org Name. Letters only', r: true, pattern: `[A-Za-z]{2,20}`},
|
|
14
|
+
{n: 'region', desc: 'AWS Region for Core Assets. Default us-east-1', r: false}
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
'new-app': {
|
|
18
|
+
desc: 'Add a new application',
|
|
19
|
+
exec: require('./commands/new_app').main,
|
|
20
|
+
args: [
|
|
21
|
+
{n: 'name', desc: 'Application name (letters only)', pattern: `[A-Za-z]{2,20}`, r: true},
|
|
22
|
+
{n: 'type', desc: 'Architecture type: asg | static', r: true},
|
|
23
|
+
{n: 'node', desc: 'Nodejs version. If set, app will run using nodejs', r: false},
|
|
24
|
+
{n: 'py', desc: 'Python version. If set, app will run using python', r: false}
|
|
25
|
+
]
|
|
26
|
+
},
|
|
27
|
+
'new-instance': {
|
|
28
|
+
desc: 'Add an instance of an existing app',
|
|
29
|
+
exec: require('./commands/new_instance').main,
|
|
30
|
+
args: [
|
|
31
|
+
{n: 'app', desc: 'Name of existing app', pattern: `[A-Za-z]{2,20}`, r: true},
|
|
32
|
+
{n: 'domain', desc: 'Domain to deploy instance behind', r: true},
|
|
33
|
+
{n: 'region', desc: 'Region to deploy instance in', r: true},
|
|
34
|
+
{n: 'admin', desc: 'Email address of first admin user', r: true},
|
|
35
|
+
{n: 'max', desc: 'Max number of Ec2 instances to allow in ASG'},
|
|
36
|
+
{n: 'ins', desc: 'Instance type. Default t2.small', r: false},
|
|
37
|
+
{n: 'env', desc: 'Enviroment (dev,prod). This value is passed to the application.', r: false}
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
'update-app': {
|
|
41
|
+
desc: 'Update application',
|
|
42
|
+
exec: require('./commands/update_app').main,
|
|
43
|
+
args: [
|
|
44
|
+
{n: 'app', desc: 'Name of existing app', pattern: `[A-Za-z]{2,20}`, r: true},
|
|
45
|
+
{n: 'v', desc: 'Version to update', pattern: `[0-9]{1,20}`, r: true},
|
|
46
|
+
{n: 'path', desc: 'Path to app zip file or folder', r: true},
|
|
47
|
+
{n: 'stack', desc: 'Path to updated JSON or YML stack', r: false}
|
|
48
|
+
]
|
|
49
|
+
},
|
|
50
|
+
'update-stack': {
|
|
51
|
+
desc: 'Update stack',
|
|
52
|
+
exec: require('./commands/update_stack').main,
|
|
53
|
+
args: [
|
|
54
|
+
{n: 'app', desc: 'Name of existing app', pattern: `[A-Za-z]{2,20}`, r: true},
|
|
55
|
+
{n: 'v', desc: 'Version to update', pattern: `[0-9]{1,20}`, r: false},
|
|
56
|
+
{n: 'default', desc: 'Update default version', r: false},
|
|
57
|
+
{n: 'stack', desc: 'Path to updated JSON or YML stack', r: false}
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
'launch': {
|
|
61
|
+
desc: 'Launch application version to an instance',
|
|
62
|
+
exec: require('./commands/launch_app').main,
|
|
63
|
+
args: [
|
|
64
|
+
{n: 'app', desc: 'Name of existing app', pattern: `[A-Za-z]{2,20}`, r: true},
|
|
65
|
+
{n: 'domain', desc: 'Instance domain to launch to', r: true},
|
|
66
|
+
{n: 'v', desc: 'Version to launch', pattern: `[0-9]{1,20}`, r: true}
|
|
67
|
+
]
|
|
68
|
+
},
|
|
69
|
+
'inspect': {
|
|
70
|
+
desc: 'Get stack status and Ec2 console logs for an instance',
|
|
71
|
+
exec: require('./commands/inspect').main,
|
|
72
|
+
args: [
|
|
73
|
+
{n: 'app', desc: 'Name of existing app', pattern: `[A-Za-z]{2,20}`, r: true},
|
|
74
|
+
{n: 'domain', desc: 'Instance domain inspect', r: true}
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
'starter': {
|
|
78
|
+
desc: 'Get a starter template for an app',
|
|
79
|
+
exec: require('./commands/starter').main,
|
|
80
|
+
args: [
|
|
81
|
+
{n: 'type', desc: 'asg or static',pattern:`^asg$|^py$`, r: true},
|
|
82
|
+
{n: 'p', desc: 'Output path', r: true},
|
|
83
|
+
{n: 'l', desc: 'Language. node or py',pattern: '^node$|^py$', r: true}
|
|
84
|
+
]
|
|
85
|
+
},
|
|
86
|
+
/////
|
|
87
|
+
'delete-app': {
|
|
88
|
+
desc: 'Delete app',
|
|
89
|
+
exec: require('./commands/delete').delete_app,
|
|
90
|
+
args: [
|
|
91
|
+
{n: 'app', desc: 'Name of existing app', pattern: `[A-Za-z]{2,20}`, r: true}
|
|
92
|
+
]
|
|
93
|
+
},
|
|
94
|
+
'delete-instance': {
|
|
95
|
+
desc: 'Delete instance',
|
|
96
|
+
exec: require('./commands/delete').delete_instance,
|
|
97
|
+
args: [
|
|
98
|
+
{n: 'app', desc: 'Name of existing app', pattern: `[A-Za-z]{2,20}`, r: true},
|
|
99
|
+
{n: 'domain', desc: 'Instance domain', r: true},
|
|
100
|
+
]
|
|
101
|
+
},
|
|
102
|
+
'reset-stack': {
|
|
103
|
+
desc: 'Reset app stack to default',
|
|
104
|
+
exec: require('./commands/reset_stack').main,
|
|
105
|
+
args: [
|
|
106
|
+
{n: 'app', desc: 'Name of existing app', pattern: `[A-Za-z]{2,20}`, r: true}
|
|
107
|
+
]
|
|
108
|
+
},
|
|
109
|
+
'list-apps': {
|
|
110
|
+
desc: 'List all apps',
|
|
111
|
+
exec: require('./commands/list_apps').main
|
|
112
|
+
},
|
|
113
|
+
'isvalid': {
|
|
114
|
+
desc: 'Check if a cloudformation template is valid',
|
|
115
|
+
exec: require('./commands/utils').checkValidCF,
|
|
116
|
+
args: [
|
|
117
|
+
{n: 'p', desc: 'Path to cloudformation template', r: true}
|
|
118
|
+
]
|
|
119
|
+
},
|
|
120
|
+
'zip': {
|
|
121
|
+
desc: 'Zip a folder',
|
|
122
|
+
exec: require('./commands/utils').zip,
|
|
123
|
+
args: [
|
|
124
|
+
{n: 'p', desc: 'Path to folder', r: true},
|
|
125
|
+
{n: 'o', desc: 'Output path', r: true}
|
|
126
|
+
]
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function main(){
|
|
131
|
+
const orgExists = await readOrgInfo();
|
|
132
|
+
if (orgExists){
|
|
133
|
+
console.log(`>>>> ${process.env.orgName} <<<<`);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const args = parseArgs();
|
|
137
|
+
// Print info if no command given
|
|
138
|
+
if (!args.cmd){
|
|
139
|
+
printAllInfo();
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
// Exit if no org found
|
|
143
|
+
if (args.cmd !== 'init-org' && args.cmd !== 'set-org' && !orgExists){
|
|
144
|
+
console.log(`No organization found. Use init-org or set-org`);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Check for valid command
|
|
148
|
+
if (!Commands[args.cmd]){
|
|
149
|
+
console.log('Invalid command. Run without args to list commands');
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
// If Command has args, but none are give, print info
|
|
153
|
+
if (Commands[args.cmd].args && Object.keys(args.args).length == 0){
|
|
154
|
+
printCmdInfo(args.cmd);
|
|
155
|
+
return
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Validate args
|
|
159
|
+
const valid = validateArgs(args);
|
|
160
|
+
if (!valid){
|
|
161
|
+
console.log('FAILED:Invalid Arguments')
|
|
162
|
+
process.exit(1);
|
|
163
|
+
}
|
|
164
|
+
// If init or set, set ENV vars
|
|
165
|
+
if (args.cmd == 'init-org' || args.cmd == 'set-org'){
|
|
166
|
+
args.args.region = process.env.orgRegion = args.args.region || 'us-east-1';
|
|
167
|
+
process.env.orgName = args.args.name;
|
|
168
|
+
process.env.orgId = args.args.domain;
|
|
169
|
+
} else if (!orgExists){
|
|
170
|
+
console.log('Run init-org or set-org first');
|
|
171
|
+
return
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Exec Command
|
|
175
|
+
try{
|
|
176
|
+
await Commands[args.cmd].exec(args.args);
|
|
177
|
+
} catch (e){
|
|
178
|
+
const errLocation = e.stack ? e.stack.split('\n')[1].replace(/.*\\/,'') : e.at;
|
|
179
|
+
console.log('FAILED>>' + e.message + ' @ ' + errLocation);
|
|
180
|
+
process.exit(1)
|
|
181
|
+
}
|
|
182
|
+
console.log('SUCCESS')
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
/////////////////////////////////
|
|
187
|
+
////////////////////////////////
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
async function readOrgInfo(){
|
|
191
|
+
const orgPath = path.resolve(__dirname,'org.txt');
|
|
192
|
+
if (fs.existsSync(orgPath)){
|
|
193
|
+
const orgInfo = fs.readFileSync(orgPath,'utf-8').split(',');
|
|
194
|
+
process.env.orgName = orgInfo[0];
|
|
195
|
+
process.env.orgRegion = orgInfo[1];
|
|
196
|
+
process.env.orgBucket = await Params.getOrgBucket();
|
|
197
|
+
return true;
|
|
198
|
+
} else {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function parseArgs(){
|
|
204
|
+
var args = {
|
|
205
|
+
cmd: process.argv[2],
|
|
206
|
+
args: {}
|
|
207
|
+
};
|
|
208
|
+
for (let i=0;i<process.argv.length; i++){
|
|
209
|
+
if (process.argv[i][0] === '-'){
|
|
210
|
+
args.args[process.argv[i].replace('-','')] = null;
|
|
211
|
+
if (process.argv[i+1] && process.argv[i+1][0] !== '-'){
|
|
212
|
+
args.args[process.argv[i].replace('-','')] = process.argv[i+1];
|
|
213
|
+
i += 1
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return args;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function printAllInfo(){
|
|
221
|
+
Object.entries(Commands).forEach((c)=>{
|
|
222
|
+
console.log(`| ${c[0]} ${c[1].desc}`)
|
|
223
|
+
c[1].args.forEach(a=>{
|
|
224
|
+
const argName = a.r ? `${a.n}*` : a.n;
|
|
225
|
+
console.log(`\t-${argName}: ${a.desc}`)
|
|
226
|
+
})
|
|
227
|
+
console.log('-------\n');
|
|
228
|
+
})
|
|
229
|
+
console.log('\n*required')
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function printCmdInfo(cmd){
|
|
233
|
+
const comm = Commands[cmd].args;
|
|
234
|
+
console.log('\n' + cmd)
|
|
235
|
+
comm.forEach(a=>{
|
|
236
|
+
const argName = a.r ? `${a.n}*` : a.n;
|
|
237
|
+
console.log(`\t-${argName}: ${a.desc}`)
|
|
238
|
+
})
|
|
239
|
+
console.log('-------\n');
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function validateArgs(args){
|
|
243
|
+
const command = Commands[args.cmd];
|
|
244
|
+
if (!command.args){ return true }
|
|
245
|
+
for (let i=0; i<command.args.length;i++){
|
|
246
|
+
let carg = command.args[i];
|
|
247
|
+
const userArg = args.args[carg.n]
|
|
248
|
+
if (carg.pattern && userArg){
|
|
249
|
+
const rgx = new RegExp(carg.pattern);
|
|
250
|
+
if (!rgx.test(userArg)){
|
|
251
|
+
console.log(`Arg ${carg.n} does not match pattern ${carg.pattern}`);
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (carg.r && !userArg){
|
|
256
|
+
console.log('Missing required arg ' + carg.n);
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
|
|
221
263
|
main();
|
package/package.json
CHANGED
|
@@ -1,28 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "cloudmason",
|
|
3
|
-
"version": "0.0.1",
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "main.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"build": "node build.js"
|
|
8
|
-
},
|
|
9
|
-
"bin": {
|
|
10
|
-
"mason": "./main.js"
|
|
11
|
-
},
|
|
12
|
-
"repository": {
|
|
13
|
-
"type": "git",
|
|
14
|
-
"url": "https://github.com/kai-harvey/secure-saas.git"
|
|
15
|
-
},
|
|
16
|
-
"author": "Kai Harvey",
|
|
17
|
-
"license": "ISC",
|
|
18
|
-
"dependencies": {
|
|
19
|
-
"@aws-sdk/client-acm": "^3.418.0",
|
|
20
|
-
"@aws-sdk/client-cloudformation": "^3.418.0",
|
|
21
|
-
"@aws-sdk/client-ec2": "^3.416.0",
|
|
22
|
-
"@aws-sdk/client-iam": "^3.418.0",
|
|
23
|
-
"@aws-sdk/client-route-53": "^3.425.0",
|
|
24
|
-
"@aws-sdk/client-s3": "^3.418.0",
|
|
25
|
-
"@aws-sdk/client-ssm": "^3.421.0",
|
|
26
|
-
"adm-zip": "^0.5.10"
|
|
27
|
-
}
|
|
28
|
-
}
|
|
1
|
+
{"name":"cloudmason","version":"1.0.2","description":"","main":"main.js","scripts":{"build":"node build.js"},"bin":{"mason":"./main.js"},"repository":{"type":"git","url":"https://github.com/kai-harvey/secure-saas.git"},"author":"Kai Harvey","license":"ISC","dependencies":{"@aws-sdk/client-acm":"^3.418.0","@aws-sdk/client-auto-scaling":"^3.470.0","@aws-sdk/client-cloudformation":"^3.418.0","@aws-sdk/client-ec2":"^3.416.0","@aws-sdk/client-iam":"^3.418.0","@aws-sdk/client-route-53":"^3.425.0","@aws-sdk/client-s3":"^3.418.0","@aws-sdk/client-ssm":"^3.421.0","adm-zip":"^0.5.10"}}
|
package/test.bat
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
@REM node main.js init-org -name orgTheorem -
|
|
2
|
-
@REM node main.js
|
|
3
|
-
@REM node main.js
|
|
4
|
-
@REM node main.js new-instance -app
|
|
5
|
-
@REM node main.js update-app -app
|
|
6
|
-
@REM node main.js
|
|
7
|
-
@REM node main.js launch -app
|
|
8
|
-
@REM node main.js
|
|
9
|
-
@REM node main.js
|
|
1
|
+
@REM node main.js init-org -name orgTheorem -region us-west-2
|
|
2
|
+
@REM node main.js list-apps
|
|
3
|
+
@REM node main.js new-app -name ot -type asg
|
|
4
|
+
@REM node main.js new-instance -app ot -domain local.elmnts.xyz -region us-west-2 -admin kkh@kkh.io -env local
|
|
5
|
+
@REM node main.js update-app -app ot -v 1.0 -path ./commands/starters/asg_node
|
|
6
|
+
@REM node main.js update-stack -app ot -v 1.0 -stack ./commands/helpers/stacks/asg.yaml
|
|
7
|
+
@REM node main.js launch -app ot -v 1.0 -domain local.elmnts.xyz
|
|
8
|
+
@REM node main.js inspect -app ot -domain local.elmnts.xyz -run
|
|
9
|
+
@REM node main.js isvalid -p ./commands/helpers/stacks/asg.yaml
|
|
10
|
+
|
|
11
|
+
@REM node main.js reset-stack -app meantto
|
|
12
|
+
@REM node main.js delete-instance -app ot -domain ot.elmnts.xyz
|
|
13
|
+
@REM node main.js delete-app -app inc
|
|
14
|
+
@REM aws ec2 get-console-output --instance-id i-0fba7c360fc2de96f --region us-west-2 --latest
|
|
15
|
+
|
|
16
|
+
@REM node main.js starter -type asg -l node -p ../../myfirstapp
|
package/commands/delete_app.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
const { S3Client,PutObjectCommand } = require("@aws-sdk/client-s3");
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const path = require('path')
|
|
4
|
-
const Params = require('./helpers/params');
|
|
5
|
-
const S3 = require('./helpers/s3');
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
exports.main = async function(args){
|
|
9
|
-
// Check for existing app
|
|
10
|
-
const existingApp = await Params.getApp(args.name);
|
|
11
|
-
if (!existingApp){
|
|
12
|
-
console.log('Err: App does not exist ' + args.name);
|
|
13
|
-
throw new Error('App does not exist')
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
// Upload Stack
|
|
18
|
-
console.log(`Uploading ${args.type} to ${process.env.orgBucket}`)
|
|
19
|
-
const stackKey = `apps/${args.name.toLowerCase()}/default_stack.yaml`
|
|
20
|
-
await S3.uploadInfraText(stackKey,stackText);
|
|
21
|
-
|
|
22
|
-
// Update app config
|
|
23
|
-
console.log('Adding app params');
|
|
24
|
-
const nodev = args.node || '';
|
|
25
|
-
const pyv = args.py || '';
|
|
26
|
-
await Params.addApp(args.name,args.type,stackKey,nodev,pyv);
|
|
27
|
-
console.log(`Added ${args.name} with ${args.type} stack`)
|
|
28
|
-
}
|