-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdeploy
executable file
·671 lines (626 loc) · 23.1 KB
/
deploy
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
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
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
191
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
#!/usr/local/bin/node
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Libs
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
const gulp = require('gulp');
const preprocess = require('gulp-preprocess');
const http = require('request-promise');
const crypto = require('crypto');
const fs = require('fs');
const prompt = require('prompt-promise');
const colors = require('colors');
const args = process.argv.slice(2);
let config = {};
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Main
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
main();
async function main() {
printSplash();
await checkEnvironment();
config.keys = await getKeys();
deploy();
}
async function deploy() {
//stuff that doesn't set anything
try{
config.login = await pubnubLogin();
config.token = config.login.result.token;
config.userId = config.login.result.user.id;
} catch (e) {
console.error(e.black.bgRed);
console.error('Nothing has been deployed, this incident has not been logged'.black.bgRed);
process.exit();
}
//stuff that might set things
try{
config.accId = await getAccId();
config.appId = await getAppId();
config.keyId = await getKeyId();
config.blockId = await getBlockId();
config.handlers = await getEventHandlers();
config.signalCode = await buildSignalHandler();
config.delightCode = await buildDelightHandler();
console.log('Uploading Signal Handler...');
await uploadSignalHandler();
console.log('Uploading Delight...');
await uploadDelightHandler();
console.log('Restarting Block...');
await restart();
} catch (e) {
console.error(e.black.bgRed);
try {
console.error('Annotating failure in Librato...'.black.bgRed);
await librato('*FAILED* ' + process.env.USER + ' - ' + config.env + ' - ' + e);
} catch (e) {
console.error('That failed too lol'.black.bgRed);
}
process.exit();
}
try{
console.log('Annotating in Librato...');
await librato(process.env.USER + ' - ' + config.env);
} catch (e) {
console.error('Annotation Failed'.black.bgRed);
}
console.log('Deployment Complete!');
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Log an Annotation on Librato
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function librato(desc) {
return http({
method: 'POST',
uri: 'https://metrics-api.librato.com/v1/annotations' +
'/opengrowth.deploy.blocks',
body: {
title: 'Deployed JavaScript to BLOCKS',
description: desc
},
headers: {
'Authorization': "Basic " + new Buffer(
config.keys.librato.email + ":" + config.keys.librato.secret
).toString("base64")
},
json: true
}).catch(error => {
throw error.message;
});
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Restart the BLOCK
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function restart() {
return http({
method: 'POST',
uri: 'https://admin.pubnub.com/api/v1' +
`/blocks/key/${config.keyId}/` +
`block/${config.blockId}/start`,
body: {
block_id: config.blockId,
key_id: config.keyId,
action: 'start'
},
headers: {
'X-Session-Token': config.token
},
json: true
}).catch(error => {
console.error('Failed to restart block'.black.bgRed);
throw error.error.message.text;
});
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Compile Signal/Before Handler Code
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function buildSignalHandler() {
let buffer = '';
let keys = 'opengrowth.keys = ' + JSON.stringify(config.keys) + ';';
return new Promise((resolve, reject) => {
gulp.src([
'./handlers/signals.js', './helpers/*.js', './modules/*.js'
//, './delights/*.js'
//, './signals/*.js'
])
.pipe(preprocess({
context: {
ENV: config.env
}
}))
.on('end', data => {
resolve(buffer + keys)
})
.on('error', error => {
reject(error);
})
.on('data', bytes => {
buffer += bytes.contents.toString().trim();
});
console.log('Built Signal Handler');
});
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Compile Delight/After Handler Code
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function buildDelightHandler() {
let buffer = '';
let keys = 'opengrowth.keys = ' + JSON.stringify(config.keys) + ';'
return new Promise((resolve, reject) => {
gulp.src([
'./handlers/delights.js', './helpers/*.js', './modules/*.js', './delights/*.js', './signals/*.js'
])
.pipe(preprocess({
context: {
ENV: config.env
}
}))
.on('end', data => {
resolve(buffer + keys)
})
.on('error', error => {
reject(error)
})
.on('data', bytes => {
buffer += bytes.contents.toString().trim();
});
console.log('Built Delight Handler');
});
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Upload Signal/Before Handler Code
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function uploadSignalHandler() {
return http({
method: 'PUT',
json: true,
uri: 'https://admin.pubnub.com/api/v1' +
`/blocks/key/${config.keyId}/` +
`event_handler/${config.handlers.before}`,
headers: {
'X-Session-Token': config.token
},
body: {
key_id: config.keyId,
block_id: config.blockId,
id: config.handlers.before,
code: config.signalCode,
channels: 'opengrowth.signals',
event: 'js-before-publish',
type: 'js',
log_level: 'debug',
name: 'Signal Handler',
output: 'opengrowth.signals-info'
}
}).catch(error => {
console.error('Failed to upload signal handler'.black.bgRed);
throw error.error.message.text;
});
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Upload Delight/After Handler Code
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function uploadDelightHandler() {
return http({
method: 'PUT',
json: true,
uri: 'https://admin.pubnub.com/api/v1' +
`/blocks/key/${config.keyId}/` +
`event_handler/${config.handlers.after}`,
headers: {
'X-Session-Token': config.token
},
body: {
key_id: config.keyId,
block_id: config.blockId,
id: config.handlers.after,
code: config.delightCode,
channels: 'opengrowth.signals',
event: 'js-after-publish',
type: 'js',
log_level: 'debug',
name: 'Delight Handler',
output: 'opengrowth.delights-info'
}
}).catch(error => {
console.error('Failed to upload delight handler'.black.bgRed);
throw error.error.message.text;
});
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Get Event Handler ids
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
async function getEventHandlers() {
let list = await listEventHandlers(config.keyId, config.blockId);
list = list.payload[0].event_handlers;
let payload = {
'before': null,
'after': null
};
for (let item of list) {
if (item.event == 'js-before-publish') {
console.log('Open Growth Before Handler:', item.id);
payload.before = item.id;
} else if (item.event == 'js-after-publish') {
console.log('Open Growth After Handler:', item.id);
payload.after = item.id;
}
}
if (!payload.before) {
let handler = await createEventHandler(config.keyId, config.blockId, 'Signals Handler', 'js-before-publish');
payload.before = handler.payload.id;
console.log('Created Open Growth Before Handler:', payload.before);
}
if (payload.after == null) {
let handler2 = await createEventHandler(config.keyId, config.blockId, 'Delights Handler', 'js-after-publish');
payload.after = handler2.payload.id;
console.log('Created Open Growth After Handler:', payload.after);
}
return payload;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// List Event Handlers
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function listEventHandlers(keyId, blockId) {
return http({
method: 'GET',
json: true,
uri: 'https://admin.pubnub.com/api/v1' +
`/blocks/key/${keyId}` +
`/block/${blockId}`,
headers: {
'X-Session-Token': config.token
}
}).catch(error => {
console.error('Failed to list event handlers'.black.bgRed)
throw error;
});
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Create Event Handler
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function createEventHandler(keyId, blockId, name, event) {
return http({
method: 'POST',
json: true,
uri: 'https://admin.pubnub.com/api/v1' +
`/blocks/key/${keyId}/` +
`event_handler`,
headers: {
'X-Session-Token': config.token
},
body: {
key_id: keyId,
block_id: blockId,
type: 'js',
event: event,
channels: 'opengrowth.signals',
name: name,
code: "console.log('hi');",
output: 'output-0.5823105682419438'
}
}).catch(error => {
console.error('Failed to create event handler'.black.bgRed);
throw error.error.message;
});
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Get BLOCK id
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
async function getBlockId() {
let list = await listBlocks(config.keyId);
for (let block of list.payload) {
if (block.name == "Open Growth") {
config.block_id = block.id;
console.log('Open Growth Block ID:', block.id);
return block.id;
}
}
let block = await createBlock('Open Growth', '10x your business!', config.keyId);
console.log('Created Open Growth Block:', block.payload.id);
return block.payload.id;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Create a BLOCK
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function createBlock(name, desc, keyId) {
return http({
method: 'POST',
json: true,
uri: 'https://admin.pubnub.com/api/v1' +
`/blocks/key/${keyId}/` +
`block`,
headers: {
'X-Session-Token': config.token
},
body: {
key_id: keyId,
name: name,
description: desc
}
}).catch(error => {
console.error('Failed to create block'.black.bgRed)
throw error.error.message;
});
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Get key id
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
async function getKeyId() {
let list = await listApps(config.accId, config.token);
let env = (config.env == 'Bronze') ? config.env + ' - ' + process.env.USER : config.env;
for (let app of list.result) {
if (app.name == "Open Growth") {
for (let key of app.keys) {
if (key.properties.name == env) {
console.log('Open Growth Key ID:', key.id);
return key.id;
}
}
}
}
let key = await createKey(config.appId, env);
console.log('Created Open Growth Key (' + config.env + '):', key.result.id);
return key.result.id;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Get list of BLOCKS
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function listBlocks(keyId) {
return http({
method: 'GET',
json: true,
uri: 'https://admin.pubnub.com/api/v1' +
`/blocks/key/${keyId}/` +
`block`,
headers: {
'X-Session-Token': config.token
}
}).catch(error => {
console.error('Failed to list blocks'.black.bgRed);
throw error;
});
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Get account id
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
async function getAccId() {
let numbers = /^\d+$/;
let list = await listAccs(config.userId, config.token);
list = list.result.accounts;
for (let i=0;i<list.length;i++) {
console.log(i + ') ' + list[i].properties.company);
}
while(true){
try{
let choice = await prompt('Account: (0) ');
prompt.done();
if (!choice) choice = 0;
if (numbers.test(choice)) {
return list[choice].id;
} else {
console.log('Not a number');
}
}
catch (e) {
console.log('Not a choice');
}
}
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Get app id
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
async function getAppId() {
let list = await listApps(config.accId, config.token);
for (let app of list.result) {
if (app.name == "Open Growth") {
console.log('Open Growth App ID:', app.id);
return app.id;
}
}
let app = await createApp('Open Growth');
console.log('Created Open Growth App: ', app.result.id);
return app.result.id;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Create a key
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function createKey(appId, name) {
return http({
method: 'POST',
json: true,
uri: 'https://admin.pubnub.com/api/keys',
headers: {
'X-Session-Token': config.token
},
body: {
app_id: appId,
properties: {
name: name
}
}
}).catch(error => {
console.error('Failed to create key set'.black.bgRed);
throw error.error;
});
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Create an app
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function createApp(name) {
return http({
method: 'POST',
json: true,
uri: 'https://admin.pubnub.com/api/apps',
headers: {
'X-Session-Token': config.token
},
body: {
owner_id: config.accId,
name: name
}
}).catch(error => {
console.error('Failed to create app'.black.bgRed)
throw error.error;
});
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Login to PubNub
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function pubnubLogin() {
return http({
method: 'POST',
uri: 'https://admin.pubnub.com/api/me',
body: {
'email': config.keys.pubnub.email,
'password': config.keys.pubnub.password
},
json: true
}).catch(error => {
console.error('PubNub Login Failed'.black.bgRed);
throw error.error.error;
});
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Get list of accounts
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function listAccs(userId, token) {
return http({
method: 'GET',
json: true,
uri: `https://admin.pubnub.com/api/accounts?user_id=${userId}`,
headers: {
'X-Session-Token': token
}
}).catch(error => {
console.error('Failed to get account list'.black.bgRed);
throw error.error;
});
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Get list of apps
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function listApps(accId, token) {
return http({
method: 'GET',
json: true,
uri: `https://admin.pubnub.com/api/apps?owner_id=${accId}`,
headers: {
'X-Session-Token': token
}
}).catch(error => {
console.error('Failed to get app list'.black.bgRed);
throw error.error;
});
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Get user API keys
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
async function getKeys() {
let encryptedFileExists = fs.existsSync('keys.aes');
let password;
if (!encryptedFileExists) {
let unencryptedFile = fs.existsSync('keys.json');
if (!unencryptedFile) {
console.error('No keys files found, please create it from keys.json.example'.black.bgRed);
process.exit();
} else {
console.log('Keys file has not been encrypted, encrypting...');
password = await encrypt();
}
} else {
console.log('Encrypted keys file found');
}
if (!password) {
password = await prompt.password('Encryption Password: ', 'Δ');
}
let keys = await decrypt(password);
return keys;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Determine GOLD (production) or SILVER (testing) deployment
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
async function checkEnvironment() {
let env;
if (args.includes('--gold')) {
console.log('\tDeploying to Gold\t'.black.bgYellow);
try {
let confirm = await prompt.confirm('Are you sure? ');
env = 'Gold';
} catch (e) {
console.log('\tCancelling Deployment\t'.black.bgRed);
process.exit();
}
} else if (args.includes('--silver')) {
env = 'Silver';
console.log('\tDeploying to Silver\t'.black.bgWhite);
} else {
env = 'Bronze';
console.log('\tDeploying to Bronze\t'.black.bgGreen);
}
config.env = env;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Decrypt the users API key file
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function decrypt(password) {
let text = fs.readFileSync('./keys.aes', 'utf8')
let decipher = crypto.createDecipher('aes-256-ctr', password);
let dec = decipher.update(text, 'hex', 'utf8');
dec += decipher.final('utf8');
try {
let keys = JSON.parse(dec);
console.log('Keys Decrypted');
return keys;
} catch (e) {
console.error('Failed to decrypt keys, check your password'.black.bgRed);
process.exit();
}
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Encrypt the users API key file, return password if running during deploy
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
async function encrypt() {
let password = await prompt.password('Enter New Encryption Password: ');
prompt.done();
console.log('Creating keys.aes from keys.json...')
let text = fs.readFileSync('./keys.json', 'utf8')
let cipher = crypto.createCipher('aes-256-ctr', password);
let crypted = cipher.update(text, 'utf8', 'hex');
crypted += cipher.final('hex');
fs.writeFileSync('./keys.aes', crypted, 'utf8');
return password;
}
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Pretend we're in the 90s and keygen chiptunes are playing
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
function printSplash() {
process.stdout.write('\033c');
console.log("\n\n .````` ".green);
console.log(" ://oo+/- ".green);
console.log(" :++//++++: ".green);
console.log(" /++++/:++oo: ".green);
console.log(" `/+ooo+++:++/` ".green);
console.log(" `+o+o+/++++:: ".green);
console.log(" `+++++://o++: ".green);
console.log(" .++++/:+o+/o- .+. ".green);
console.log(" .++++//oooo:. -+++- ".green);
console.log(" -++++//++++: -/oooo- ".green);
console.log(" :oooo//++++- /o+/ooo+: ".green);
console.log(" /oooo/+oooo- +ooo+/o+oo: ".green);
console.log(" `/++oo/osooo. .oooo+:++++/ ".green);
console.log(" `/++o+/oooso` .ooooo:++++/` ".green);
console.log(" `/++++:+ooo+` .ooooo:++++/` ".green);
console.log(" .+++++:oooo/ `ooooo/++++/` ".green);
console.log(" .++++/:++++::::::::::::::/:::/++++//o+o++. ".green);
console.log(" -++++/:/+++:+++++++++++ooooooooooooooo+++++. ".green);
console.log(" -++++/:////-///++////////++++++++++++++//////. ".green);
console.log(" ./++/:///+++++++++++++++++oossssossosooo++++/. ".green);
console.log(" `/::/+//+///+++++++oo+++ooosoosssosoooo+++/` ".green);
console.log(" `......................-.---...------...` ".green);
console.log(" ____ ______ __ __ ".green);
console.log(" / __ \\____ ___ ____ / ____/________ _ __/ /_/ /_ ".green);
console.log(" / / / / __ \\/ _ \\/ __ \\ / / __/ ___/ __ \\ | /| / / __/ __ \\ ".green);
console.log(" / /_/ / /_/ / __/ / / / / /_/ / / / /_/ / |/ |/ / /_/ / / / ".green);
console.log(" \\____/ .___/\\___/_/ /_/ \\____/_/ \\____/|__/|__/\\__/_/ /_/ ".green);
console.log(" /_/ \n\n".green);
}