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