@hotglue/cli 1.0.32 → 1.0.34
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/README.md +1 -1
- package/lib/cjs/index.js +9 -8
- package/lib/cjs/index.js.map +1 -1
- package/lib/mjs/index.js +9 -8
- package/lib/mjs/index.js.map +1 -1
- package/package.json +2 -1
- package/lib/commands/config/set.js +0 -82
- package/lib/commands/config.js +0 -69
- package/lib/commands/env/deploy.js +0 -162
- package/lib/commands/env/download.js +0 -169
- package/lib/commands/env.js +0 -32
- package/lib/commands/etl/delete.js +0 -171
- package/lib/commands/etl/deploy.js +0 -263
- package/lib/commands/etl/download.js +0 -205
- package/lib/commands/etl.js +0 -32
- package/lib/commands/flows/list.js +0 -104
- package/lib/commands/flows.js +0 -32
- package/lib/commands/jobs/download.js +0 -188
- package/lib/commands/jobs/list.js +0 -108
- package/lib/commands/jobs.js +0 -32
- package/lib/commands/snapshots/deploy.js +0 -202
- package/lib/commands/snapshots/download.js +0 -213
- package/lib/commands/snapshots.js +0 -32
- package/lib/commands/tenants/custom-etl.js +0 -183
- package/lib/commands/tenants/custom-field-map.js +0 -191
- package/lib/commands/tenants/delete.js +0 -150
- package/lib/commands/tenants/list.js +0 -97
- package/lib/commands/tenants/updateConfig.js +0 -188
- package/lib/commands/tenants.js +0 -32
- package/lib/helpers/api.js +0 -326
- package/lib/helpers/baseBuilder.js +0 -30
- package/lib/helpers/config.js +0 -105
- package/lib/helpers/debug.js +0 -19
- package/lib/helpers/descriptions.js +0 -137
- package/lib/helpers/flow.js +0 -32
- package/lib/helpers/print.js +0 -92
- package/lib/helpers/utils.js +0 -245
- package/lib/index.js +0 -12
- package/lib/main.js +0 -27
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.handler = exports.desc = exports.command = exports.builder = void 0;
|
|
7
|
-
|
|
8
|
-
var _util = require("util");
|
|
9
|
-
|
|
10
|
-
var _debug = _interopRequireDefault(require("../../helpers/debug"));
|
|
11
|
-
|
|
12
|
-
var _ora = _interopRequireDefault(require("ora"));
|
|
13
|
-
|
|
14
|
-
var _axios = _interopRequireDefault(require("axios/dist/node/axios.cjs"));
|
|
15
|
-
|
|
16
|
-
var _cliTable = _interopRequireDefault(require("cli-table"));
|
|
17
|
-
|
|
18
|
-
var _descriptions = _interopRequireDefault(require("../../helpers/descriptions"));
|
|
19
|
-
|
|
20
|
-
var _print = require("../../helpers/print");
|
|
21
|
-
|
|
22
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
-
|
|
24
|
-
const debug = (0, _debug.default)('commands:flows:list');
|
|
25
|
-
const command = 'list';
|
|
26
|
-
exports.command = command;
|
|
27
|
-
const desc = 'List flows';
|
|
28
|
-
exports.desc = desc;
|
|
29
|
-
|
|
30
|
-
const builder = async yargs => {
|
|
31
|
-
debug('builder', command);
|
|
32
|
-
return yargs.option('tenant', { ..._descriptions.default.options['tenant'].config
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
exports.builder = builder;
|
|
37
|
-
|
|
38
|
-
const handler = async argv => {
|
|
39
|
-
debug('handler', command, argv);
|
|
40
|
-
const {
|
|
41
|
-
hg,
|
|
42
|
-
json,
|
|
43
|
-
apikey,
|
|
44
|
-
env,
|
|
45
|
-
tenant
|
|
46
|
-
} = argv;
|
|
47
|
-
const {
|
|
48
|
-
clientApiBaseUri
|
|
49
|
-
} = hg;
|
|
50
|
-
let message;
|
|
51
|
-
let spinner = (0, _ora.default)();
|
|
52
|
-
|
|
53
|
-
try {
|
|
54
|
-
// 1. get data from client-api backend
|
|
55
|
-
message = (0, _print.themed)(`Retrieving ${!tenant ? `the` : `${(0, _print.themed)(tenant, 'info')} tenant's`} flows for environment: ${(0, _print.themed)(env, 'info')}`); // todo: look into changing when if client-api combined these two endpoints
|
|
56
|
-
|
|
57
|
-
const uri = `${clientApiBaseUri}/${env}/flows/${tenant ? `linked?user_id=${tenant}` : `supported`}`;
|
|
58
|
-
debug('requesting:', uri);
|
|
59
|
-
!json && spinner.start((0, _print.themed)(`In progress: ${message}...`, 'secondary'));
|
|
60
|
-
const {
|
|
61
|
-
data
|
|
62
|
-
} = await _axios.default.get(uri, {
|
|
63
|
-
headers: {
|
|
64
|
-
'x-api-key': apikey
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
!json && spinner.succeed((0, _print.themed)(`Finished: ${message}.`, 'secondary'));
|
|
68
|
-
debug('response-data', data); // exit if there is no data
|
|
69
|
-
|
|
70
|
-
if (!data || data.length === 0) {
|
|
71
|
-
json ? (0, _print.printJSON)([]) : spinner.warn((0, _print.themed)(`Warning: ${(0, _print.themed)('No flows for specified environment and tenant')}.`, 'secondary'));
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (json) {
|
|
76
|
-
(0, _print.printJSON)(data);
|
|
77
|
-
} else {
|
|
78
|
-
// generate results table
|
|
79
|
-
const table = new _cliTable.default({
|
|
80
|
-
head: ['ID', 'Name', 'isPush', 'Taps', 'Targets']
|
|
81
|
-
});
|
|
82
|
-
data.forEach(item => table.push([item.id, item.name || '', item.type || false, item.taps ? (0, _util.inspect)(item.taps) : '', item.targets ? (0, _util.inspect)(item.targets) : 'none'])); // print results
|
|
83
|
-
|
|
84
|
-
console.log(table.toString());
|
|
85
|
-
}
|
|
86
|
-
} catch (err) {
|
|
87
|
-
if (json) {
|
|
88
|
-
(0, _print.printJSON)({
|
|
89
|
-
status: 'error',
|
|
90
|
-
error: err
|
|
91
|
-
});
|
|
92
|
-
} else {
|
|
93
|
-
spinner.fail((0, _print.themed)(`Error: ${message}.`, 'secondary'));
|
|
94
|
-
(0, _print.pr)((0, _print.themed)(`Message: ${(0, _print.themed)(err.message)}`, 'secondary'));
|
|
95
|
-
debug(err);
|
|
96
|
-
|
|
97
|
-
if (err && err.response && err.response.data) {
|
|
98
|
-
debug('response', err.response.data);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
exports.handler = handler;
|
package/lib/commands/flows.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.handler = exports.desc = exports.command = exports.builder = void 0;
|
|
7
|
-
|
|
8
|
-
var _debug = _interopRequireDefault(require("../helpers/debug"));
|
|
9
|
-
|
|
10
|
-
var _baseBuilder = require("../helpers/baseBuilder");
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
const debug = (0, _debug.default)('commands:flows');
|
|
15
|
-
const command = 'flows <action>';
|
|
16
|
-
exports.command = command;
|
|
17
|
-
const desc = 'Manage flows';
|
|
18
|
-
exports.desc = desc;
|
|
19
|
-
|
|
20
|
-
const builder = async function (yargs) {
|
|
21
|
-
debug('builder', command);
|
|
22
|
-
const base = await (0, _baseBuilder.baseApiBuilder)(yargs);
|
|
23
|
-
return base.commandDir('flows');
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
exports.builder = builder;
|
|
27
|
-
|
|
28
|
-
const handler = async function (argv) {
|
|
29
|
-
debug('handler', command, argv);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
exports.handler = handler;
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.handler = exports.desc = exports.command = exports.builder = void 0;
|
|
7
|
-
|
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
|
-
var _promises = require("fs/promises");
|
|
11
|
-
|
|
12
|
-
var _fs = require("fs");
|
|
13
|
-
|
|
14
|
-
var _debug = _interopRequireDefault(require("../../helpers/debug"));
|
|
15
|
-
|
|
16
|
-
var _ora = _interopRequireDefault(require("ora"));
|
|
17
|
-
|
|
18
|
-
var _cliTable = _interopRequireDefault(require("cli-table"));
|
|
19
|
-
|
|
20
|
-
var _awsSdk = _interopRequireDefault(require("aws-sdk"));
|
|
21
|
-
|
|
22
|
-
var _eachSeries = _interopRequireDefault(require("async/eachSeries"));
|
|
23
|
-
|
|
24
|
-
var _descriptions = _interopRequireDefault(require("../../helpers/descriptions"));
|
|
25
|
-
|
|
26
|
-
var _print = require("../../helpers/print");
|
|
27
|
-
|
|
28
|
-
var _api = require("../../helpers/api");
|
|
29
|
-
|
|
30
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
|
-
|
|
32
|
-
const debug = (0, _debug.default)('commands:jobs:download');
|
|
33
|
-
const command = 'download <jobroot>';
|
|
34
|
-
exports.command = command;
|
|
35
|
-
const desc = 'Download Job files';
|
|
36
|
-
exports.desc = desc;
|
|
37
|
-
|
|
38
|
-
const builder = async yargs => {
|
|
39
|
-
debug('builder', command);
|
|
40
|
-
return yargs.option('downloadTo', _descriptions.default.options['downloadTo'].config); // .option('jobroot', descriptions.options['jobroot'].config)
|
|
41
|
-
// .demandOption('jobroot', descriptions.options['jobroot'].demandText)
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
exports.builder = builder;
|
|
45
|
-
|
|
46
|
-
const handler = async argv => {
|
|
47
|
-
debug('handler', command, argv);
|
|
48
|
-
const {
|
|
49
|
-
hg,
|
|
50
|
-
json,
|
|
51
|
-
apikey,
|
|
52
|
-
env,
|
|
53
|
-
jobroot,
|
|
54
|
-
downloadTo
|
|
55
|
-
} = argv;
|
|
56
|
-
const {
|
|
57
|
-
clientApiBaseUri
|
|
58
|
-
} = hg;
|
|
59
|
-
let message;
|
|
60
|
-
let spinner = (0, _ora.default)();
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
// 1. get STS credentials
|
|
64
|
-
message = (0, _print.themed)(`Verifying user and authorizing`);
|
|
65
|
-
!json && spinner.start((0, _print.themed)(`In progress: ${message}...`, 'secondary'));
|
|
66
|
-
const {
|
|
67
|
-
accessKeyId,
|
|
68
|
-
secretAccessKey,
|
|
69
|
-
sessionToken
|
|
70
|
-
} = await (0, _api.genCredentialsOnClientApi)({
|
|
71
|
-
debug,
|
|
72
|
-
baseUri: clientApiBaseUri,
|
|
73
|
-
task: 'job-download',
|
|
74
|
-
env,
|
|
75
|
-
apikey,
|
|
76
|
-
jobroot
|
|
77
|
-
}); // get data from AWS bucket
|
|
78
|
-
|
|
79
|
-
const s3 = new _awsSdk.default.S3({
|
|
80
|
-
accessKeyId,
|
|
81
|
-
secretAccessKey,
|
|
82
|
-
sessionToken
|
|
83
|
-
});
|
|
84
|
-
!json && spinner.succeed((0, _print.themed)(`Finished: ${message}.`, 'secondary')); // 2. get list of available files
|
|
85
|
-
|
|
86
|
-
message = (0, _print.themed)(`Scanning for downloadable files`);
|
|
87
|
-
!json && spinner.start((0, _print.themed)(`In progress: ${message}...`, 'secondary'));
|
|
88
|
-
const params = {
|
|
89
|
-
Bucket: env,
|
|
90
|
-
Prefix: jobroot
|
|
91
|
-
};
|
|
92
|
-
const {
|
|
93
|
-
Contents: filesList
|
|
94
|
-
} = await s3.listObjectsV2(params).promise();
|
|
95
|
-
debug('res', filesList);
|
|
96
|
-
|
|
97
|
-
if (!filesList || filesList.length === 0) {
|
|
98
|
-
if (json) {
|
|
99
|
-
(0, _print.printJSON)({
|
|
100
|
-
status: 'error',
|
|
101
|
-
error: 'Nothing to download!'
|
|
102
|
-
});
|
|
103
|
-
} else {
|
|
104
|
-
spinner.fail((0, _print.themed)(`Error: ${message}.`, 'secondary'));
|
|
105
|
-
(0, _print.pr)((0, _print.themed)(`Message: ${(0, _print.themed)('Nothing to download!')}`, 'secondary'));
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
!json && spinner.succeed((0, _print.themed)(`Finished: ${message}.`, 'secondary'));
|
|
112
|
-
|
|
113
|
-
if (!json) {
|
|
114
|
-
// print remote files
|
|
115
|
-
const table = new _cliTable.default({
|
|
116
|
-
head: ['File', 'Size', 'LastModified']
|
|
117
|
-
});
|
|
118
|
-
filesList.forEach(item => {
|
|
119
|
-
const subPath = item.Key.substring(jobroot.length + 1); // const details = { LastModified: item.LastModified, Size: item.Size };
|
|
120
|
-
|
|
121
|
-
table.push([subPath, item.Size, item.LastModified.toLocaleString('en-US')]); // JSON.stringify(details, undefined, 2)]);
|
|
122
|
-
});
|
|
123
|
-
console.log(table.toString());
|
|
124
|
-
} // 3. download job files one-by-one
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const localRoot = _path.default.resolve(process.cwd(), downloadTo, _path.default.basename(jobroot));
|
|
128
|
-
|
|
129
|
-
await (0, _eachSeries.default)( // Filter out tap/target config files
|
|
130
|
-
filesList.filter(({
|
|
131
|
-
Key
|
|
132
|
-
}) => {
|
|
133
|
-
// Filter out all *-config.json files in the root of "jobroo"
|
|
134
|
-
const regex = new RegExp(`${jobroot}/([^\/]+)-config\.json`);
|
|
135
|
-
return !regex.test(Key);
|
|
136
|
-
}), async item => {
|
|
137
|
-
message = (0, _print.themed)(`Downloading file: ${(0, _print.themed)(item.Key, 'info')}`);
|
|
138
|
-
!json && spinner.start((0, _print.themed)(`In progress: ${message}...`, 'secondary'));
|
|
139
|
-
|
|
140
|
-
const file = _path.default.resolve(localRoot, item.Key.substring(jobroot.length + 1));
|
|
141
|
-
|
|
142
|
-
debug('file', file); // ensure destination folder exists
|
|
143
|
-
|
|
144
|
-
await (0, _promises.mkdir)(_path.default.dirname(file), {
|
|
145
|
-
recursive: true
|
|
146
|
-
}); // download s3 object into destination folder
|
|
147
|
-
|
|
148
|
-
const fileStream = s3.getObject({
|
|
149
|
-
Bucket: env,
|
|
150
|
-
Key: item.Key
|
|
151
|
-
}).createReadStream();
|
|
152
|
-
const writableStream = (0, _fs.createWriteStream)(file, {
|
|
153
|
-
flags: 'w'
|
|
154
|
-
});
|
|
155
|
-
fileStream.pipe(writableStream);
|
|
156
|
-
!json && spinner.succeed((0, _print.themed)(`Finished: ${message}.`, 'secondary'));
|
|
157
|
-
}); // print final success message
|
|
158
|
-
|
|
159
|
-
if (json) {
|
|
160
|
-
(0, _print.printJSON)({
|
|
161
|
-
status: 'success',
|
|
162
|
-
downloadedFiles: filesList.map(({
|
|
163
|
-
Key
|
|
164
|
-
}) => Key)
|
|
165
|
-
});
|
|
166
|
-
} else {
|
|
167
|
-
message = (0, _print.themed)(`Downloading job files.`);
|
|
168
|
-
spinner.succeed((0, _print.themed)(`Finished: ${message}`, 'secondary'));
|
|
169
|
-
}
|
|
170
|
-
} catch (err) {
|
|
171
|
-
if (json) {
|
|
172
|
-
(0, _print.printJSON)({
|
|
173
|
-
status: 'error',
|
|
174
|
-
error: err
|
|
175
|
-
});
|
|
176
|
-
} else {
|
|
177
|
-
spinner.fail((0, _print.themed)(`Error: ${message}.`, 'secondary'));
|
|
178
|
-
(0, _print.pr)((0, _print.themed)(`Message: ${(0, _print.themed)(err.message)}`, 'secondary'));
|
|
179
|
-
debug(err);
|
|
180
|
-
|
|
181
|
-
if (err && err.response && err.response.data) {
|
|
182
|
-
debug('response', err.response.data);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
exports.handler = handler;
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.handler = exports.desc = exports.command = exports.builder = void 0;
|
|
7
|
-
|
|
8
|
-
var _debug = _interopRequireDefault(require("../../helpers/debug"));
|
|
9
|
-
|
|
10
|
-
var _ora = _interopRequireDefault(require("ora"));
|
|
11
|
-
|
|
12
|
-
var _axios = _interopRequireDefault(require("axios/dist/node/axios.cjs"));
|
|
13
|
-
|
|
14
|
-
var _cliTable = _interopRequireDefault(require("cli-table"));
|
|
15
|
-
|
|
16
|
-
var _descriptions = _interopRequireDefault(require("../../helpers/descriptions"));
|
|
17
|
-
|
|
18
|
-
var _print = require("../../helpers/print");
|
|
19
|
-
|
|
20
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
|
-
const debug = (...args) => {
|
|
23
|
-
const debug = (0, _debug.default)('commands:jobs:list');
|
|
24
|
-
debug(...args);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const command = 'list';
|
|
28
|
-
exports.command = command;
|
|
29
|
-
const desc = 'List jobs';
|
|
30
|
-
exports.desc = desc;
|
|
31
|
-
|
|
32
|
-
const builder = async yargs => {
|
|
33
|
-
debug('builder', command);
|
|
34
|
-
return yargs.option('flow', _descriptions.default.options['flow'].config).demandOption('flow', _descriptions.default.options['flow'].demandText).option('tenant', { ..._descriptions.default.options['tenant'].config,
|
|
35
|
-
default: 'default'
|
|
36
|
-
}).option('count', _descriptions.default.options['count'].config);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
exports.builder = builder;
|
|
40
|
-
|
|
41
|
-
const handler = async argv => {
|
|
42
|
-
debug('handler', command, argv);
|
|
43
|
-
const {
|
|
44
|
-
hg,
|
|
45
|
-
json,
|
|
46
|
-
apikey,
|
|
47
|
-
env,
|
|
48
|
-
flow,
|
|
49
|
-
tenant,
|
|
50
|
-
count
|
|
51
|
-
} = argv;
|
|
52
|
-
const {
|
|
53
|
-
clientApiBaseUri
|
|
54
|
-
} = hg;
|
|
55
|
-
let message;
|
|
56
|
-
let spinner = (0, _ora.default)();
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
// 1. get data from client-api backend
|
|
60
|
-
message = (0, _print.themed)(`Retrieving jobs for environment: ${(0, _print.themed)(env, 'info')} flow: ${(0, _print.themed)(flow, 'info')} tenant: ${(0, _print.themed)(tenant, 'info')}...`);
|
|
61
|
-
const uri = `${clientApiBaseUri}/${env}/${flow}/${tenant}/jobs${count ? `?count=${count}` : ''}`;
|
|
62
|
-
debug('requesting:', uri);
|
|
63
|
-
!json && spinner.start((0, _print.themed)(`In progress: ${message}...`, 'secondary'));
|
|
64
|
-
const {
|
|
65
|
-
data
|
|
66
|
-
} = await _axios.default.get(uri, {
|
|
67
|
-
headers: {
|
|
68
|
-
'x-api-key': apikey
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
!json && spinner.succeed((0, _print.themed)(`Finished: ${message}.`, 'secondary'));
|
|
72
|
-
debug('response-data', data); // exit if there is no data
|
|
73
|
-
|
|
74
|
-
if (!data || data.length === 0) {
|
|
75
|
-
json ? (0, _print.printJSON)([]) : spinner.warn((0, _print.themed)(`Warning: ${(0, _print.themed)('No jobs for the specified environment, flow and tenant')}.`, 'secondary'));
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (json) {
|
|
80
|
-
(0, _print.printJSON)(data);
|
|
81
|
-
} else {
|
|
82
|
-
// generate results table
|
|
83
|
-
const table = new _cliTable.default({
|
|
84
|
-
head: ['name', 'details']
|
|
85
|
-
});
|
|
86
|
-
data.forEach(item => table.push([item.job_name, JSON.stringify(item, undefined, 2)])); // print results
|
|
87
|
-
|
|
88
|
-
console.log(table.toString());
|
|
89
|
-
}
|
|
90
|
-
} catch (err) {
|
|
91
|
-
if (json) {
|
|
92
|
-
(0, _print.printJSON)({
|
|
93
|
-
status: 'error',
|
|
94
|
-
error: err
|
|
95
|
-
});
|
|
96
|
-
} else {
|
|
97
|
-
spinner.fail((0, _print.themed)(`Error: ${message}.`, 'secondary'));
|
|
98
|
-
(0, _print.pr)((0, _print.themed)(`Message: ${(0, _print.themed)(err.message)}`, 'secondary'));
|
|
99
|
-
debug(err);
|
|
100
|
-
|
|
101
|
-
if (err && err.response && err.response.data) {
|
|
102
|
-
debug('response', err.response.data);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
exports.handler = handler;
|
package/lib/commands/jobs.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.handler = exports.desc = exports.command = exports.builder = void 0;
|
|
7
|
-
|
|
8
|
-
var _debug = _interopRequireDefault(require("../helpers/debug"));
|
|
9
|
-
|
|
10
|
-
var _baseBuilder = require("../helpers/baseBuilder");
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
const debug = (0, _debug.default)('commands:jobs');
|
|
15
|
-
const command = 'jobs <action>';
|
|
16
|
-
exports.command = command;
|
|
17
|
-
const desc = 'Manage ETL jobs';
|
|
18
|
-
exports.desc = desc;
|
|
19
|
-
|
|
20
|
-
const builder = async function (yargs) {
|
|
21
|
-
debug('builder', command);
|
|
22
|
-
const base = await (0, _baseBuilder.baseApiBuilder)(yargs);
|
|
23
|
-
return base.commandDir('jobs');
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
exports.builder = builder;
|
|
27
|
-
|
|
28
|
-
const handler = async function (argv) {
|
|
29
|
-
debug('handler', command, argv);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
exports.handler = handler;
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.handler = exports.desc = exports.command = exports.builder = void 0;
|
|
7
|
-
|
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
|
-
var _promises = require("fs/promises");
|
|
11
|
-
|
|
12
|
-
var _debug = _interopRequireDefault(require("../../helpers/debug"));
|
|
13
|
-
|
|
14
|
-
var _ora = _interopRequireDefault(require("ora"));
|
|
15
|
-
|
|
16
|
-
var _axios = _interopRequireDefault(require("axios/dist/node/axios.cjs"));
|
|
17
|
-
|
|
18
|
-
var _awsSdk = _interopRequireDefault(require("aws-sdk"));
|
|
19
|
-
|
|
20
|
-
var _cliTable = _interopRequireDefault(require("cli-table"));
|
|
21
|
-
|
|
22
|
-
var _utils = require("../../helpers/utils");
|
|
23
|
-
|
|
24
|
-
var _descriptions = _interopRequireDefault(require("../../helpers/descriptions"));
|
|
25
|
-
|
|
26
|
-
var _print = require("../../helpers/print");
|
|
27
|
-
|
|
28
|
-
var _api = require("../../helpers/api");
|
|
29
|
-
|
|
30
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
|
-
|
|
32
|
-
const debug = (0, _debug.default)('commands:snapshots:deploy');
|
|
33
|
-
const command = 'deploy';
|
|
34
|
-
exports.command = command;
|
|
35
|
-
const desc = 'Deploy Snapshots';
|
|
36
|
-
exports.desc = desc;
|
|
37
|
-
|
|
38
|
-
const builder = async yargs => {
|
|
39
|
-
debug('builder', command);
|
|
40
|
-
return yargs.option('tenant', { ..._descriptions.default.options['tenant'].config,
|
|
41
|
-
default: 'default'
|
|
42
|
-
}).option('sourceFolder', _descriptions.default.options['sourceFolder'].config).demandOption('sourceFolder', _descriptions.default.options['sourceFolder'].demandText);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
exports.builder = builder;
|
|
46
|
-
|
|
47
|
-
const handler = async argv => {
|
|
48
|
-
debug('handler', command, argv);
|
|
49
|
-
const {
|
|
50
|
-
hg,
|
|
51
|
-
json,
|
|
52
|
-
apikey,
|
|
53
|
-
env,
|
|
54
|
-
tenant,
|
|
55
|
-
sourceFolder
|
|
56
|
-
} = argv;
|
|
57
|
-
const {
|
|
58
|
-
clientApiBaseUri
|
|
59
|
-
} = hg;
|
|
60
|
-
let message;
|
|
61
|
-
let spinner = (0, _ora.default)();
|
|
62
|
-
|
|
63
|
-
const folderPrefix = _path.default.resolve(process.cwd(), sourceFolder);
|
|
64
|
-
|
|
65
|
-
try {
|
|
66
|
-
message = (0, _print.themed)(`Deploying Snapshots for Tenant ${(0, _print.themed)(tenant, 'info')} to ${(0, _print.themed)(env, 'info')}`);
|
|
67
|
-
!json && spinner.info((0, _print.themed)(`Info: ${message}.`, 'secondary')); // 1. build list of deployable files
|
|
68
|
-
|
|
69
|
-
const deployableFiles = await (0, _utils.getFolderFiles)(folderPrefix, {
|
|
70
|
-
recursive: true
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
if (deployableFiles.length === 0) {
|
|
74
|
-
json ? (0, _print.printJSON)({
|
|
75
|
-
status: 'error',
|
|
76
|
-
error: 'There are no files to deploy at the specified location!'
|
|
77
|
-
}) : spinner.fail((0, _print.themed)(`Error: ${(0, _print.themed)('There are no files to deploy at the specified location!')}.`, 'secondary'));
|
|
78
|
-
return;
|
|
79
|
-
} // 2. get STS credentials
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
message = (0, _print.themed)(`Verifying user and authorizing`);
|
|
83
|
-
const {
|
|
84
|
-
accessKeyId,
|
|
85
|
-
secretAccessKey,
|
|
86
|
-
sessionToken
|
|
87
|
-
} = await (0, _api.genCredentialsOnClientApi)({
|
|
88
|
-
debug,
|
|
89
|
-
baseUri: clientApiBaseUri,
|
|
90
|
-
task: 'snapshot-deploy',
|
|
91
|
-
env,
|
|
92
|
-
tenant,
|
|
93
|
-
apikey
|
|
94
|
-
});
|
|
95
|
-
!json && spinner.succeed((0, _print.themed)(`Finished: ${message}.`, 'secondary')); // create authenticated S3 instance
|
|
96
|
-
|
|
97
|
-
const s3 = new _awsSdk.default.S3({
|
|
98
|
-
accessKeyId,
|
|
99
|
-
secretAccessKey,
|
|
100
|
-
sessionToken
|
|
101
|
-
}); // 3. verify tenant is valid
|
|
102
|
-
|
|
103
|
-
message = (0, _print.themed)(`Validating tenant exists`);
|
|
104
|
-
!json && spinner.start((0, _print.themed)(`In progress: ${message}...`, 'secondary'));
|
|
105
|
-
|
|
106
|
-
try {
|
|
107
|
-
const {
|
|
108
|
-
CommonPrefixes: tenantFolders
|
|
109
|
-
} = await s3.listObjectsV2({
|
|
110
|
-
Bucket: env,
|
|
111
|
-
Prefix: `${tenant}/`,
|
|
112
|
-
Delimiter: '/'
|
|
113
|
-
}).promise();
|
|
114
|
-
if (tenantFolders.length === 0) throw new Error('Invalid tenant');
|
|
115
|
-
} catch (err) {
|
|
116
|
-
debug('err', err);
|
|
117
|
-
throw new Error(`Tenant doesn't exist. Please check your tenant (-u) argument.`);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
!json && spinner.succeed((0, _print.themed)(`Finished: ${message}.`, 'secondary'));
|
|
121
|
-
const rootKey = `${tenant}/snapshots/`;
|
|
122
|
-
const table = new _cliTable.default({
|
|
123
|
-
head: ['File', 'Status']
|
|
124
|
-
}); // 4. cleanup old files
|
|
125
|
-
|
|
126
|
-
message = (0, _print.themed)(`Preparing deployment target`);
|
|
127
|
-
!json && spinner.start((0, _print.themed)(`In progress: ${message}...`, 'secondary'));
|
|
128
|
-
const {
|
|
129
|
-
Contents
|
|
130
|
-
} = await s3.listObjectsV2({
|
|
131
|
-
Bucket: env,
|
|
132
|
-
Prefix: `${rootKey}`
|
|
133
|
-
}).promise();
|
|
134
|
-
!json && spinner.stop();
|
|
135
|
-
debug('contents', Contents);
|
|
136
|
-
!json && spinner.start((0, _print.themed)(`In progress: ${message}...`, 'secondary'));
|
|
137
|
-
const filesToDelete = Contents.map(item => ({
|
|
138
|
-
Key: item.Key
|
|
139
|
-
}));
|
|
140
|
-
|
|
141
|
-
if (filesToDelete.length > 0) {
|
|
142
|
-
const delParams = {
|
|
143
|
-
Bucket: env,
|
|
144
|
-
Delete: {
|
|
145
|
-
Objects: filesToDelete,
|
|
146
|
-
Quiet: true
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
await s3.deleteObjects(delParams).promise();
|
|
150
|
-
filesToDelete.forEach(({
|
|
151
|
-
Key
|
|
152
|
-
}) => table.push([Key.substring(rootKey.length), (0, _print.themed)('Deleted', 'warn')]));
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
!json && spinner.succeed((0, _print.themed)(`Finished: ${message}.`, 'secondary')); // 5. upload new files
|
|
156
|
-
|
|
157
|
-
for await (const file of deployableFiles) {
|
|
158
|
-
const relativePath = _path.default.relative(sourceFolder, file);
|
|
159
|
-
|
|
160
|
-
const key = `${rootKey}${relativePath}`;
|
|
161
|
-
message = (0, _print.themed)(`Deploying file: ${(0, _print.themed)(relativePath, 'info')}`);
|
|
162
|
-
!json && spinner.start((0, _print.themed)(`In progress: ${message}...`, 'secondary'));
|
|
163
|
-
const readBuffer = await (0, _promises.readFile)(file);
|
|
164
|
-
const params = {
|
|
165
|
-
Bucket: env,
|
|
166
|
-
Key: key,
|
|
167
|
-
Body: readBuffer
|
|
168
|
-
};
|
|
169
|
-
const res = await s3.putObject(params).promise();
|
|
170
|
-
!json && spinner.succeed((0, _print.themed)(`Finished: ${message}.`, 'secondary'));
|
|
171
|
-
debug('s3-put-res', res);
|
|
172
|
-
table.push([relativePath, (0, _print.themed)('Deployed', 'info')]);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (json) {
|
|
176
|
-
(0, _print.printJSON)({
|
|
177
|
-
status: 'success',
|
|
178
|
-
deployedFiles: deployableFiles
|
|
179
|
-
});
|
|
180
|
-
} else {
|
|
181
|
-
// print results
|
|
182
|
-
(0, _print.cl)(table.toString());
|
|
183
|
-
}
|
|
184
|
-
} catch (err) {
|
|
185
|
-
if (json) {
|
|
186
|
-
(0, _print.printJSON)({
|
|
187
|
-
status: 'error',
|
|
188
|
-
error: err
|
|
189
|
-
});
|
|
190
|
-
} else {
|
|
191
|
-
spinner.fail((0, _print.themed)(`Error: ${message}.`, 'secondary'));
|
|
192
|
-
(0, _print.pr)((0, _print.themed)(`Message: ${(0, _print.themed)(err.message)}`, 'secondary'));
|
|
193
|
-
debug(err);
|
|
194
|
-
|
|
195
|
-
if (err && err.response && err.response.data) {
|
|
196
|
-
debug('response', err.response.data);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
exports.handler = handler;
|