@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,476 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.FormatString = FormatString;
7
- exports.KeyValueMapToNameValueArray = KeyValueMapToNameValueArray;
8
- exports.ValueFromKey = ValueFromKey;
9
- exports.parseScopeParam = exports.loadAndVerifySpecs = exports.loadAndVerifyApigeeXCredentialFile = exports.isWindows = exports.isValidJson = exports.isApiServerErrorType = exports.isApiServerErrorResponseType = exports.hbsCompare = exports.getResourceDefinition = exports.getLatestServedAPIVersion = exports.getConfig = exports.createLanguageSubresourceNames = exports.configFile = exports.compareResourcesByKindDesc = exports.compareResourcesByKindAsc = exports.buildTemplate = exports.buildGenericResource = void 0;
10
- exports.sanitizeMetadata = sanitizeMetadata;
11
- exports.writeToFile = exports.writeTemplates = exports.wait = exports.verifyScopeParam = exports.verifyFile = exports.transformSimpleFilters = void 0;
12
- var _fsExtra = require("fs-extra");
13
- var _handlebars = _interopRequireDefault(require("handlebars"));
14
- var _jsYaml = require("js-yaml");
15
- var _os = require("os");
16
- var _path = require("path");
17
- var _ApiServerClient = require("./ApiServerClient");
18
- var _CompositeError = require("./CompositeError");
19
- var _types = require("./types");
20
- var _chalk = _interopRequireDefault(require("chalk"));
21
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
22
- const isWindows = exports.isWindows = /^win/.test(process.platform);
23
- const configFile = exports.configFile = (0, _path.join)((0, _os.homedir)(), '.axway', 'central.json');
24
- const getConfig = async () => !(0, _fsExtra.existsSync)(configFile) ? Promise.resolve({}) : await (0, _fsExtra.readJson)(configFile);
25
- exports.getConfig = getConfig;
26
- const verifyFile = specFilePath => {
27
- let stats;
28
- let fileExtension;
29
- try {
30
- stats = (0, _fsExtra.lstatSync)(specFilePath);
31
- fileExtension = (0, _path.extname)(specFilePath);
32
- } catch (e) {
33
- throw new Error(`Couldn't find the definition file: ${specFilePath}`);
34
- }
35
- if (!stats.isFile()) {
36
- throw new Error(`Couldn't load the definition file: ${specFilePath}`);
37
- } else if (stats.size >= _types.MAX_FILE_SIZE) {
38
- throw new Error(`File size too large`);
39
- } else if (fileExtension !== '.yaml' && fileExtension !== '.yml' && fileExtension !== '.json') {
40
- throw new Error(`File extension is invalid, please provide '.yaml' or '.yml' or '.json' file`);
41
- }
42
- };
43
- exports.verifyFile = verifyFile;
44
- const writeToFile = (path, data) => {
45
- try {
46
- (0, _fsExtra.writeFileSync)(path, data);
47
- } catch (e) {
48
- // if parser is failing, rethrow with our own error
49
- throw new Error(`Error while writing the yaml file to: ${path}`);
50
- }
51
- };
52
-
53
- /**
54
- * Checks if the passed item can be converted to a JSON or is a valid JSON object.
55
- * @param item item to check
56
- * @returns true if the item can be converted, false otherwise.
57
- */
58
- exports.writeToFile = writeToFile;
59
- const isValidJson = item => {
60
- let parsedItem = typeof item !== 'string' ? JSON.stringify(item) : item;
61
- try {
62
- parsedItem = JSON.parse(parsedItem);
63
- } catch (e) {
64
- return false;
65
- }
66
- return typeof parsedItem === 'object' && item !== null;
67
- };
68
-
69
- /**
70
- * Loads and parse file from path, accepts JSON and YAML files. Also completing validation on "kind" values.
71
- * @param specFilePath file path
72
- * @param allowedKinds array of allowed "kind" values
73
- */
74
- exports.isValidJson = isValidJson;
75
- const loadAndVerifySpecs = async (specFilePath, allowedKinds, skipKindCheck) => {
76
- // Load the given JSON or YAML file.
77
- let docs = [];
78
- let isMissingName = false;
79
- try {
80
- docs = (0, _jsYaml.loadAll)(await (0, _fsExtra.readFile)(specFilePath, 'utf8'));
81
- } catch (e) {
82
- throw new Error(e.reason && e.reason.includes('null byte') ? `File encoding is invalid, please make sure it is using UTF-8` : `File content is invalid.`);
83
- }
84
-
85
- // if user pass an array of json objects, docs const will have nested array, workaround for this:
86
- if ((0, _path.extname)(specFilePath) === '.json' && docs.length === 1 && Array.isArray(docs[0])) {
87
- docs = docs[0];
88
- }
89
-
90
- // Do not continue if given an empty file.
91
- if (!docs.length) throw new Error(`File is empty.`);
92
-
93
- // Validate all entries in the file.
94
- const errors = [];
95
- const createErrorPrefix = (index, kind, name) => {
96
- return `Entry ${index + 1}, "${kind}/${name || 'Unknown name'}"`;
97
- };
98
- for (let index = 0; index < docs.length; index++) {
99
- // Verify document is defined/valid.
100
- const doc = docs[index];
101
- if (typeof doc !== 'object' || !doc) {
102
- errors.push(new Error(`${createErrorPrefix(index)}: Entry format is invalid.`));
103
- continue;
104
- }
105
-
106
- // Set a flag if at least 1 name is messing in file.
107
- if (!doc.name) {
108
- isMissingName = true;
109
- }
110
- if (!skipKindCheck) {
111
- // Validate resource kind.
112
- if (!doc.kind) {
113
- errors.push(Error(`${createErrorPrefix(index, doc.kind, doc.name)}: The "kind" field is missing.` + `\nCurrently supported values are (case sensitive): ${[...allowedKinds.values()].join(', ')}`));
114
- } else if (!allowedKinds.has(doc.kind)) {
115
- errors.push(new Error(`${createErrorPrefix(index, doc.kind, doc.name)}: Kind "${doc.kind}" is unsupported.` + `\nCurrently supported values are (case sensitive): ${[...allowedKinds.values()].join(', ')}`));
116
- }
117
- }
118
-
119
- // TODO: Validate "metadata.scope.kind" if available. Requires DefinitionManager.getSortedKindsMap() result.
120
- }
121
- if (errors.length > 0) {
122
- throw new _CompositeError.CompositeError(errors);
123
- }
124
-
125
- // File's contents appears to be valid. Return loaded info.
126
- return {
127
- docs,
128
- isMissingName
129
- };
130
- };
131
-
132
- /**
133
- * Generate a GenericResource instance from resource definition, resource name, and scope name. Used
134
- * in some rendering logic for the "delete" command.
135
- * Note that generated metadata includes only scope info.
136
- * @param {ResourceDefinition} resourceDef resource definition
137
- * @param {string} resourceName resource name
138
- * @param {string} scopeName optional scope name
139
- * @returns {GenericResource} generic resource representation
140
- */
141
- exports.loadAndVerifySpecs = loadAndVerifySpecs;
142
- const buildGenericResource = ({
143
- resourceDef,
144
- resourceName,
145
- scopeName
146
- }) => {
147
- if (resourceName) {
148
- var _resourceDef$spec, _resourceDef$spec2, _resourceDef$spec2$sc;
149
- return {
150
- apiVersion: resourceDef === null || resourceDef === void 0 ? void 0 : resourceDef.apiVersion,
151
- group: resourceDef === null || resourceDef === void 0 ? void 0 : resourceDef.group,
152
- title: resourceName,
153
- name: resourceName,
154
- kind: resourceDef === null || resourceDef === void 0 ? void 0 : resourceDef.spec.kind,
155
- attributes: {},
156
- tags: [],
157
- metadata: resourceDef !== null && resourceDef !== void 0 && (_resourceDef$spec = resourceDef.spec) !== null && _resourceDef$spec !== void 0 && _resourceDef$spec.scope && scopeName ? {
158
- scope: {
159
- kind: resourceDef === null || resourceDef === void 0 ? void 0 : (_resourceDef$spec2 = resourceDef.spec) === null || _resourceDef$spec2 === void 0 ? void 0 : (_resourceDef$spec2$sc = _resourceDef$spec2.scope) === null || _resourceDef$spec2$sc === void 0 ? void 0 : _resourceDef$spec2$sc.kind,
160
- name: scopeName
161
- }
162
- // note: forced conversion here only because using generated resources for rendering simple text
163
- } : undefined,
164
- spec: {}
165
- };
166
- } else {
167
- var _resourceDef$spec3, _resourceDef$spec4, _resourceDef$spec4$sc;
168
- return {
169
- apiVersion: resourceDef === null || resourceDef === void 0 ? void 0 : resourceDef.apiVersion,
170
- group: resourceDef === null || resourceDef === void 0 ? void 0 : resourceDef.group,
171
- kind: resourceDef === null || resourceDef === void 0 ? void 0 : resourceDef.spec.kind,
172
- attributes: {},
173
- tags: [],
174
- metadata: resourceDef !== null && resourceDef !== void 0 && (_resourceDef$spec3 = resourceDef.spec) !== null && _resourceDef$spec3 !== void 0 && _resourceDef$spec3.scope && scopeName ? {
175
- scope: {
176
- kind: resourceDef === null || resourceDef === void 0 ? void 0 : (_resourceDef$spec4 = resourceDef.spec) === null || _resourceDef$spec4 === void 0 ? void 0 : (_resourceDef$spec4$sc = _resourceDef$spec4.scope) === null || _resourceDef$spec4$sc === void 0 ? void 0 : _resourceDef$spec4$sc.kind,
177
- name: scopeName
178
- }
179
- // note: forced conversion here only because using generated resources for rendering simple text
180
- } : undefined,
181
- spec: {}
182
- };
183
- }
184
- };
185
-
186
- /**
187
- * Returns true if error object is of type ApiServerError
188
- * @param err error object to check
189
- */
190
- exports.buildGenericResource = buildGenericResource;
191
- const isApiServerErrorType = err => {
192
- const cast = err;
193
- return !!cast.status && !!cast.title && !!cast.detail;
194
- };
195
-
196
- /**
197
- * Returns true if error object is of type ApiServerErrorResponse
198
- * @param err error object to check
199
- */
200
- exports.isApiServerErrorType = isApiServerErrorType;
201
- const isApiServerErrorResponseType = err => {
202
- const cast = err;
203
- return !!cast.errors && Array.isArray(cast.errors);
204
- };
205
-
206
- /**
207
- * Wrapper to return a compare function for sorting by "kind" value in array of resources in ascending
208
- * order. Order based on "sortedKindValues" array.
209
- * @param {Array<ResourceDefinition>} sortedResourceDefs array of ResourceDefinitions defining a required order of the resources.
210
- * @returns {Function} Array sorting function
211
- */
212
- exports.isApiServerErrorResponseType = isApiServerErrorResponseType;
213
- const compareResourcesByKindAsc = sortedResourceDefs => (a, b) => sortedResourceDefs.findIndex(def => {
214
- var _def$spec$scope, _a$metadata, _a$metadata$scope;
215
- return def.spec.kind === a.kind && ((_def$spec$scope = def.spec.scope) === null || _def$spec$scope === void 0 ? void 0 : _def$spec$scope.kind) === ((_a$metadata = a.metadata) === null || _a$metadata === void 0 ? void 0 : (_a$metadata$scope = _a$metadata.scope) === null || _a$metadata$scope === void 0 ? void 0 : _a$metadata$scope.kind);
216
- }) - sortedResourceDefs.findIndex(def => {
217
- var _def$spec$scope2, _b$metadata, _b$metadata$scope;
218
- return def.spec.kind === b.kind && ((_def$spec$scope2 = def.spec.scope) === null || _def$spec$scope2 === void 0 ? void 0 : _def$spec$scope2.kind) === ((_b$metadata = b.metadata) === null || _b$metadata === void 0 ? void 0 : (_b$metadata$scope = _b$metadata.scope) === null || _b$metadata$scope === void 0 ? void 0 : _b$metadata$scope.kind);
219
- });
220
-
221
- /**
222
- * Wrapper to return a compare function for sorting by "kind" value in array of resources in descending
223
- * order. Order based on "sortedKindValues" array.
224
- * @param {Array<ResourceDefinition>} sortedResourceDefs array of ResourceDefinitions defining a required order of the resources.
225
- * @returns {Function} Array sorting function
226
- */
227
- exports.compareResourcesByKindAsc = compareResourcesByKindAsc;
228
- const compareResourcesByKindDesc = sortedResourceDefs => (a, b) => sortedResourceDefs.findIndex(def => {
229
- var _def$spec$scope3, _b$metadata2, _b$metadata2$scope;
230
- return def.spec.kind === b.kind && ((_def$spec$scope3 = def.spec.scope) === null || _def$spec$scope3 === void 0 ? void 0 : _def$spec$scope3.kind) === ((_b$metadata2 = b.metadata) === null || _b$metadata2 === void 0 ? void 0 : (_b$metadata2$scope = _b$metadata2.scope) === null || _b$metadata2$scope === void 0 ? void 0 : _b$metadata2$scope.kind);
231
- }) - sortedResourceDefs.findIndex(def => {
232
- var _def$spec$scope4, _a$metadata2, _a$metadata2$scope;
233
- return def.spec.kind === a.kind && ((_def$spec$scope4 = def.spec.scope) === null || _def$spec$scope4 === void 0 ? void 0 : _def$spec$scope4.kind) === ((_a$metadata2 = a.metadata) === null || _a$metadata2 === void 0 ? void 0 : (_a$metadata2$scope = _a$metadata2.scope) === null || _a$metadata2$scope === void 0 ? void 0 : _a$metadata2$scope.kind);
234
- });
235
-
236
- /**
237
- * Api-server returns the "resourceVersion" in metadata object as a counter for resource updates.
238
- * If a user will send this key in the payload it will throw an error so using this helper to sanitizing metadata on
239
- * the updates.
240
- * @param doc resource data
241
- * @returns {GenericResource} resource data without metadata.resourceVersion key
242
- */
243
- exports.compareResourcesByKindDesc = compareResourcesByKindDesc;
244
- function sanitizeMetadata(doc) {
245
- var _doc$metadata;
246
- if (doc !== null && doc !== void 0 && (_doc$metadata = doc.metadata) !== null && _doc$metadata !== void 0 && _doc$metadata.resourceVersion) {
247
- delete doc.metadata.resourceVersion;
248
- }
249
- return doc;
250
- }
251
- const buildTemplate = (templateFunc, input) => {
252
- const template = _handlebars.default.compile(templateFunc(), {
253
- noEscape: true
254
- });
255
- return template(input);
256
- };
257
-
258
- /**
259
- * Takes in a set of parameters (values), compiles a string utilizing the provided handlebars templating function (templateFunc)
260
- * and the buildTemplate function with those parameters, and finally writes the output string to a file of the name that was provided (fileName).
261
- * @param {string} fileName
262
- * @param {object} values
263
- * @param {()=>string} templateFunc
264
- */
265
- exports.buildTemplate = buildTemplate;
266
- const writeTemplates = (fileName, values, templateFunc) => {
267
- const data = buildTemplate(templateFunc, values);
268
- writeToFile(fileName, data);
269
- };
270
-
271
- /**
272
- * helper function to extend the handlebars built-in helpers functionality to add a way to compare equality of two strings or numbers
273
- * @param {string|number} lvalue
274
- * @param {string|number} rvalue
275
- * @param {{fn:(} options
276
- */
277
- exports.writeTemplates = writeTemplates;
278
- const hbsCompare = () => {
279
- _handlebars.default.registerHelper('compare', (context, lvalue, rvalue, options) => {
280
- let operator = options.hash.operator || '===';
281
- let operators = {
282
- '==': (l, r) => {
283
- return l == r;
284
- },
285
- '===': (l, r) => {
286
- return l === r;
287
- },
288
- '!=': (l, r) => {
289
- return l != r;
290
- },
291
- '<': (l, r) => {
292
- return l < r;
293
- },
294
- '>': (l, r) => {
295
- return l > r;
296
- },
297
- '<=': (l, r) => {
298
- return l <= r;
299
- },
300
- '>=': (l, r) => {
301
- return l >= r;
302
- },
303
- typeof: (l, r) => {
304
- return typeof l == r;
305
- }
306
- };
307
- var result = operators[operator](lvalue, rvalue);
308
- if (result) {
309
- return options.fn(context);
310
- } else {
311
- return options.inverse(context);
312
- }
313
- });
314
- };
315
-
316
- /**
317
- * Parse and verify scope param, returns undefined if param is undefined. Throws an error if "Kind" is unknown.
318
- * @param scopeParam raw scope param value
319
- * @returns {ParsedScopeParam | undefined}
320
- */
321
- exports.hbsCompare = hbsCompare;
322
- const parseScopeParam = scopeParam => {
323
- if (!scopeParam) return undefined;
324
- let sp = scopeParam.toString();
325
- if (sp.indexOf('/') === -1) return {
326
- name: scopeParam
327
- };else {
328
- const name = sp.substring(scopeParam.indexOf('/') + 1);
329
- const kind = sp.substring(0, scopeParam.indexOf('/'));
330
- if (!name.length || !kind.length) throw Error(`invalid scope (-s/--scope) parameter value.` + `\nPlease use "--scope <scope kind>/<scope name>" or "--scope <scope name>" formats.`);
331
- return {
332
- name,
333
- kind
334
- };
335
- }
336
- };
337
-
338
- /**
339
- * Verify parsed scope param:
340
- * 1. scope kind should be known.
341
- * 2. scope kind should match at least one in a resource "scoped" definitions ("non-scoped" definition will be ignored).
342
- * @param allKinds all available kinds.
343
- * @param defs resource definitions where at least one should match the scope kind if some "scoped" resources are there.
344
- * @param scopeParam parsed scope param.
345
- */
346
- exports.parseScopeParam = parseScopeParam;
347
- const verifyScopeParam = (allKinds, defs, scopeParam) => {
348
- const allowedScopeKinds = new Set();
349
- defs.forEach(defs => !!defs.scope && allowedScopeKinds.add(defs.scope.spec.kind));
350
- if (scopeParam !== null && scopeParam !== void 0 && scopeParam.kind) {
351
- if (!allKinds.has(scopeParam.kind)) throw new Error(`unsupported kind value "${scopeParam.kind}" in the "--scope" param.` + `\nCurrently supported values are (case sensitive): ${[...allKinds.values()].join(', ')}`);
352
- if (allowedScopeKinds.size > 0 && !allowedScopeKinds.has(scopeParam.kind)) throw Error(`scope kind "${scopeParam.kind}" is invalid.` + `\n"${defs[0].resource.spec.kind}" resource might exist in the following scopes: ${[...allowedScopeKinds.values()].join(', ')}`);
353
- }
354
- };
355
-
356
- /**
357
- * Transforms simple filters(title, attribute, tag) into an RSQL-formatted query string the GET API supports.
358
- * @param {string} title The title the user wants to filter the resource list by.
359
- * @param {string} attribute The attribute(key=value) the user wants to filter the resource list by.
360
- * @param {string} tag The tag the user wants to filter the resource list by.
361
- * @returns {string} transformedFilter, the RSQL formatted query string
362
- */
363
- exports.verifyScopeParam = verifyScopeParam;
364
- const transformSimpleFilters = (title, attribute, tag) => {
365
- const titleFilter = title ? `title=='*${title}*'` : '';
366
- const attributeKey = attribute && attribute.split('=')[0];
367
- const attributeValue = attribute && attribute.split('=')[1];
368
- const attributeFilter = attributeKey && attributeValue ? `attributes.${attributeKey}==${attributeValue}` : '';
369
- const tagFilter = tag ? `tags==${tag}` : '';
370
- const formattedFilter = `${titleFilter && `${titleFilter};`}${attributeFilter && `${attributeFilter};`}${tagFilter}`;
371
- const transformedFilter = formattedFilter.charAt(formattedFilter.length - 1) === ';' ? formattedFilter.slice(0, -1) : formattedFilter;
372
- return transformedFilter;
373
- };
374
- exports.transformSimpleFilters = transformSimpleFilters;
375
- function FormatString(str, ...val) {
376
- for (let index = 0; index < val.length; index++) {
377
- str = str.replace(`{${index}}`, val[index]);
378
- }
379
- return str;
380
- }
381
-
382
- /**
383
- * Loads and parse file from path, accepts JSON file. Also validates additional details.
384
- * @param credentialFilePath file path
385
- */
386
- const loadAndVerifyApigeeXCredentialFile = async credentialFilePath => {
387
- // Load the given JSON file.
388
- let fileInfo = '';
389
- try {
390
- fileInfo = await (0, _fsExtra.readJson)(credentialFilePath);
391
- } catch (e) {
392
- throw new Error(e.reason);
393
- }
394
-
395
- // Do not continue if given an empty file.
396
- if (fileInfo === '') throw new Error(`File is empty.`);
397
-
398
- // TODO: Validate additional details if needed
399
-
400
- // Return loaded info.
401
- return fileInfo;
402
- };
403
- exports.loadAndVerifyApigeeXCredentialFile = loadAndVerifyApigeeXCredentialFile;
404
- function KeyValueMapToNameValueArray(m) {
405
- let array = [];
406
- m.forEach((value, key) => {
407
- array.push({
408
- name: key,
409
- value: value
410
- });
411
- });
412
- if (array.length == 0) {
413
- return undefined;
414
- }
415
- return array;
416
- }
417
- const createLanguageSubresourceNames = langCode => {
418
- const langCodeArr = langCode.split(',');
419
- let langSubresourceNamesArr = ['languages'];
420
- let languageTypesArr = [];
421
- Object.keys(_types.LanguageTypes).forEach(key => languageTypesArr.push(ValueFromKey(_types.LanguageTypes, key)));
422
- langCodeArr.forEach(langCode => {
423
- if (langCode.trim() != '') {
424
- if (!languageTypesArr.includes(langCode)) {
425
- console.log(_chalk.default.yellow(`\n\'${langCode}\' language code is not supported, hence create/update cannot be performed on \'languages-${langCode}\. Allowed language codes: ${_types.LanguageTypes.French} | ${_types.LanguageTypes.German} | ${_types.LanguageTypes.US} | ${_types.LanguageTypes.Portugese}.'`));
426
- } else {
427
- langSubresourceNamesArr.push(`languages-${langCode.trim()}`);
428
- }
429
- }
430
- });
431
- return langSubresourceNamesArr;
432
- };
433
- exports.createLanguageSubresourceNames = createLanguageSubresourceNames;
434
- function ValueFromKey(stringEnum, key) {
435
- for (const k of Object.values(stringEnum)) {
436
- if (k === stringEnum[key]) return k;
437
- }
438
- return undefined;
439
- }
440
- const getLatestServedAPIVersion = resourceDef => {
441
- let apiVersions = resourceDef.spec.apiVersions;
442
- if (apiVersions && apiVersions.length > 0) {
443
- for (const version of apiVersions) {
444
- if (version.served && !version.deprecated) {
445
- return version.name;
446
- }
447
- }
448
- return _ApiServerClient.ApiServerVersions.v1alpha1;
449
- }
450
- // if the apiVersions are not set on the resource definition, fallback to v1alpha1 version
451
- return _ApiServerClient.ApiServerVersions.v1alpha1;
452
- };
453
-
454
- /**
455
- * Wait for the given milliseconds
456
- * @param {number} ms The given time to wait
457
- * @returns {Promise} A fulfilled promise after the given time has passed
458
- */
459
- exports.getLatestServedAPIVersion = getLatestServedAPIVersion;
460
- const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
461
-
462
- /**
463
- * Fetch resource definition of given kind and scope kind if exists
464
- * @param {ResourceDefinition[]} sortedDefsArray The given time to wait
465
- * @param {Kind} kind The kind of the resource
466
- * @param {Kind} scopeKind The scope kind of the resource
467
- */
468
- exports.wait = wait;
469
- const getResourceDefinition = async (sortedDefsArray, kind, scopeKind) => {
470
- const resourceDefinition = sortedDefsArray.find(def => {
471
- var _def$spec$scope5;
472
- return scopeKind ? def.spec.kind === kind && ((_def$spec$scope5 = def.spec.scope) === null || _def$spec$scope5 === void 0 ? void 0 : _def$spec$scope5.kind) === scopeKind : def.spec.kind === kind;
473
- });
474
- return resourceDefinition;
475
- };
476
- exports.getResourceDefinition = getResourceDefinition;
package/dist/main.js DELETED
@@ -1,8 +0,0 @@
1
- "use strict";
2
-
3
- var _cli = _interopRequireDefault(require("./cli"));
4
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
5
- _cli.default.exec().catch(err => {
6
- console.error(err);
7
- process.exit(err.exitCode || 1);
8
- });