@axway/axway-central-cli 2.17.0-rc.5 → 2.17.0
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/dist/cli.js +28 -6
- package/dist/commands/apply/index.js +24 -9
- package/dist/commands/completion/index.js +9 -3
- package/dist/commands/config/common/index.js +11 -2
- package/dist/commands/config/index.js +7 -2
- package/dist/commands/config/list.js +6 -2
- package/dist/commands/config/set.js +31 -4
- package/dist/commands/config/unset.js +12 -2
- package/dist/commands/create/agentResource.js +32 -12
- package/dist/commands/create/environment.js +16 -6
- package/dist/commands/create/index.js +26 -9
- package/dist/commands/create/serviceAccount.js +6 -2
- package/dist/commands/delete/index.js +33 -15
- package/dist/commands/edit/environment.js +21 -6
- package/dist/commands/edit/index.js +8 -4
- package/dist/commands/get/index.js +44 -27
- package/dist/commands/install/agents.js +73 -44
- package/dist/commands/install/apigeexSaasAgents.js +98 -35
- package/dist/commands/install/awsAgents.js +139 -89
- package/dist/commands/install/awsSaasAgents.js +142 -50
- package/dist/commands/install/azureAgents.js +79 -39
- package/dist/commands/install/edgeAgents.js +110 -17
- package/dist/commands/install/helpers/creators.js +70 -17
- package/dist/commands/install/helpers/deleters.js +11 -2
- package/dist/commands/install/helpers/getters.js +30 -4
- package/dist/commands/install/helpers/index.js +48 -13
- package/dist/commands/install/helpers/inputs.js +98 -26
- package/dist/commands/install/helpers/regex.js +34 -29
- package/dist/commands/install/helpers/templates/awsTemplates.js +23 -6
- package/dist/commands/install/helpers/templates/azureTemplates.js +24 -5
- package/dist/commands/install/helpers/templates/edgeTemplates.js +38 -7
- package/dist/commands/install/helpers/templates/istioTemplates.js +16 -5
- package/dist/commands/install/index.js +10 -4
- package/dist/commands/install/istioAgents.js +117 -40
- package/dist/commands/install/platform.js +52 -20
- package/dist/commands/proxies/create.js +18 -2
- package/dist/commands/proxies/index.js +8 -4
- package/dist/commands/proxies/promote.js +21 -2
- package/dist/common/ApiServerClient.js +173 -64
- package/dist/common/CacheController.js +32 -11
- package/dist/common/CliConfigManager.js +27 -14
- package/dist/common/CompositeError.js +30 -6
- package/dist/common/CoreConfigController.js +40 -18
- package/dist/common/DefinitionsManager.js +76 -29
- package/dist/common/Kubectl.js +25 -2
- package/dist/common/PlatformClient.js +63 -19
- package/dist/common/Renderer.js +87 -25
- package/dist/common/TmpFile.js +28 -11
- package/dist/common/bashCommands.js +22 -3
- package/dist/common/basicPrompts.js +43 -8
- package/dist/common/dataService.js +50 -22
- package/dist/common/errorHandler.js +9 -0
- package/dist/common/resultsRenderers.js +42 -10
- package/dist/common/types.js +341 -116
- package/dist/common/utils.js +99 -37
- package/dist/main.js +2 -0
- package/package.json +2 -2
- package/dist/commands/install/gitHubSaasAgents.js +0 -283
package/dist/common/Renderer.js
CHANGED
|
@@ -4,75 +4,86 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
|
|
7
8
|
var _cliKit = require("cli-kit");
|
|
9
|
+
|
|
8
10
|
var _ora = _interopRequireDefault(require("ora"));
|
|
11
|
+
|
|
9
12
|
var _CompositeError = require("./CompositeError");
|
|
13
|
+
|
|
10
14
|
var _resultsRenderers = require("./resultsRenderers");
|
|
15
|
+
|
|
11
16
|
var _types = require("./types");
|
|
17
|
+
|
|
12
18
|
var _utils = require("./utils");
|
|
19
|
+
|
|
13
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
|
|
14
22
|
function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
|
|
23
|
+
|
|
15
24
|
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
16
|
-
|
|
17
|
-
function
|
|
18
|
-
|
|
25
|
+
|
|
26
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
27
|
+
|
|
19
28
|
function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
|
|
29
|
+
|
|
20
30
|
var _createApiServerErrorMessage = /*#__PURE__*/new WeakSet();
|
|
31
|
+
|
|
21
32
|
class Renderer {
|
|
22
33
|
constructor(console, output) {
|
|
23
|
-
/**
|
|
24
|
-
* Creates an error message for the given ApiResponseError title and detail strings.
|
|
25
|
-
* @param prefix String to be prefixed to the message.
|
|
26
|
-
* @param title Optional title such as "Validation error", "Forbidden error", etc.
|
|
27
|
-
* @param detail Optional error detail explaining exactly what went wrong.
|
|
28
|
-
* @returns Returns an error message to be outputted to the console.
|
|
29
|
-
*/
|
|
30
34
|
_classPrivateMethodInitSpec(this, _createApiServerErrorMessage);
|
|
35
|
+
|
|
31
36
|
_defineProperty(this, "spinner", void 0);
|
|
37
|
+
|
|
32
38
|
_defineProperty(this, "_console", void 0);
|
|
39
|
+
|
|
33
40
|
_defineProperty(this, "output", void 0);
|
|
41
|
+
|
|
34
42
|
this.spinner = process.env['DEBUG'] || !!output ? null : (0, _ora.default)({
|
|
35
43
|
spinner: 'dots3'
|
|
36
44
|
});
|
|
37
45
|
this._console = console;
|
|
38
46
|
this.output = output;
|
|
39
47
|
}
|
|
40
|
-
|
|
41
48
|
/**
|
|
42
49
|
* Start the spinner and return self
|
|
43
50
|
* @param text text to display near the spinner
|
|
44
51
|
*/
|
|
52
|
+
|
|
53
|
+
|
|
45
54
|
startSpin(text) {
|
|
46
55
|
this.spinner && this.spinner.start(text);
|
|
47
56
|
return this;
|
|
48
57
|
}
|
|
49
|
-
|
|
50
58
|
/**
|
|
51
59
|
* Stop the spinner
|
|
52
60
|
*/
|
|
61
|
+
|
|
62
|
+
|
|
53
63
|
stopSpin() {
|
|
54
64
|
this.spinner && this.spinner.stop();
|
|
55
65
|
return this;
|
|
56
66
|
}
|
|
57
|
-
|
|
58
67
|
/**
|
|
59
68
|
* Replaces the text shown by startSpin(). Intended to show progress.
|
|
60
69
|
* @param text The text to displayed next to the spinner.
|
|
61
70
|
*/
|
|
71
|
+
|
|
72
|
+
|
|
62
73
|
updateSpinText(text) {
|
|
63
74
|
if (this.spinner) {
|
|
64
75
|
this.spinner.text = text;
|
|
65
76
|
}
|
|
66
77
|
}
|
|
67
|
-
|
|
68
78
|
/**
|
|
69
79
|
* Print simple text to console
|
|
70
80
|
* @param text text to render
|
|
71
81
|
*/
|
|
82
|
+
|
|
83
|
+
|
|
72
84
|
console(text) {
|
|
73
85
|
this._console.log(text);
|
|
74
86
|
}
|
|
75
|
-
|
|
76
87
|
/**
|
|
77
88
|
* Render success message. If output param has been provided use simple console
|
|
78
89
|
* otherwise use spinner.
|
|
@@ -80,10 +91,11 @@ class Renderer {
|
|
|
80
91
|
* @param spinnerOnly optional, if its true message will be rendered
|
|
81
92
|
* only when spinner is in use (which mean no output param has been provided)
|
|
82
93
|
*/
|
|
94
|
+
|
|
95
|
+
|
|
83
96
|
success(text, spinnerOnly = false) {
|
|
84
97
|
this.output && !spinnerOnly ? this.console(text) : this.spinner && this.spinner.succeed((0, _cliKit.chalk)`{greenBright ${text}}`);
|
|
85
98
|
}
|
|
86
|
-
|
|
87
99
|
/**
|
|
88
100
|
* Render warning message. If output param has been provided use simple console
|
|
89
101
|
* otherwise use spinner.
|
|
@@ -91,10 +103,11 @@ class Renderer {
|
|
|
91
103
|
* @param spinnerOnly optional, if its true message will be rendered
|
|
92
104
|
* only when spinner is in use (which mean no output param has been provided)
|
|
93
105
|
*/
|
|
106
|
+
|
|
107
|
+
|
|
94
108
|
warning(text, spinnerOnly = false) {
|
|
95
109
|
this.output && !spinnerOnly ? this.console(text) : this.spinner && this.spinner.warn((0, _cliKit.chalk)`{yellow ${text}}`);
|
|
96
110
|
}
|
|
97
|
-
|
|
98
111
|
/**
|
|
99
112
|
* Render error message. If output param has been provided use simple console
|
|
100
113
|
* otherwise use spinner.
|
|
@@ -102,48 +115,57 @@ class Renderer {
|
|
|
102
115
|
* @param spinnerOnly optional, if true message will be rendered
|
|
103
116
|
* only when spinner is in use (which mean no output param has been provided)
|
|
104
117
|
*/
|
|
118
|
+
|
|
119
|
+
|
|
105
120
|
error(text, spinnerOnly = false) {
|
|
106
121
|
this.output && !spinnerOnly ? this.console(text) : this.spinner && this.spinner.fail((0, _cliKit.chalk)`{red ${text}}`);
|
|
107
122
|
}
|
|
108
|
-
|
|
109
123
|
/**
|
|
110
124
|
* A helper returning `"<resource kind>/<resource name>" in the scope "<scope kind>/<scope name>"`
|
|
111
125
|
* string used to print bulk results (in "bulkResult" or "bulkCreateOrUpdateResult") or individually (see the "delete" cmd)
|
|
112
126
|
* @param {GenericResource} resource resource for witch the string should be created
|
|
113
127
|
* @returns {string}
|
|
114
128
|
*/
|
|
129
|
+
|
|
130
|
+
|
|
115
131
|
resourceAndScopeKinds(resource) {
|
|
116
132
|
var _resource$metadata;
|
|
133
|
+
|
|
117
134
|
// prettier-ignore
|
|
118
135
|
return `"${resource.kind}/${resource.name}"${!!((_resource$metadata = resource.metadata) !== null && _resource$metadata !== void 0 && _resource$metadata.scope) ? ` in the scope "${resource.metadata.scope.kind}/${resource.metadata.scope.name}"` : ``}`;
|
|
119
136
|
}
|
|
120
|
-
|
|
121
137
|
/**
|
|
122
138
|
* Render bulk call result.
|
|
123
139
|
* If error is happening - render as simple output (even if "output" param has been provided)
|
|
124
140
|
* @param bulkResult bulk response from ApiServerClient
|
|
125
141
|
* @param simpleSuccessMsg message to display for each created "kind/name"
|
|
126
142
|
*/
|
|
143
|
+
|
|
144
|
+
|
|
127
145
|
bulkResult(bulkResult, simpleSuccessMsg) {
|
|
128
146
|
if (bulkResult.error.length) {
|
|
129
147
|
var _bulkResult$warning;
|
|
148
|
+
|
|
130
149
|
(_bulkResult$warning = bulkResult.warning) === null || _bulkResult$warning === void 0 ? void 0 : _bulkResult$warning.forEach(r => this.warning(`${this.resourceAndScopeKinds(r)} was created with an autogenerated logical name.`));
|
|
131
150
|
bulkResult.success.forEach(r => this.success(`${this.resourceAndScopeKinds(r)} ${simpleSuccessMsg}`));
|
|
132
151
|
bulkResult.error.forEach(r => this.anyError(r.error, `"${r.kind}/${r.name}" `, true));
|
|
133
152
|
} else if (this.output) {
|
|
134
153
|
var _bulkResult$warning2;
|
|
154
|
+
|
|
135
155
|
let results = bulkResult.success;
|
|
156
|
+
|
|
136
157
|
if ((_bulkResult$warning2 = bulkResult.warning) !== null && _bulkResult$warning2 !== void 0 && _bulkResult$warning2.length) {
|
|
137
158
|
results = bulkResult.warning.concat(results);
|
|
138
159
|
}
|
|
160
|
+
|
|
139
161
|
(0, _resultsRenderers.renderResponse)(this._console, results, this.output);
|
|
140
162
|
} else {
|
|
141
163
|
var _bulkResult$warning3;
|
|
164
|
+
|
|
142
165
|
(_bulkResult$warning3 = bulkResult.warning) === null || _bulkResult$warning3 === void 0 ? void 0 : _bulkResult$warning3.forEach(r => this.warning(`${this.resourceAndScopeKinds(r)} was created with an autogenerated logical name.`));
|
|
143
166
|
bulkResult.success.forEach(r => this.success(`${this.resourceAndScopeKinds(r)} ${simpleSuccessMsg}`));
|
|
144
167
|
}
|
|
145
168
|
}
|
|
146
|
-
|
|
147
169
|
/**
|
|
148
170
|
* Render bulk "apply" result (with different success messages).
|
|
149
171
|
* If error is happening - render as simple output (even if "output" param has been provided)
|
|
@@ -151,6 +173,8 @@ class Renderer {
|
|
|
151
173
|
* @param createSuccessMsg message to display for each created "kind/name"
|
|
152
174
|
* @param updateSuccessMsg message to display for each updated "kind/name"
|
|
153
175
|
*/
|
|
176
|
+
|
|
177
|
+
|
|
154
178
|
bulkCreateOrUpdateResult(bulkResult, createSuccessMsg, updateSuccessMsg, createWarningMsg) {
|
|
155
179
|
// if array passed, combine in a single ApiServerClientBulkResult, else use as-is
|
|
156
180
|
const bulkResultCombined = {
|
|
@@ -158,26 +182,33 @@ class Renderer {
|
|
|
158
182
|
error: [...bulkResult.created.error, ...bulkResult.updated.error],
|
|
159
183
|
warning: [bulkResult.created.warning]
|
|
160
184
|
};
|
|
185
|
+
|
|
161
186
|
if (bulkResultCombined.error.length) {
|
|
162
187
|
var _bulkResult$created$w;
|
|
188
|
+
|
|
163
189
|
(_bulkResult$created$w = bulkResult.created.warning) === null || _bulkResult$created$w === void 0 ? void 0 : _bulkResult$created$w.forEach(r => this.warning(`${this.resourceAndScopeKinds(r)} ${createWarningMsg}`));
|
|
164
190
|
bulkResult.created.success.forEach(r => this.success(`${this.resourceAndScopeKinds(r)} ${createSuccessMsg}`));
|
|
165
191
|
bulkResult.updated.success.forEach(r => this.success(`${this.resourceAndScopeKinds(r)} ${updateSuccessMsg}`));
|
|
166
192
|
bulkResultCombined.error.forEach(r => this.anyError(r.error, `"${r.kind}/${r.name}" `, true));
|
|
167
193
|
} else if (this.output) {
|
|
168
194
|
var _bulkResult$created$w2;
|
|
195
|
+
|
|
169
196
|
let results = bulkResultCombined.success;
|
|
197
|
+
|
|
170
198
|
if ((_bulkResult$created$w2 = bulkResult.created.warning) !== null && _bulkResult$created$w2 !== void 0 && _bulkResult$created$w2.length) {
|
|
171
199
|
results = bulkResult.created.warning.concat(results);
|
|
172
200
|
}
|
|
201
|
+
|
|
173
202
|
(0, _resultsRenderers.renderResponse)(this._console, results, this.output);
|
|
174
203
|
} else {
|
|
175
204
|
var _bulkResult$created$w3;
|
|
205
|
+
|
|
176
206
|
(_bulkResult$created$w3 = bulkResult.created.warning) === null || _bulkResult$created$w3 === void 0 ? void 0 : _bulkResult$created$w3.forEach(r => this.warning(`${this.resourceAndScopeKinds(r)} ${createWarningMsg}`));
|
|
177
207
|
bulkResult.created.success.forEach(r => this.success(`${this.resourceAndScopeKinds(r)} ${createSuccessMsg}`));
|
|
178
208
|
bulkResult.updated.success.forEach(r => this.success(`${this.resourceAndScopeKinds(r)} ${updateSuccessMsg}`));
|
|
179
209
|
}
|
|
180
210
|
}
|
|
211
|
+
|
|
181
212
|
renderGetResults(bulkResultsArray, successMsg) {
|
|
182
213
|
// sort all results by success / error
|
|
183
214
|
// IMPORTANT: mind the response.data! non-null assertion later on, should be covered by this loop
|
|
@@ -188,6 +219,7 @@ class Renderer {
|
|
|
188
219
|
success: [],
|
|
189
220
|
error: []
|
|
190
221
|
});
|
|
222
|
+
|
|
191
223
|
if (this.output) {
|
|
192
224
|
/**
|
|
193
225
|
* IF bulkResultsArray.length === 1 this means user query only for a single resource (entire list or by name,
|
|
@@ -196,8 +228,10 @@ class Renderer {
|
|
|
196
228
|
* dataToRender to first "success" element (sortedResults will also include only one element in this case).
|
|
197
229
|
*/
|
|
198
230
|
let dataToRender = [];
|
|
231
|
+
|
|
199
232
|
if (bulkResultsArray.length === 1) {
|
|
200
233
|
var _sortedResults$succes, _sortedResults$succes2;
|
|
234
|
+
|
|
201
235
|
dataToRender = ((_sortedResults$succes = sortedResults.success[0]) === null || _sortedResults$succes === void 0 ? void 0 : (_sortedResults$succes2 = _sortedResults$succes.response) === null || _sortedResults$succes2 === void 0 ? void 0 : _sortedResults$succes2.data) || {};
|
|
202
236
|
} else {
|
|
203
237
|
/**
|
|
@@ -209,6 +243,7 @@ class Renderer {
|
|
|
209
243
|
return a;
|
|
210
244
|
}, []);
|
|
211
245
|
}
|
|
246
|
+
|
|
212
247
|
(0, _resultsRenderers.renderResponse)(this._console, dataToRender, this.output);
|
|
213
248
|
} else {
|
|
214
249
|
// stop spinner and render a table for each successful request
|
|
@@ -219,19 +254,19 @@ class Renderer {
|
|
|
219
254
|
}, {
|
|
220
255
|
empty: [],
|
|
221
256
|
notEmpty: []
|
|
222
|
-
});
|
|
223
|
-
|
|
257
|
+
}); // if all results are empty, render just once, otherwise render only successful results
|
|
258
|
+
|
|
224
259
|
if (!sortedSuccess.notEmpty.length && sortedSuccess.empty.length) {
|
|
225
260
|
(0, _resultsRenderers.renderResponse)(this._console, sortedSuccess.empty[0].response.data, this.output, sortedSuccess.empty[0].columns);
|
|
226
261
|
} else {
|
|
227
262
|
sortedSuccess.notEmpty.forEach(v => (0, _resultsRenderers.renderResponse)(this._console, v.response.data, this.output, v.columns));
|
|
228
263
|
}
|
|
229
|
-
}
|
|
230
|
-
// rendering errors only if there are zero successful results,
|
|
264
|
+
} // rendering errors only if there are zero successful results,
|
|
231
265
|
// also assuming only first (and only) error will be in api-server error response in case of 404
|
|
266
|
+
|
|
267
|
+
|
|
232
268
|
if (!sortedResults.success.length) sortedResults.error.forEach(v => v.response.error && this.error(`Error: ${v.response.error[0].detail || v.response.error[0].title}`));
|
|
233
269
|
}
|
|
234
|
-
|
|
235
270
|
/**
|
|
236
271
|
* Render any kind of error
|
|
237
272
|
* @param error error or ApiServer error to render
|
|
@@ -239,11 +274,15 @@ class Renderer {
|
|
|
239
274
|
* @param ignoreOutputParam if provided as true will ignore the output param and always render
|
|
240
275
|
* the error message as set of strings. Currently used in bulk result renderers in case of any errors.
|
|
241
276
|
*/
|
|
277
|
+
|
|
278
|
+
|
|
242
279
|
anyError(error, prefixMsg = '', ignoreOutputParam = false) {
|
|
243
280
|
var _error$errors;
|
|
281
|
+
|
|
244
282
|
if ((this.output === _types.OutputTypes.json || this.output === _types.OutputTypes.yaml) && !ignoreOutputParam) {
|
|
245
283
|
// Output given error to a JSON or YAML format.
|
|
246
284
|
let response;
|
|
285
|
+
|
|
247
286
|
if ((0, _utils.isApiServerErrorType)(error) || (0, _utils.isApiServerErrorResponseType)(error)) {
|
|
248
287
|
if (error instanceof Error && error.name === 'HTTPError' && error.errors) {
|
|
249
288
|
// The HTTP response has an errors array. Only log that part.
|
|
@@ -259,6 +298,7 @@ class Renderer {
|
|
|
259
298
|
message: error === null || error === void 0 ? void 0 : error.message
|
|
260
299
|
};
|
|
261
300
|
}
|
|
301
|
+
|
|
262
302
|
(0, _resultsRenderers.renderResponse)(this._console, response, this.output);
|
|
263
303
|
} else if (error instanceof _CompositeError.CompositeError) {
|
|
264
304
|
// A hierarchy of nested errors was provided. Log it with appropriate indentation.
|
|
@@ -266,6 +306,7 @@ class Renderer {
|
|
|
266
306
|
const indentation = this.output ? '' : ' ';
|
|
267
307
|
this.error(compositeError.toNestedMessageArray().join(`\n${indentation}`));
|
|
268
308
|
};
|
|
309
|
+
|
|
269
310
|
if (error.message) {
|
|
270
311
|
// Root error has a message. Log entire error hierarchy as a single error.
|
|
271
312
|
logCompositeError(error);
|
|
@@ -292,6 +333,7 @@ class Renderer {
|
|
|
292
333
|
// ELSE this is ApiServer error or ApiServer error response
|
|
293
334
|
// using just first error from api response since all bulk operations executed one-by-one for now
|
|
294
335
|
const err = error;
|
|
336
|
+
|
|
295
337
|
switch (err.status) {
|
|
296
338
|
// TODO: some pasta here: 401 thrown manually on data service, fix it?
|
|
297
339
|
// https://jira.axway.com/browse/APIGOV-20818
|
|
@@ -302,10 +344,12 @@ class Renderer {
|
|
|
302
344
|
this.console('Or if using a service account:');
|
|
303
345
|
this.console((0, _cliKit.chalk)`{cyan axway auth login --client-id <Service Account Client ID> --secret-file <Private Key>}`);
|
|
304
346
|
break;
|
|
347
|
+
|
|
305
348
|
case 400:
|
|
306
349
|
this.error(_classPrivateMethodGet(this, _createApiServerErrorMessage, _createApiServerErrorMessage2).call(this, prefixMsg, err.title, err.detail));
|
|
307
350
|
if (err.source) this.console(_cliKit.chalk.gray(`Caused by: ${JSON.stringify(err.source)}`));
|
|
308
351
|
break;
|
|
352
|
+
|
|
309
353
|
case 403:
|
|
310
354
|
case 404:
|
|
311
355
|
case 409:
|
|
@@ -314,6 +358,7 @@ class Renderer {
|
|
|
314
358
|
// status 0 used for internal errors (see ApiServerClient.deleteSingleResource wait logic)
|
|
315
359
|
this.error(_classPrivateMethodGet(this, _createApiServerErrorMessage, _createApiServerErrorMessage2).call(this, prefixMsg, err.title, err.detail));
|
|
316
360
|
break;
|
|
361
|
+
|
|
317
362
|
default:
|
|
318
363
|
// rare case, should almost never happen.
|
|
319
364
|
if (error instanceof Error) {
|
|
@@ -321,22 +366,39 @@ class Renderer {
|
|
|
321
366
|
} else {
|
|
322
367
|
this.error(`An unknown error occurred, try different output formats (for ex.: "-o ${_types.OutputTypes.json}") to find out more details.`);
|
|
323
368
|
}
|
|
369
|
+
|
|
324
370
|
}
|
|
325
371
|
}
|
|
326
372
|
}
|
|
373
|
+
/**
|
|
374
|
+
* Creates an error message for the given ApiResponseError title and detail strings.
|
|
375
|
+
* @param prefix String to be prefixed to the message.
|
|
376
|
+
* @param title Optional title such as "Validation error", "Forbidden error", etc.
|
|
377
|
+
* @param detail Optional error detail explaining exactly what went wrong.
|
|
378
|
+
* @returns Returns an error message to be outputted to the console.
|
|
379
|
+
*/
|
|
380
|
+
|
|
381
|
+
|
|
327
382
|
}
|
|
383
|
+
|
|
328
384
|
exports.default = Renderer;
|
|
385
|
+
|
|
329
386
|
function _createApiServerErrorMessage2(prefix, title, detail) {
|
|
330
387
|
let message = prefix;
|
|
388
|
+
|
|
331
389
|
if (message.length > 0 && !message.endsWith(' ')) {
|
|
332
390
|
message += ' ';
|
|
333
391
|
}
|
|
392
|
+
|
|
334
393
|
message += title || 'Error';
|
|
394
|
+
|
|
335
395
|
if (detail) {
|
|
336
396
|
if (!message.endsWith(':') && !message.endsWith('.') && !message.endsWith('!')) {
|
|
337
397
|
message += ':';
|
|
338
398
|
}
|
|
399
|
+
|
|
339
400
|
message += ' ' + detail;
|
|
340
401
|
}
|
|
402
|
+
|
|
341
403
|
return message;
|
|
342
404
|
}
|
package/dist/common/TmpFile.js
CHANGED
|
@@ -4,19 +4,27 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
|
|
7
8
|
var _fs = require("fs");
|
|
9
|
+
|
|
8
10
|
var _snooplogg = _interopRequireDefault(require("snooplogg"));
|
|
11
|
+
|
|
9
12
|
var _tmp = _interopRequireDefault(require("tmp"));
|
|
13
|
+
|
|
10
14
|
var _resultsRenderers = require("../common/resultsRenderers");
|
|
15
|
+
|
|
11
16
|
var _utils = require("../common/utils");
|
|
17
|
+
|
|
12
18
|
var _bashCommands = require("./bashCommands");
|
|
19
|
+
|
|
13
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
|
-
function
|
|
16
|
-
|
|
21
|
+
|
|
22
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
23
|
+
|
|
17
24
|
const {
|
|
18
25
|
log
|
|
19
26
|
} = (0, _snooplogg.default)('central:class.TmpFile');
|
|
27
|
+
|
|
20
28
|
class TmpFile {
|
|
21
29
|
/**
|
|
22
30
|
* Init temporary file if "data" is provided - write data to file (as YAML at the moment)
|
|
@@ -24,46 +32,50 @@ class TmpFile {
|
|
|
24
32
|
*/
|
|
25
33
|
constructor(data) {
|
|
26
34
|
_defineProperty(this, "file", void 0);
|
|
35
|
+
|
|
27
36
|
_defineProperty(this, "path", void 0);
|
|
28
|
-
|
|
29
|
-
// discardDescriptor = true is required for windows (fixes "file is open by another process" error).
|
|
37
|
+
|
|
38
|
+
log('crating a new file'); // discardDescriptor = true is required for windows (fixes "file is open by another process" error).
|
|
39
|
+
|
|
30
40
|
this.file = _tmp.default.fileSync({
|
|
31
41
|
discardDescriptor: true,
|
|
32
42
|
prefix: 'axway-central-edit-',
|
|
33
43
|
postfix: '.yaml'
|
|
34
44
|
});
|
|
35
45
|
this.path = this.file.name;
|
|
36
|
-
log(`file created at: ${this.path}`);
|
|
37
|
-
|
|
46
|
+
log(`file created at: ${this.path}`); // if data is provided write it to the file as YAML
|
|
47
|
+
|
|
38
48
|
data && this.write((0, _resultsRenderers.parseAsYaml)(data));
|
|
39
49
|
}
|
|
40
|
-
|
|
41
50
|
/**
|
|
42
51
|
* Delete tmp file
|
|
43
52
|
*/
|
|
53
|
+
|
|
54
|
+
|
|
44
55
|
delete() {
|
|
45
56
|
log(`removing: ${this.path}`);
|
|
46
57
|
this.file.removeCallback();
|
|
47
58
|
}
|
|
48
|
-
|
|
49
59
|
/**
|
|
50
60
|
* Write to file
|
|
51
61
|
* @param {string} data data to write
|
|
52
62
|
*/
|
|
63
|
+
|
|
64
|
+
|
|
53
65
|
write(data) {
|
|
54
66
|
log(`writing to: ${this.path}`);
|
|
55
67
|
(0, _fs.writeFileSync)(this.path, data);
|
|
56
68
|
}
|
|
57
|
-
|
|
58
69
|
/**
|
|
59
70
|
* Read file as string (as is)
|
|
60
71
|
* @return {string} data from file
|
|
61
72
|
*/
|
|
73
|
+
|
|
74
|
+
|
|
62
75
|
read() {
|
|
63
76
|
log(`reading from: ${this.path}`);
|
|
64
77
|
return (0, _fs.readFileSync)(this.path, 'utf8');
|
|
65
78
|
}
|
|
66
|
-
|
|
67
79
|
/**
|
|
68
80
|
* Open file in editor and return promise with flags indicating if edit was successful or not
|
|
69
81
|
* (process killed, vim q! happened etc. ), and if file content has been changed or not.
|
|
@@ -72,12 +84,15 @@ class TmpFile {
|
|
|
72
84
|
* isComplete: editor process completed successfully
|
|
73
85
|
* isUpdated: content of the file changed
|
|
74
86
|
*/
|
|
87
|
+
|
|
88
|
+
|
|
75
89
|
async edit() {
|
|
76
90
|
log(`editing: ${this.path}`);
|
|
77
91
|
const editorToUse = _utils.isWindows ? 'notepad' : process.env.EDITOR || 'vi';
|
|
78
92
|
const contentBeforeEdit = Buffer.from(this.read());
|
|
79
93
|
const editorExitCode = await (0, _bashCommands.editor)(editorToUse, this.path);
|
|
80
94
|
const isUpdated = !contentBeforeEdit.equals(Buffer.from(this.read()));
|
|
95
|
+
|
|
81
96
|
if (editorExitCode === 0) {
|
|
82
97
|
log('file edit has been successful');
|
|
83
98
|
return {
|
|
@@ -92,5 +107,7 @@ class TmpFile {
|
|
|
92
107
|
};
|
|
93
108
|
}
|
|
94
109
|
}
|
|
110
|
+
|
|
95
111
|
}
|
|
112
|
+
|
|
96
113
|
exports.default = TmpFile;
|
|
@@ -4,21 +4,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.openssl = exports.isOpenSslInstalled = exports.editor = exports.createTlsCert = exports.createKeyPair = void 0;
|
|
7
|
+
|
|
7
8
|
var _child_process = require("child_process");
|
|
9
|
+
|
|
8
10
|
var _path = _interopRequireDefault(require("path"));
|
|
11
|
+
|
|
9
12
|
var _snooplogg = _interopRequireDefault(require("snooplogg"));
|
|
13
|
+
|
|
10
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
11
16
|
/* istanbul ignore file */
|
|
12
17
|
// note: mocking/stubbing spawn is not a trivial task and causes some problems
|
|
13
18
|
// if done incorrectly. Need to find a good way to test it.
|
|
14
|
-
|
|
15
19
|
const {
|
|
16
20
|
log
|
|
17
|
-
} = (0, _snooplogg.default)('central: bashCommands');
|
|
21
|
+
} = (0, _snooplogg.default)('central: bashCommands'); // mask / unmask used in file paths for preventing incorrect params split in "openssl" function
|
|
18
22
|
|
|
19
|
-
// mask / unmask used in file paths for preventing incorrect params split in "openssl" function
|
|
20
23
|
const maskSpaces = str => str.replace(/ /g, '<SPACE_REPLACEMENT>');
|
|
24
|
+
|
|
21
25
|
const unmaskSpaces = str => str.replace(/<SPACE_REPLACEMENT>/g, ' ');
|
|
26
|
+
|
|
22
27
|
const openssl = (params, showStdio = false) => {
|
|
23
28
|
const parsedParams = params.split(' ').map(unmaskSpaces);
|
|
24
29
|
const process = (0, _child_process.spawn)('openssl', parsedParams, {
|
|
@@ -49,18 +54,25 @@ const openssl = (params, showStdio = false) => {
|
|
|
49
54
|
});
|
|
50
55
|
});
|
|
51
56
|
};
|
|
57
|
+
|
|
52
58
|
exports.openssl = openssl;
|
|
59
|
+
|
|
53
60
|
const isOpenSslInstalled = async () => await openssl('version').then(res => {
|
|
54
61
|
if (res && !res.isComplete) {
|
|
55
62
|
throw Error('OpenSSL is not installed, and must be installed to proceed with TLS certificate creation. Please install OpenSSL and try again.');
|
|
56
63
|
}
|
|
64
|
+
|
|
57
65
|
return true;
|
|
58
66
|
});
|
|
67
|
+
|
|
59
68
|
exports.isOpenSslInstalled = isOpenSslInstalled;
|
|
69
|
+
|
|
60
70
|
const createKeyPair = async () => {
|
|
61
71
|
// note: space in file name is not supported
|
|
62
72
|
let privateKey = _path.default.join(process.cwd(), 'private_key.pem');
|
|
73
|
+
|
|
63
74
|
let publicKey = _path.default.join(process.cwd(), 'public_key.pem');
|
|
75
|
+
|
|
64
76
|
const privKeyRes = await openssl(`genpkey -algorithm RSA -out ${maskSpaces(privateKey)} -pkeyopt rsa_keygen_bits:2048`);
|
|
65
77
|
if (privKeyRes.code === 1) throw new Error('OpenSSL failed to create the private key');
|
|
66
78
|
const pubKeyRes = await openssl(`rsa -pubout -in ${maskSpaces(privateKey)} -out ${maskSpaces(publicKey)}`);
|
|
@@ -70,11 +82,15 @@ const createKeyPair = async () => {
|
|
|
70
82
|
privateKey
|
|
71
83
|
};
|
|
72
84
|
};
|
|
85
|
+
|
|
73
86
|
exports.createKeyPair = createKeyPair;
|
|
87
|
+
|
|
74
88
|
const createTlsCert = async (secretName, domain) => {
|
|
75
89
|
// note: space in file name is not supported
|
|
76
90
|
const cert = _path.default.join(process.cwd(), `${secretName}.crt`);
|
|
91
|
+
|
|
77
92
|
const privateKey = _path.default.join(process.cwd(), `${secretName}.key`);
|
|
93
|
+
|
|
78
94
|
const output = await openssl(`req -new -newkey rsa:4096 -days 3650 -nodes -x509 -subj /C=US/ST=AZ/L=Phoenix/O=Axway/CN=${domain} -keyout ${maskSpaces(privateKey)} -out ${maskSpaces(cert)}`);
|
|
79
95
|
if (output.code === 1) throw new Error('OpenSSL failed to create the certificate');
|
|
80
96
|
return {
|
|
@@ -82,7 +98,9 @@ const createTlsCert = async (secretName, domain) => {
|
|
|
82
98
|
privateKey
|
|
83
99
|
};
|
|
84
100
|
};
|
|
101
|
+
|
|
85
102
|
exports.createTlsCert = createTlsCert;
|
|
103
|
+
|
|
86
104
|
const editor = (editor, filePath) => {
|
|
87
105
|
log(`editor ${filePath}`);
|
|
88
106
|
return new Promise(resolve => {
|
|
@@ -94,4 +112,5 @@ const editor = (editor, filePath) => {
|
|
|
94
112
|
});
|
|
95
113
|
});
|
|
96
114
|
};
|
|
115
|
+
|
|
97
116
|
exports.editor = editor;
|