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