@hotglue/cli 1.0.25 → 1.0.27
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/lib/cjs/index.js +34 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/mjs/index.js +34 -0
- package/lib/mjs/index.js.map +1 -0
- package/package.json +20 -21
- package/lib/commands/config/index.js +0 -15
- package/lib/commands/config/set.js +0 -82
- package/lib/commands/config.js +0 -71
- package/lib/commands/env/deploy.js +0 -162
- package/lib/commands/env/download.js +0 -169
- package/lib/commands/env/index.js +0 -17
- package/lib/commands/env.js +0 -34
- package/lib/commands/etl/delete.js +0 -171
- package/lib/commands/etl/deploy.js +0 -261
- package/lib/commands/etl/download.js +0 -205
- package/lib/commands/etl/index.js +0 -19
- package/lib/commands/etl.js +0 -34
- package/lib/commands/flows/index.js +0 -15
- package/lib/commands/flows/list.js +0 -104
- package/lib/commands/flows.js +0 -34
- package/lib/commands/index.js +0 -27
- package/lib/commands/jobs/download.js +0 -188
- package/lib/commands/jobs/index.js +0 -17
- package/lib/commands/jobs/list.js +0 -108
- package/lib/commands/jobs.js +0 -34
- package/lib/commands/snapshots/deploy.js +0 -202
- package/lib/commands/snapshots/download.js +0 -213
- package/lib/commands/snapshots/index.js +0 -17
- package/lib/commands/snapshots.js +0 -34
- package/lib/commands/tenants/customCatalog.js +0 -199
- package/lib/commands/tenants/customEtl.js +0 -183
- package/lib/commands/tenants/customFieldMap.js +0 -191
- package/lib/commands/tenants/delete.js +0 -150
- package/lib/commands/tenants/index.js +0 -23
- package/lib/commands/tenants/list.js +0 -97
- package/lib/commands/tenants/updateConfig.js +0 -188
- package/lib/commands/tenants.js +0 -34
- package/lib/esm/index.js +0 -2312
- 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 -34
|
@@ -1,183 +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.js"));
|
|
9
|
-
|
|
10
|
-
var _ora = _interopRequireDefault(require("ora"));
|
|
11
|
-
|
|
12
|
-
var _awsSdk = _interopRequireDefault(require("aws-sdk"));
|
|
13
|
-
|
|
14
|
-
var _cliTable = _interopRequireDefault(require("cli-table"));
|
|
15
|
-
|
|
16
|
-
var _descriptions = _interopRequireDefault(require("../../helpers/descriptions.js"));
|
|
17
|
-
|
|
18
|
-
var _print = require("../../helpers/print.js");
|
|
19
|
-
|
|
20
|
-
var _api = require("../../helpers/api.js");
|
|
21
|
-
|
|
22
|
-
var _utils = require("../../helpers/utils.js");
|
|
23
|
-
|
|
24
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
-
|
|
26
|
-
const debug = (0, _debug.default)('commands:tenants:custom-etl');
|
|
27
|
-
const command = 'custom-etl';
|
|
28
|
-
exports.command = command;
|
|
29
|
-
const desc = 'List tenants with custom ETL in a specific flow';
|
|
30
|
-
exports.desc = desc;
|
|
31
|
-
|
|
32
|
-
const builder = async yargs => {
|
|
33
|
-
debug('builder', command);
|
|
34
|
-
return yargs.option('tenant', _descriptions.default.options['tenant'].config).option('flow', _descriptions.default.options['flow'].config).demandOption('flow', _descriptions.default.options['flow'].demandText);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
exports.builder = builder;
|
|
38
|
-
|
|
39
|
-
const processTenant = async ({
|
|
40
|
-
debug,
|
|
41
|
-
baseUri,
|
|
42
|
-
apikey,
|
|
43
|
-
env,
|
|
44
|
-
flow,
|
|
45
|
-
tenant,
|
|
46
|
-
supportedSources
|
|
47
|
-
}) => {
|
|
48
|
-
// Get all linked sources of the tuple (env, flow, tenant)
|
|
49
|
-
const linkedSources = await (0, _api.getLinkedSources)({
|
|
50
|
-
debug,
|
|
51
|
-
baseUri,
|
|
52
|
-
env,
|
|
53
|
-
flow,
|
|
54
|
-
tenant,
|
|
55
|
-
apikey
|
|
56
|
-
});
|
|
57
|
-
let result = null;
|
|
58
|
-
|
|
59
|
-
for (const {
|
|
60
|
-
tap
|
|
61
|
-
} of [...linkedSources, ...supportedSources]) {
|
|
62
|
-
// Generate AWS credentials in order to read the S3 tap folder
|
|
63
|
-
// Note(davi): I'm using "etl-download" because it's a "read ETL" operation
|
|
64
|
-
const {
|
|
65
|
-
accessKeyId,
|
|
66
|
-
secretAccessKey,
|
|
67
|
-
sessionToken
|
|
68
|
-
} = await (0, _api.genCredentialsOnClientApi)({
|
|
69
|
-
debug,
|
|
70
|
-
baseUri,
|
|
71
|
-
task: 'etl-download',
|
|
72
|
-
env,
|
|
73
|
-
tenant,
|
|
74
|
-
flow,
|
|
75
|
-
tap,
|
|
76
|
-
apikey
|
|
77
|
-
});
|
|
78
|
-
const s3 = new _awsSdk.default.S3({
|
|
79
|
-
accessKeyId,
|
|
80
|
-
secretAccessKey,
|
|
81
|
-
sessionToken
|
|
82
|
-
});
|
|
83
|
-
const keyPrefix = `${tenant}/flows/${flow}/taps/${tap}/etl/`;
|
|
84
|
-
const params = {
|
|
85
|
-
Bucket: env,
|
|
86
|
-
Prefix: keyPrefix
|
|
87
|
-
}; // List all files inside the S3 tap folder
|
|
88
|
-
|
|
89
|
-
const {
|
|
90
|
-
Contents: s3Files
|
|
91
|
-
} = await s3.listObjectsV2(params).promise(); // Check if either "etl.py" or "etl.ipynb" exist
|
|
92
|
-
|
|
93
|
-
const hasCustomEtl = s3Files.some(({
|
|
94
|
-
Key
|
|
95
|
-
}) => Key.endsWith('etl.py') || Key.endsWith('etl.ipynb'));
|
|
96
|
-
if (hasCustomEtl) result = tenant; // If it's true, we can break already
|
|
97
|
-
|
|
98
|
-
if (result !== null) break;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return result;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const handler = async argv => {
|
|
105
|
-
debug('handler', command, argv);
|
|
106
|
-
const {
|
|
107
|
-
hg,
|
|
108
|
-
json,
|
|
109
|
-
apikey,
|
|
110
|
-
env,
|
|
111
|
-
flow
|
|
112
|
-
} = argv;
|
|
113
|
-
let message;
|
|
114
|
-
let spinner = (0, _ora.default)();
|
|
115
|
-
|
|
116
|
-
try {
|
|
117
|
-
message = (0, _print.themed)(`Retrieving tenants for environment ${(0, _print.themed)(env, 'info')}`);
|
|
118
|
-
!json && spinner.start((0, _print.themed)(`In progress: ${message}...`, 'secondary'));
|
|
119
|
-
const [allTenants, supportedSources] = await Promise.all([(0, _api.getTenants)({
|
|
120
|
-
debug,
|
|
121
|
-
baseUri: hg.clientApiBaseUri,
|
|
122
|
-
apikey,
|
|
123
|
-
env
|
|
124
|
-
}), (0, _api.getSupportedSources)({
|
|
125
|
-
debug,
|
|
126
|
-
baseUri: hg.clientApiBaseUri,
|
|
127
|
-
apikey,
|
|
128
|
-
env,
|
|
129
|
-
flow
|
|
130
|
-
})]);
|
|
131
|
-
!json && spinner.succeed((0, _print.themed)(`Finished: ${message}.`, 'secondary'));
|
|
132
|
-
let tenantsWithCustomEtl = [];
|
|
133
|
-
message = (0, _print.themed)(`Querying for custom ETL scripts for flow ${(0, _print.themed)(flow, 'info')}`);
|
|
134
|
-
!json && spinner.start((0, _print.themed)(`In progress: ${message}...`, 'secondary')); // Break the tenants array in to an array of arrays so we can make
|
|
135
|
-
// parallel calls and make it faster
|
|
136
|
-
|
|
137
|
-
for (const tenants of (0, _utils.buildChunks)(allTenants)) {
|
|
138
|
-
const maybeTenantsWithCustomEtl = await Promise.all(tenants.map(tenant => processTenant({
|
|
139
|
-
debug,
|
|
140
|
-
baseUri: hg.clientApiBaseUri,
|
|
141
|
-
apikey,
|
|
142
|
-
env,
|
|
143
|
-
flow,
|
|
144
|
-
tenant,
|
|
145
|
-
supportedSources
|
|
146
|
-
}))); // Note(davi): we need the `.filter(Boolean)` because sometimes
|
|
147
|
-
// the function above returns `null`
|
|
148
|
-
|
|
149
|
-
tenantsWithCustomEtl = tenantsWithCustomEtl.concat(maybeTenantsWithCustomEtl.filter(Boolean));
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
!json && spinner.succeed((0, _print.themed)(`Finished: ${message}.`, 'secondary'));
|
|
153
|
-
|
|
154
|
-
if (json) {
|
|
155
|
-
(0, _print.printJSON)(tenantsWithCustomEtl);
|
|
156
|
-
} else {
|
|
157
|
-
// generate results table
|
|
158
|
-
const table = new _cliTable.default({
|
|
159
|
-
head: ['Tenant ID']
|
|
160
|
-
});
|
|
161
|
-
table.push(...tenantsWithCustomEtl.map(item => [item])); // print results
|
|
162
|
-
|
|
163
|
-
console.log(table.toString());
|
|
164
|
-
}
|
|
165
|
-
} catch (err) {
|
|
166
|
-
if (json) {
|
|
167
|
-
(0, _print.printJSON)({
|
|
168
|
-
status: 'error',
|
|
169
|
-
error: err
|
|
170
|
-
});
|
|
171
|
-
} else {
|
|
172
|
-
spinner.fail((0, _print.themed)(`Error: ${message}.`, 'secondary'));
|
|
173
|
-
(0, _print.pr)((0, _print.themed)(`Message: ${(0, _print.themed)(err.message)}`, 'secondary'));
|
|
174
|
-
debug(err);
|
|
175
|
-
|
|
176
|
-
if (err && err.response && err.response.data) {
|
|
177
|
-
debug('response', err.response.data);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
exports.handler = handler;
|
|
@@ -1,191 +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.js"));
|
|
9
|
-
|
|
10
|
-
var _ora = _interopRequireDefault(require("ora"));
|
|
11
|
-
|
|
12
|
-
var _awsSdk = _interopRequireDefault(require("aws-sdk"));
|
|
13
|
-
|
|
14
|
-
var _cliTable = _interopRequireDefault(require("cli-table"));
|
|
15
|
-
|
|
16
|
-
var _descriptions = _interopRequireDefault(require("../../helpers/descriptions.js"));
|
|
17
|
-
|
|
18
|
-
var _print = require("../../helpers/print.js");
|
|
19
|
-
|
|
20
|
-
var _api = require("../../helpers/api.js");
|
|
21
|
-
|
|
22
|
-
var _utils = require("../../helpers/utils.js");
|
|
23
|
-
|
|
24
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
-
|
|
26
|
-
const debug = (0, _debug.default)('commands:tenants:custom-field-map');
|
|
27
|
-
const command = 'custom-field-map';
|
|
28
|
-
exports.command = command;
|
|
29
|
-
const desc = 'List tenants with custom field map in a specific flow';
|
|
30
|
-
exports.desc = desc;
|
|
31
|
-
|
|
32
|
-
const builder = async yargs => {
|
|
33
|
-
debug('builder', command);
|
|
34
|
-
return yargs.option('tenant', _descriptions.default.options['tenant'].config).option('flow', _descriptions.default.options['flow'].config).demandOption('flow', _descriptions.default.options['flow'].demandText);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
exports.builder = builder;
|
|
38
|
-
|
|
39
|
-
const processTenant = async ({
|
|
40
|
-
debug,
|
|
41
|
-
baseUri,
|
|
42
|
-
apikey,
|
|
43
|
-
env,
|
|
44
|
-
flow,
|
|
45
|
-
tenant,
|
|
46
|
-
isV2Flow
|
|
47
|
-
}) => {
|
|
48
|
-
// Get all linked connectors/sources of the tuple (env, flow, tenant)
|
|
49
|
-
const linkedConnectors = isV2Flow ? await (0, _api.getLinkedConnectors)({
|
|
50
|
-
debug,
|
|
51
|
-
baseUri,
|
|
52
|
-
env,
|
|
53
|
-
flow,
|
|
54
|
-
tenant,
|
|
55
|
-
apikey
|
|
56
|
-
}) : await (0, _api.getLinkedSources)({
|
|
57
|
-
debug,
|
|
58
|
-
baseUri,
|
|
59
|
-
env,
|
|
60
|
-
flow,
|
|
61
|
-
tenant,
|
|
62
|
-
apikey
|
|
63
|
-
});
|
|
64
|
-
const connectors = []; // Generate AWS credentials in order to read the S3 tap folder
|
|
65
|
-
|
|
66
|
-
const {
|
|
67
|
-
accessKeyId,
|
|
68
|
-
secretAccessKey,
|
|
69
|
-
sessionToken
|
|
70
|
-
} = await (0, _api.genCredentialsOnClientApi)({
|
|
71
|
-
debug,
|
|
72
|
-
baseUri,
|
|
73
|
-
task: 'field-map-download',
|
|
74
|
-
env,
|
|
75
|
-
tenant,
|
|
76
|
-
flow,
|
|
77
|
-
apikey
|
|
78
|
-
});
|
|
79
|
-
const s3 = new _awsSdk.default.S3({
|
|
80
|
-
accessKeyId,
|
|
81
|
-
secretAccessKey,
|
|
82
|
-
sessionToken
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
for (const {
|
|
86
|
-
id,
|
|
87
|
-
tap
|
|
88
|
-
} of linkedConnectors) {
|
|
89
|
-
const entityLabel = isV2Flow ? 'connectors' : 'taps';
|
|
90
|
-
const params = {
|
|
91
|
-
Bucket: env,
|
|
92
|
-
Key: `${tenant}/flows/${flow}/${entityLabel}/${isV2Flow ? id : tap}/fieldMap.json`
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
try {
|
|
96
|
-
await s3.headObject(params).promise();
|
|
97
|
-
connectors.push(isV2Flow ? id : tap);
|
|
98
|
-
} catch (error) {// Does not have fieldMap.json
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return {
|
|
103
|
-
tenant,
|
|
104
|
-
connectors
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const handler = async argv => {
|
|
109
|
-
debug('handler', command, argv);
|
|
110
|
-
const {
|
|
111
|
-
hg,
|
|
112
|
-
json,
|
|
113
|
-
apikey,
|
|
114
|
-
env,
|
|
115
|
-
flow
|
|
116
|
-
} = argv;
|
|
117
|
-
let message;
|
|
118
|
-
let spinner = (0, _ora.default)();
|
|
119
|
-
|
|
120
|
-
try {
|
|
121
|
-
message = (0, _print.themed)(`Retrieving tenants for environment ${(0, _print.themed)(env, 'info')}`);
|
|
122
|
-
!json && spinner.start((0, _print.themed)(`In progress: ${message}...`, 'secondary'));
|
|
123
|
-
const [allTenants, supportedFlow] = await Promise.all([(0, _api.getTenants)({
|
|
124
|
-
debug,
|
|
125
|
-
baseUri: hg.clientApiBaseUri,
|
|
126
|
-
apikey,
|
|
127
|
-
env
|
|
128
|
-
}), (0, _api.getSupportedFlow)({
|
|
129
|
-
debug,
|
|
130
|
-
baseUri: hg.clientApiBaseUri,
|
|
131
|
-
apikey,
|
|
132
|
-
env,
|
|
133
|
-
flow
|
|
134
|
-
})]);
|
|
135
|
-
const isV2Flow = (supportedFlow === null || supportedFlow === void 0 ? void 0 : supportedFlow.version) === 2;
|
|
136
|
-
!json && spinner.succeed((0, _print.themed)(`Finished: ${message}.`, 'secondary'));
|
|
137
|
-
const tenantsWithCustomFieldMap = [];
|
|
138
|
-
message = (0, _print.themed)(`Querying for custom field maps for flow ${(0, _print.themed)(flow, 'info')}`);
|
|
139
|
-
!json && spinner.start((0, _print.themed)(`In progress: ${message}...`, 'secondary')); // Break the tenants array in to an array of arrays so we can make
|
|
140
|
-
// parallel calls and make it faster
|
|
141
|
-
|
|
142
|
-
for (const tenants of (0, _utils.buildChunks)(allTenants)) {
|
|
143
|
-
const maybeTenantsWithCustomFieldMap = await Promise.all(tenants.map(tenant => processTenant({
|
|
144
|
-
debug,
|
|
145
|
-
baseUri: hg.clientApiBaseUri,
|
|
146
|
-
apikey,
|
|
147
|
-
env,
|
|
148
|
-
flow,
|
|
149
|
-
tenant,
|
|
150
|
-
isV2Flow
|
|
151
|
-
})));
|
|
152
|
-
tenantsWithCustomFieldMap.push(...maybeTenantsWithCustomFieldMap.filter(({
|
|
153
|
-
connectors
|
|
154
|
-
}) => connectors.length > 0));
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
!json && spinner.succeed((0, _print.themed)(`Finished: ${message}.`, 'secondary'));
|
|
158
|
-
|
|
159
|
-
if (json) {
|
|
160
|
-
(0, _print.printJSON)(tenantsWithCustomFieldMap);
|
|
161
|
-
} else {
|
|
162
|
-
// generate results table
|
|
163
|
-
const table = new _cliTable.default({
|
|
164
|
-
head: ['Tenant ID', 'Connector IDs']
|
|
165
|
-
});
|
|
166
|
-
table.push(...tenantsWithCustomFieldMap.map(({
|
|
167
|
-
tenant,
|
|
168
|
-
connectors
|
|
169
|
-
}) => [tenant, connectors.join(', ')])); // print results
|
|
170
|
-
|
|
171
|
-
console.log(table.toString());
|
|
172
|
-
}
|
|
173
|
-
} catch (err) {
|
|
174
|
-
if (json) {
|
|
175
|
-
(0, _print.printJSON)({
|
|
176
|
-
status: 'error',
|
|
177
|
-
error: err
|
|
178
|
-
});
|
|
179
|
-
} else {
|
|
180
|
-
spinner.fail((0, _print.themed)(`Error: ${message}.`, 'secondary'));
|
|
181
|
-
(0, _print.pr)((0, _print.themed)(`Message: ${(0, _print.themed)(err.message)}`, 'secondary'));
|
|
182
|
-
debug(err);
|
|
183
|
-
|
|
184
|
-
if (err && err.response && err.response.data) {
|
|
185
|
-
debug('response', err.response.data);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
exports.handler = handler;
|
|
@@ -1,150 +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 _awsSdk = _interopRequireDefault(require("aws-sdk"));
|
|
9
|
-
|
|
10
|
-
var _ora = _interopRequireDefault(require("ora"));
|
|
11
|
-
|
|
12
|
-
var _cliTable = _interopRequireDefault(require("cli-table"));
|
|
13
|
-
|
|
14
|
-
var _debug = _interopRequireDefault(require("../../helpers/debug.js"));
|
|
15
|
-
|
|
16
|
-
var _descriptions = _interopRequireDefault(require("../../helpers/descriptions.js"));
|
|
17
|
-
|
|
18
|
-
var _print = require("../../helpers/print.js");
|
|
19
|
-
|
|
20
|
-
var _api = require("../../helpers/api.js");
|
|
21
|
-
|
|
22
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
-
|
|
24
|
-
const debug = (0, _debug.default)('commands:tenants:delete');
|
|
25
|
-
const command = 'delete';
|
|
26
|
-
exports.command = command;
|
|
27
|
-
const desc = 'Delete tenant';
|
|
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
|
-
exports.builder = builder;
|
|
36
|
-
|
|
37
|
-
const handler = async argv => {
|
|
38
|
-
debug('handler', command, argv);
|
|
39
|
-
const {
|
|
40
|
-
hg,
|
|
41
|
-
json,
|
|
42
|
-
apikey,
|
|
43
|
-
env,
|
|
44
|
-
tenant
|
|
45
|
-
} = argv;
|
|
46
|
-
const {
|
|
47
|
-
clientApiBaseUri
|
|
48
|
-
} = hg;
|
|
49
|
-
let message;
|
|
50
|
-
let spinner = (0, _ora.default)();
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
if (tenant === 'default') {
|
|
54
|
-
throw new Error('It\'s not possible to delete "default" tenant!');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
message = (0, _print.themed)(`Deleting tenant ${tenant} schedules`);
|
|
58
|
-
!json && spinner.start((0, _print.themed)(`In progress: ${message}...`, 'secondary'));
|
|
59
|
-
await (0, _api.deleteTenantSchedules)({
|
|
60
|
-
debug,
|
|
61
|
-
baseUri: clientApiBaseUri,
|
|
62
|
-
env,
|
|
63
|
-
apikey,
|
|
64
|
-
tenant
|
|
65
|
-
});
|
|
66
|
-
!json && spinner.succeed((0, _print.themed)(`Finished: ${message}.`, 'secondary'));
|
|
67
|
-
message = (0, _print.themed)(`Verifying user and authorizing`);
|
|
68
|
-
!json && spinner.start((0, _print.themed)(`In progress: ${message}...`, 'secondary'));
|
|
69
|
-
const {
|
|
70
|
-
accessKeyId,
|
|
71
|
-
secretAccessKey,
|
|
72
|
-
sessionToken
|
|
73
|
-
} = await (0, _api.genCredentialsOnClientApi)({
|
|
74
|
-
debug,
|
|
75
|
-
baseUri: clientApiBaseUri,
|
|
76
|
-
task: 'tenant-delete',
|
|
77
|
-
env,
|
|
78
|
-
tenant,
|
|
79
|
-
apikey
|
|
80
|
-
});
|
|
81
|
-
!json && spinner.succeed((0, _print.themed)(`Finished: ${message}.`, 'secondary')); // created authenticated S3 instance
|
|
82
|
-
|
|
83
|
-
const s3 = new _awsSdk.default.S3({
|
|
84
|
-
accessKeyId,
|
|
85
|
-
secretAccessKey,
|
|
86
|
-
sessionToken
|
|
87
|
-
});
|
|
88
|
-
message = (0, _print.themed)(`Deleting tenant ${tenant} for environment ${(0, _print.themed)(env, 'info')}`);
|
|
89
|
-
!json && spinner.start((0, _print.themed)(`In progress: ${message}...`, 'secondary'));
|
|
90
|
-
|
|
91
|
-
while (true) {
|
|
92
|
-
// List objects, 1000 keys at a time
|
|
93
|
-
const s3Objects = await s3.listObjectsV2({
|
|
94
|
-
Bucket: env,
|
|
95
|
-
Prefix: `${tenant}/`
|
|
96
|
-
}).promise();
|
|
97
|
-
const Objects = (s3Objects.Contents || []).map(({
|
|
98
|
-
Key
|
|
99
|
-
}) => ({
|
|
100
|
-
Key
|
|
101
|
-
}));
|
|
102
|
-
|
|
103
|
-
if (Objects.length === 0) {
|
|
104
|
-
break;
|
|
105
|
-
} // Purge the objects
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const response = await s3.deleteObjects({
|
|
109
|
-
Bucket: env,
|
|
110
|
-
Delete: {
|
|
111
|
-
Objects
|
|
112
|
-
}
|
|
113
|
-
}).promise();
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
!json && spinner.succeed((0, _print.themed)(`Finished: ${message}.`, 'secondary'));
|
|
117
|
-
|
|
118
|
-
if (json) {
|
|
119
|
-
(0, _print.printJSON)({
|
|
120
|
-
statu: 'success',
|
|
121
|
-
tenantDeleted: tenant
|
|
122
|
-
});
|
|
123
|
-
} else {
|
|
124
|
-
// generate results table
|
|
125
|
-
const table = new _cliTable.default({
|
|
126
|
-
head: ['Tenant ID']
|
|
127
|
-
});
|
|
128
|
-
table.push([tenant]); // print results
|
|
129
|
-
|
|
130
|
-
console.log(table.toString());
|
|
131
|
-
}
|
|
132
|
-
} catch (err) {
|
|
133
|
-
if (json) {
|
|
134
|
-
(0, _print.printJSON)({
|
|
135
|
-
status: 'error',
|
|
136
|
-
error: err
|
|
137
|
-
});
|
|
138
|
-
} else {
|
|
139
|
-
spinner.fail((0, _print.themed)(`Error: ${message}.`, 'secondary'));
|
|
140
|
-
(0, _print.pr)((0, _print.themed)(`Message: ${(0, _print.themed)(err.message)}`, 'secondary'));
|
|
141
|
-
debug(err);
|
|
142
|
-
|
|
143
|
-
if (err && err.response && err.response.data) {
|
|
144
|
-
debug('response', err.response.data);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
exports.handler = handler;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.tenants = void 0;
|
|
7
|
-
|
|
8
|
-
var customEtl = _interopRequireWildcard(require("./customEtl.js"));
|
|
9
|
-
|
|
10
|
-
var customField = _interopRequireWildcard(require("./customFieldMap.js"));
|
|
11
|
-
|
|
12
|
-
var del = _interopRequireWildcard(require("./delete.js"));
|
|
13
|
-
|
|
14
|
-
var list = _interopRequireWildcard(require("./list.js"));
|
|
15
|
-
|
|
16
|
-
var updateConfig = _interopRequireWildcard(require("./updateConfig.js"));
|
|
17
|
-
|
|
18
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
-
|
|
20
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
-
|
|
22
|
-
const tenants = [customEtl, customField, del, list, updateConfig];
|
|
23
|
-
exports.tenants = tenants;
|
|
@@ -1,97 +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.js"));
|
|
9
|
-
|
|
10
|
-
var _ora = _interopRequireDefault(require("ora"));
|
|
11
|
-
|
|
12
|
-
var _axios = _interopRequireDefault(require("axios"));
|
|
13
|
-
|
|
14
|
-
var _cliTable = _interopRequireDefault(require("cli-table"));
|
|
15
|
-
|
|
16
|
-
var _descriptions = _interopRequireDefault(require("../../helpers/descriptions.js"));
|
|
17
|
-
|
|
18
|
-
var _print = require("../../helpers/print.js");
|
|
19
|
-
|
|
20
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
|
-
const debug = (0, _debug.default)('commands:tenants:list');
|
|
23
|
-
const command = 'list';
|
|
24
|
-
exports.command = command;
|
|
25
|
-
const desc = 'List tenants';
|
|
26
|
-
exports.desc = desc;
|
|
27
|
-
|
|
28
|
-
const builder = async yargs => {
|
|
29
|
-
debug('builder', command);
|
|
30
|
-
return yargs.option('tenant', _descriptions.default.options['tenant'].config);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
exports.builder = builder;
|
|
34
|
-
|
|
35
|
-
const handler = async argv => {
|
|
36
|
-
debug('handler', command, argv);
|
|
37
|
-
const {
|
|
38
|
-
hg,
|
|
39
|
-
json,
|
|
40
|
-
apikey,
|
|
41
|
-
env,
|
|
42
|
-
tenant
|
|
43
|
-
} = argv;
|
|
44
|
-
let message;
|
|
45
|
-
let spinner = (0, _ora.default)();
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
// 1. get data from client-api backend
|
|
49
|
-
message = (0, _print.themed)(`Retrieving tenants for environment ${(0, _print.themed)(env, 'info')}`);
|
|
50
|
-
const uri = `${hg.clientApiBaseUri}/tenants/${env}${tenant ? `?tenant=${tenant}` : ''}`;
|
|
51
|
-
debug('requesting:', uri);
|
|
52
|
-
!json && spinner.start((0, _print.themed)(`In progress: ${message}...`, 'secondary'));
|
|
53
|
-
const {
|
|
54
|
-
data
|
|
55
|
-
} = await _axios.default.get(uri, {
|
|
56
|
-
headers: {
|
|
57
|
-
'x-api-key': apikey
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
!json && spinner.succeed((0, _print.themed)(`Finished: ${message}.`, 'secondary'));
|
|
61
|
-
debug('response-data', data); // exit if there is no data
|
|
62
|
-
|
|
63
|
-
if (!data || data.length === 0) {
|
|
64
|
-
json ? (0, _print.printJSON)([]) : spinner.info((0, _print.themed)(`Info: ${(0, _print.themed)('No tenants found in the specified environment')}.`, 'secondary'));
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (json) {
|
|
69
|
-
(0, _print.printJSON)(data);
|
|
70
|
-
} else {
|
|
71
|
-
// generate results table
|
|
72
|
-
const table = new _cliTable.default({
|
|
73
|
-
head: ['tenant ID']
|
|
74
|
-
});
|
|
75
|
-
table.push(...data.map(item => [item])); // print results
|
|
76
|
-
|
|
77
|
-
console.log(table.toString());
|
|
78
|
-
}
|
|
79
|
-
} catch (err) {
|
|
80
|
-
if (json) {
|
|
81
|
-
(0, _print.printJSON)({
|
|
82
|
-
status: 'error',
|
|
83
|
-
error: err
|
|
84
|
-
});
|
|
85
|
-
} else {
|
|
86
|
-
spinner.fail((0, _print.themed)(`Error: ${message}.`, 'secondary'));
|
|
87
|
-
(0, _print.pr)((0, _print.themed)(`Message: ${(0, _print.themed)(err.message)}`, 'secondary'));
|
|
88
|
-
debug(err);
|
|
89
|
-
|
|
90
|
-
if (err && err.response && err.response.data) {
|
|
91
|
-
debug('response', err.response.data);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
exports.handler = handler;
|