@axway/axway-central-cli 2.17.0 → 2.18.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 (58) hide show
  1. package/dist/cli.js +6 -28
  2. package/dist/commands/apply/index.js +9 -24
  3. package/dist/commands/completion/index.js +3 -9
  4. package/dist/commands/config/common/index.js +2 -11
  5. package/dist/commands/config/index.js +2 -7
  6. package/dist/commands/config/list.js +2 -6
  7. package/dist/commands/config/set.js +4 -31
  8. package/dist/commands/config/unset.js +2 -12
  9. package/dist/commands/create/agentResource.js +12 -32
  10. package/dist/commands/create/environment.js +6 -16
  11. package/dist/commands/create/index.js +9 -26
  12. package/dist/commands/create/serviceAccount.js +2 -6
  13. package/dist/commands/delete/index.js +15 -33
  14. package/dist/commands/edit/environment.js +6 -21
  15. package/dist/commands/edit/index.js +4 -8
  16. package/dist/commands/get/index.js +27 -44
  17. package/dist/commands/install/agents.js +44 -73
  18. package/dist/commands/install/apigeexSaasAgents.js +35 -98
  19. package/dist/commands/install/awsAgents.js +89 -139
  20. package/dist/commands/install/awsSaasAgents.js +50 -142
  21. package/dist/commands/install/azureAgents.js +39 -79
  22. package/dist/commands/install/edgeAgents.js +17 -110
  23. package/dist/commands/install/gitHubSaasAgents.js +286 -0
  24. package/dist/commands/install/helpers/creators.js +17 -70
  25. package/dist/commands/install/helpers/deleters.js +2 -11
  26. package/dist/commands/install/helpers/getters.js +4 -30
  27. package/dist/commands/install/helpers/index.js +13 -48
  28. package/dist/commands/install/helpers/inputs.js +26 -98
  29. package/dist/commands/install/helpers/regex.js +29 -34
  30. package/dist/commands/install/helpers/templates/awsTemplates.js +6 -23
  31. package/dist/commands/install/helpers/templates/azureTemplates.js +5 -24
  32. package/dist/commands/install/helpers/templates/edgeTemplates.js +7 -38
  33. package/dist/commands/install/helpers/templates/istioTemplates.js +5 -16
  34. package/dist/commands/install/index.js +4 -10
  35. package/dist/commands/install/istioAgents.js +40 -117
  36. package/dist/commands/install/platform.js +20 -52
  37. package/dist/commands/proxies/create.js +2 -18
  38. package/dist/commands/proxies/index.js +4 -8
  39. package/dist/commands/proxies/promote.js +2 -21
  40. package/dist/common/ApiServerClient.js +64 -173
  41. package/dist/common/CacheController.js +11 -32
  42. package/dist/common/CliConfigManager.js +14 -27
  43. package/dist/common/CompositeError.js +6 -30
  44. package/dist/common/CoreConfigController.js +18 -40
  45. package/dist/common/DefinitionsManager.js +29 -76
  46. package/dist/common/Kubectl.js +2 -25
  47. package/dist/common/PlatformClient.js +19 -63
  48. package/dist/common/Renderer.js +25 -87
  49. package/dist/common/TmpFile.js +11 -28
  50. package/dist/common/bashCommands.js +3 -22
  51. package/dist/common/basicPrompts.js +8 -43
  52. package/dist/common/dataService.js +22 -50
  53. package/dist/common/errorHandler.js +0 -9
  54. package/dist/common/resultsRenderers.js +10 -42
  55. package/dist/common/types.js +116 -341
  56. package/dist/common/utils.js +37 -99
  57. package/dist/main.js +0 -2
  58. package/package.json +2 -2
@@ -4,44 +4,30 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.DefinitionsManager = void 0;
7
-
8
7
  var _snooplogg = _interopRequireDefault(require("snooplogg"));
9
-
10
8
  var _easyTable = _interopRequireDefault(require("easy-table"));
11
-
12
9
  var _findIndex = _interopRequireDefault(require("lodash/findIndex"));
13
-
14
10
  var _findLastIndex = _interopRequireDefault(require("lodash/findLastIndex"));
15
-
16
11
  var _omit = _interopRequireDefault(require("lodash/omit"));
17
-
18
12
  var _max2 = _interopRequireDefault(require("lodash/max"));
19
-
20
13
  var _min2 = _interopRequireDefault(require("lodash/min"));
21
-
22
14
  var _chalk = require("chalk");
23
-
24
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
-
26
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
27
-
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
  const {
29
20
  log
30
21
  } = (0, _snooplogg.default)('central:class.DefinitionsManager');
31
-
32
22
  /**
33
23
  * Get / fetch / set specs.
34
24
  */
35
25
  class DefinitionsManager {
36
26
  constructor(apiServerClient) {
37
27
  _defineProperty(this, "apiServerClient", void 0);
38
-
39
28
  _defineProperty(this, "specs", void 0);
40
-
41
29
  _defineProperty(this, "cli", new Map());
42
-
43
30
  _defineProperty(this, "resources", new Map());
44
-
45
31
  this.apiServerClient = apiServerClient;
46
32
  }
47
33
  /**
@@ -59,80 +45,68 @@ class DefinitionsManager {
59
45
  * @param curr
60
46
  * @param defsFrom
61
47
  */
62
-
63
-
64
48
  reduceByReferenceLinks(curr, defsFrom) {
65
49
  return curr.unsorted.reduce((a, c, _, arr) => {
66
50
  // IF any unsorted reference found, push current definition to unsorted too and skip
67
51
  const unsortedRefs = c.spec.references.toResources.find(ref => {
68
52
  return (0, _findLastIndex.default)(arr, def => {
69
53
  var _def$spec$scope;
70
-
71
54
  return def.spec.kind === ref.kind && ((_def$spec$scope = def.spec.scope) === null || _def$spec$scope === void 0 ? void 0 : _def$spec$scope.kind) === ref.scopeKind;
72
55
  }) !== -1;
73
56
  });
74
-
75
57
  if (!!unsortedRefs) {
76
58
  a.unsorted.push(c);
77
59
  } else {
78
60
  var _max, _min;
79
-
80
61
  // ELSE all refs are in pre populated or in sorted lists, calculate
81
62
  const startIndex = (_max = (0, _max2.default)(c.spec.references.toResources.map(ref => {
82
63
  // find index in current sorted array
83
64
  const sortedListIndex = (0, _findLastIndex.default)(a.sorted, def => {
84
65
  var _def$spec$scope2;
85
-
86
66
  return def.spec.kind === ref.kind && ((_def$spec$scope2 = def.spec.scope) === null || _def$spec$scope2 === void 0 ? void 0 : _def$spec$scope2.kind) === ref.scopeKind;
87
- }); // find index in "from-only" array
88
-
67
+ });
68
+ // find index in "from-only" array
89
69
  const fromListIndex = (0, _findLastIndex.default)(defsFrom, def => {
90
70
  var _def$spec$scope3;
91
-
92
71
  return def.spec.kind === ref.kind && ((_def$spec$scope3 = def.spec.scope) === null || _def$spec$scope3 === void 0 ? void 0 : _def$spec$scope3.kind) === ref.scopeKind;
93
- }); // this should never happen only if the api-server is missing some corresponding
72
+ });
73
+ // this should never happen only if the api-server is missing some corresponding
94
74
  // references so nothing found
95
-
96
75
  if (sortedListIndex === -1 && fromListIndex === -1) {
97
76
  var _c$spec$scope;
98
-
99
77
  log('reduceByReferenceLinks, startIndex error, def: ', JSON.stringify(c, null, 2), '\nref: ', ref);
100
78
  throw Error(`References calculation error, startIndex for kind: ${c.spec.kind} in scope: ${(_c$spec$scope = c.spec.scope) === null || _c$spec$scope === void 0 ? void 0 : _c$spec$scope.kind}`);
101
- } // if nothing found in sorted and pre return null so it will put it back to unsorted
79
+ }
80
+ // if nothing found in sorted and pre return null so it will put it back to unsorted
102
81
  else return sortedListIndex === -1 ? 0 : sortedListIndex;
103
82
  }))) !== null && _max !== void 0 ? _max : null;
104
83
  const stopIndex = (_min = (0, _min2.default)(c.spec.references.fromResources.map(ref => {
105
84
  const i = (0, _findIndex.default)(a.sorted, def => {
106
85
  var _def$spec$scope4;
107
-
108
86
  return def.spec.kind === ref.kind && ((_def$spec$scope4 = def.spec.scope) === null || _def$spec$scope4 === void 0 ? void 0 : _def$spec$scope4.kind) === ref.scopeKind;
109
87
  });
110
88
  return i === -1 ? null : i;
111
89
  }))) !== null && _min !== void 0 ? _min : null;
112
-
113
90
  if (startIndex && stopIndex && startIndex >= stopIndex || startIndex === null) {
114
91
  var _c$spec$scope2;
115
-
116
92
  log('reduceByReferenceLinks, indexes error, definition: ', JSON.stringify(c, null, 2));
117
93
  throw Error(`References calculation error, indexes for kind: ${c.spec.kind} in scope: ${(_c$spec$scope2 = c.spec.scope) === null || _c$spec$scope2 === void 0 ? void 0 : _c$spec$scope2.kind}`);
118
94
  } else {
119
95
  a.sorted.splice(startIndex + 1, 0, c);
120
96
  }
121
97
  }
122
-
123
98
  return a;
124
99
  }, {
125
100
  sorted: curr.sorted,
126
101
  unsorted: []
127
102
  });
128
103
  }
104
+
129
105
  /**
130
106
  * Utility for sorting ResourceDefinition by refs. Its grouping resources into 4 arrays and
131
107
  * iterates over the "fromTo" list with "reduceByReferenceLinks" reducer until its completely sorted.
132
108
  * @param defs list of resources to sort
133
109
  */
134
-
135
-
136
110
  sortByReferences(defs) {
137
111
  // 1. Sort by references into 4 arrays
138
112
  const groupedDefs = defs.reduce((a, c) => {
@@ -145,24 +119,24 @@ class DefinitionsManager {
145
119
  from: [],
146
120
  fromTo: [],
147
121
  to: []
148
- }); // 2. Iterate over "fromTo" defs until its completely sorted
122
+ });
149
123
 
124
+ // 2. Iterate over "fromTo" defs until its completely sorted
150
125
  let result = this.reduceByReferenceLinks({
151
126
  sorted: [],
152
127
  unsorted: groupedDefs.fromTo
153
128
  }, groupedDefs.from);
154
129
  let loopCount = 0; // just in case, circuit breaker;
155
-
156
130
  while (result.unsorted.length > 0 && loopCount <= 1000) {
157
131
  result = this.reduceByReferenceLinks(result, groupedDefs.from);
158
132
  loopCount += 1;
159
- } // On average function should not take more than 5 loops currently.
133
+ }
134
+ // On average function should not take more than 5 loops currently.
160
135
  // Lets signal that something is wrong here.
161
-
162
-
163
136
  if (loopCount === 1000) throw Error('Definition references calculation error, max loop count reached');
164
137
  return [...groupedDefs.noRefs, ...groupedDefs.from, ...result.sorted, ...groupedDefs.to];
165
138
  }
139
+
166
140
  /**
167
141
  * Public
168
142
  * Constructs two maps per resource group(e.g. management, catalog)
@@ -170,25 +144,20 @@ class DefinitionsManager {
170
144
  * Created by stripping the 'definitions' group from the specs object, leaving only the 'management' and 'catalog' groups as of 6/7(this will dynamically update in case new groups are added on api-server)
171
145
  * Then iterating over that specs object and pushing the cli and resource objects for each group into arrays, which are used to initialize the final maps
172
146
  */
173
-
174
-
175
147
  async init() {
176
148
  log('init');
177
149
  this.specs = await this.apiServerClient.getSpecs();
178
150
  const filteredSpecs = (0, _omit.default)(this.specs, 'definitions');
179
151
  const cliArray = [];
180
152
  const resourcesArray = [];
181
-
182
153
  for (const [key] of Object.entries(filteredSpecs)) {
183
154
  resourcesArray.push(...filteredSpecs[key].resources);
184
155
  cliArray.push(...filteredSpecs[key].cli);
185
156
  }
186
-
187
157
  this.cli = new Map(cliArray);
188
158
  this.resources = new Map(resourcesArray);
189
159
  return this;
190
160
  }
191
-
192
161
  getAllWordsList() {
193
162
  if (!this.specs) return [];
194
163
  const result = [];
@@ -197,7 +166,6 @@ class DefinitionsManager {
197
166
  });
198
167
  return result;
199
168
  }
200
-
201
169
  getAllKindsList() {
202
170
  if (!this.specs) throw Error('DefinitionManager.specs is not initialized.');
203
171
  const result = new Set([]);
@@ -206,37 +174,33 @@ class DefinitionsManager {
206
174
  });
207
175
  return result;
208
176
  }
177
+
209
178
  /**
210
179
  * Get the map with resources definitions sorted by references.
211
180
  * Used to identify the correct order in which resources should be created / removed.
212
181
  * @returns {Map<string,ResourceDefinition>} map where key is ResourceDefinition.name, value is ResourceDefinition
213
182
  */
214
-
215
-
216
183
  getSortedKindsMap() {
217
- if (!this.specs) throw Error('DefinitionManager.specs is not initialized.'); // For each spec modify the references:
184
+ if (!this.specs) throw Error('DefinitionManager.specs is not initialized.');
185
+ // For each spec modify the references:
218
186
  // 1. since cli do not support creating or updating sub-resources we are ignoring references and removing them atm.
219
187
  // 2. if it is a scoped resource, add a manual "to" reference to the scope resource and a corresponding "from"
220
188
  // reference in the scope resource
221
-
222
189
  this.resources.forEach(definition => {
223
190
  // 1. remove the references from the sub-resources and circular references (to self)
224
191
  // TODO: circular references support: https://jira.axway.com/browse/APIGOV-20808
225
192
  definition.spec.references.toResources = definition.spec.references.toResources.filter(ref => {
226
193
  var _definition$spec$scop;
227
-
228
194
  return !ref.from && !(ref.kind === definition.spec.kind && ref.scopeKind === ((_definition$spec$scop = definition.spec.scope) === null || _definition$spec$scop === void 0 ? void 0 : _definition$spec$scop.kind));
229
195
  });
230
196
  definition.spec.references.fromResources = definition.spec.references.fromResources.filter(ref => {
231
197
  var _definition$spec$scop2;
232
-
233
198
  return !ref.from && !(ref.kind === definition.spec.kind && ref.scopeKind === ((_definition$spec$scop2 = definition.spec.scope) === null || _definition$spec$scop2 === void 0 ? void 0 : _definition$spec$scop2.kind));
234
- }); // 2. add references between scope and scoped resources
235
-
199
+ });
200
+ // 2. add references between scope and scoped resources
236
201
  if (!!definition.spec.scope) {
237
202
  const scopeDef = [...this.resources.values()].find(res => res.spec.kind === definition.spec.scope.kind); // mind the non-null assertion here
238
203
  // modify current definition by adding "toResources" link to scopeDef
239
-
240
204
  if (!definition.spec.references.toResources.find(ref => ref.kind === scopeDef.spec.kind)) {
241
205
  definition.spec.references.toResources.push({
242
206
  kind: scopeDef.spec.kind,
@@ -244,9 +208,8 @@ class DefinitionsManager {
244
208
  // NOTE: not used value, adding just to indicate it's manual nature.
245
209
  types: ['CALCULATED']
246
210
  });
247
- } // modify related "scope" definition by adding "fromResources" link to current definition
248
-
249
-
211
+ }
212
+ // modify related "scope" definition by adding "fromResources" link to current definition
250
213
  if (!scopeDef.spec.references.fromResources.find(ref => ref.kind === definition.spec.kind)) {
251
214
  scopeDef.spec.references.fromResources.push({
252
215
  kind: definition.spec.kind,
@@ -257,19 +220,18 @@ class DefinitionsManager {
257
220
  });
258
221
  }
259
222
  }
260
- }); // execute the sorting, note that the returning map is using the "name" field as keys.
261
-
223
+ });
224
+ // execute the sorting, note that the returning map is using the "name" field as keys.
262
225
  const res = this.sortByReferences([...this.resources.values()]);
263
226
  return new Map(res.map(v => [v.name, v]));
264
227
  }
265
-
266
228
  getDefsTableForHelpMsg() {
267
229
  if (!this.specs) return 'No resources found.';
268
- const t = new _easyTable.default(); // create the 'axway central get' table
230
+ const t = new _easyTable.default();
269
231
 
232
+ // create the 'axway central get' table
270
233
  this.cli.forEach(v => {
271
234
  var _this$resources$get, _this$resources$get2, _this$resources, _this$resources$get3, _this$resources$get3$;
272
-
273
235
  // grab the resource group
274
236
  const group = v.metadata.scope.name;
275
237
  t.cell('RESOURCE', `${v.spec.names.plural}`, () => (0, _chalk.cyan)(v.spec.names.plural));
@@ -282,7 +244,6 @@ class DefinitionsManager {
282
244
  });
283
245
  return t.sort(['RESOURCE']).toString();
284
246
  }
285
-
286
247
  findDefsByKind(kind) {
287
248
  log('findDefsByKind: ', kind);
288
249
  const res = [...this.resources].reduce((a, [_, def]) => {
@@ -293,11 +254,11 @@ class DefinitionsManager {
293
254
  scope: def.spec.scope ? [...this.resources].find(([_, resDef]) => resDef.spec.kind === def.spec.scope.kind)[1] : undefined
294
255
  });
295
256
  }
296
-
297
257
  return a;
298
258
  }, []);
299
259
  return res.length ? res : null;
300
260
  }
261
+
301
262
  /**
302
263
  * Returns set of related definitions if word is known.
303
264
  * @param word word to search for
@@ -307,24 +268,19 @@ class DefinitionsManager {
307
268
  * scope: scope resource definition, can support multiple scopes (only for scoped resources, otherwise it is undefined)
308
269
  * } or null if no definitions found for this word.
309
270
  */
310
-
311
-
312
271
  findDefsByWord(word) {
313
272
  log('findDefsByWord: ', word);
314
273
  if (!this.specs) return null;
315
274
  const cliKv = [...this.cli].filter(([_, v]) => {
316
275
  var _v$spec$names$shortNa;
317
-
318
276
  return v.spec.names.plural === word || v.spec.names.singular === word || v.spec.names.shortNames.includes(word) || ((_v$spec$names$shortNa = v.spec.names.shortNamesAlias) === null || _v$spec$names$shortNa === void 0 ? void 0 : _v$spec$names$shortNa.includes(word));
319
- }); // no match found returning null
320
-
277
+ });
278
+ // no match found returning null
321
279
  if (!cliKv.length) return null;
322
280
  const result = [...this.cli].reduce((a, [_, cliDef]) => {
323
281
  var _cliDef$spec$names$sh;
324
-
325
282
  if (cliDef.spec.names.plural === word || cliDef.spec.names.singular === word || cliDef.spec.names.shortNames.includes(word) || (_cliDef$spec$names$sh = cliDef.spec.names.shortNamesAlias) !== null && _cliDef$spec$names$sh !== void 0 && _cliDef$spec$names$sh.includes(word)) {
326
283
  var _this$findDefsByKind;
327
-
328
284
  // note: mind non-null assertion
329
285
  const resource = this.resources.get(cliDef.spec.resourceDefinition);
330
286
  const scope = resource.spec.scope ? (_this$findDefsByKind = this.findDefsByKind(resource.spec.scope.kind)) === null || _this$findDefsByKind === void 0 ? void 0 : _this$findDefsByKind[0].resource : null;
@@ -334,12 +290,9 @@ class DefinitionsManager {
334
290
  scope: !!scope ? scope : undefined
335
291
  });
336
292
  }
337
-
338
293
  return a;
339
294
  }, []);
340
295
  return result;
341
296
  }
342
-
343
297
  }
344
-
345
298
  exports.DefinitionsManager = DefinitionsManager;
@@ -4,43 +4,29 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.kubectl = exports.exec = void 0;
7
-
8
7
  var _child_process = require("child_process");
9
-
10
8
  var _cliKit = require("cli-kit");
11
-
12
9
  var _util = _interopRequireDefault(require("util"));
13
-
14
10
  var _utils = require("./utils");
15
-
16
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
12
  const quotes = _utils.isWindows ? '"' : "'";
19
13
  const {
20
14
  log
21
15
  } = (0, _cliKit.snooplogg)('central: kubectl');
22
-
23
- const exec = _util.default.promisify(_child_process.exec);
24
-
25
- exports.exec = exec;
26
-
16
+ const exec = exports.exec = _util.default.promisify(_child_process.exec);
27
17
  class Kubectl {
28
18
  async get(resource, args) {
29
19
  return await this.invoke('get', resource, args);
30
20
  }
31
-
32
21
  async create(resource, args) {
33
22
  return await this.invoke('create', resource, args);
34
23
  }
35
-
36
24
  async delete(resource, args) {
37
25
  return await this.invoke('delete', resource, args);
38
26
  }
39
-
40
27
  async isInstalled() {
41
28
  return await this.execKubectl('version', 'version');
42
29
  }
43
-
44
30
  async invoke(action, resource, args) {
45
31
  const obj = {
46
32
  error: null,
@@ -50,28 +36,23 @@ class Kubectl {
50
36
  logMsg = args ? logMsg += ` ${args}` : logMsg;
51
37
  log(logMsg);
52
38
  const res = await this.execKubectl(`${action} ${resource} ${args || ''}`, resource);
53
-
54
39
  if (res.error) {
55
40
  obj.error = res.error;
56
41
  log(`command failed: ${res.error}`);
57
42
  return obj;
58
43
  }
59
-
60
44
  obj.data = this.cleanResponse(res.data);
61
45
  log('command success');
62
46
  return obj;
63
47
  }
64
-
65
48
  async execKubectl(action, resource) {
66
49
  let {
67
50
  stdout,
68
51
  stderr
69
52
  } = await exec(`kubectl ${action} | awk ${quotes}{print $1}${quotes}`);
70
-
71
53
  if (stderr.includes('WARNING')) {
72
54
  stderr = '';
73
55
  }
74
-
75
56
  return stderr ? {
76
57
  data: null,
77
58
  error: `K8S ${resource}: ${stderr}`
@@ -80,12 +61,8 @@ class Kubectl {
80
61
  error: null
81
62
  };
82
63
  }
83
-
84
64
  cleanResponse(res) {
85
65
  return res.split('\n').filter(str => str !== 'NAME' && str != '').sort();
86
66
  }
87
-
88
67
  }
89
-
90
- const kubectl = new Kubectl();
91
- exports.kubectl = kubectl;
68
+ const kubectl = exports.kubectl = new Kubectl();
@@ -4,42 +4,25 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.PlatformTeamMemberRole = exports.PlatformServiceAccountRole = exports.PlatformClient = exports.PlatformAuthMethod = void 0;
7
-
8
7
  var _snooplogg = _interopRequireDefault(require("snooplogg"));
9
-
10
8
  var _amplifyCliUtils = require("@axway/amplify-cli-utils");
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
10
  function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
15
-
16
11
  function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
17
-
18
12
  function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
19
-
20
13
  function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
21
-
22
14
  function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
23
-
24
15
  function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
25
-
26
16
  function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
27
-
28
17
  const {
29
18
  log
30
19
  } = (0, _snooplogg.default)('central:class.PlatformClient');
31
- let PlatformAuthMethod;
32
- exports.PlatformAuthMethod = PlatformAuthMethod;
33
-
34
- (function (PlatformAuthMethod) {
20
+ let PlatformAuthMethod = exports.PlatformAuthMethod = /*#__PURE__*/function (PlatformAuthMethod) {
35
21
  PlatformAuthMethod["Certificate"] = "certificate";
36
22
  PlatformAuthMethod["Secret"] = "secret";
37
- })(PlatformAuthMethod || (exports.PlatformAuthMethod = PlatformAuthMethod = {}));
38
-
39
- let PlatformServiceAccountRole;
40
- exports.PlatformServiceAccountRole = PlatformServiceAccountRole;
41
-
42
- (function (PlatformServiceAccountRole) {
23
+ return PlatformAuthMethod;
24
+ }({});
25
+ let PlatformServiceAccountRole = exports.PlatformServiceAccountRole = /*#__PURE__*/function (PlatformServiceAccountRole) {
43
26
  PlatformServiceAccountRole["ApiCentralAdmin"] = "api_central_admin";
44
27
  PlatformServiceAccountRole["FlowCentralAccessManager"] = "fc_access_manager";
45
28
  PlatformServiceAccountRole["FlowCentralIntegration"] = "fc_integration";
@@ -50,26 +33,21 @@ exports.PlatformServiceAccountRole = PlatformServiceAccountRole;
50
33
  PlatformServiceAccountRole["FlowCentralSubscriptionSpecialist"] = "fc_subscriptionspecialist";
51
34
  PlatformServiceAccountRole["FlowCentralTemplatePublisher"] = "fc_templatepublisher";
52
35
  PlatformServiceAccountRole["FlowCentralCftAdmin"] = "fc_cft_admin";
53
- })(PlatformServiceAccountRole || (exports.PlatformServiceAccountRole = PlatformServiceAccountRole = {}));
54
-
55
- let PlatformTeamMemberRole;
56
- exports.PlatformTeamMemberRole = PlatformTeamMemberRole;
57
-
58
- (function (PlatformTeamMemberRole) {
36
+ return PlatformServiceAccountRole;
37
+ }({});
38
+ let PlatformTeamMemberRole = exports.PlatformTeamMemberRole = /*#__PURE__*/function (PlatformTeamMemberRole) {
59
39
  PlatformTeamMemberRole["Admin"] = "administrator";
60
40
  PlatformTeamMemberRole["Developer"] = "developer";
61
41
  PlatformTeamMemberRole["Consumer"] = "consumer";
62
42
  PlatformTeamMemberRole["CatalogManager"] = "catalog_manager";
63
- })(PlatformTeamMemberRole || (exports.PlatformTeamMemberRole = PlatformTeamMemberRole = {}));
64
-
43
+ return PlatformTeamMemberRole;
44
+ }({});
45
+ /** Options used to create a service account via the PlatformClient.createServiceAccount() method. */
46
+ /** Provides information for a platform service account. */
65
47
  var _baseUrl = /*#__PURE__*/new WeakMap();
66
-
67
48
  var _accountName = /*#__PURE__*/new WeakMap();
68
-
69
49
  var _amplifyConfig = /*#__PURE__*/new WeakMap();
70
-
71
50
  var _amplifySdk = /*#__PURE__*/new WeakMap();
72
-
73
51
  class PlatformClient {
74
52
  constructor({
75
53
  baseUrl,
@@ -80,107 +58,85 @@ class PlatformClient {
80
58
  writable: true,
81
59
  value: void 0
82
60
  });
83
-
84
61
  _classPrivateFieldInitSpec(this, _accountName, {
85
62
  writable: true,
86
63
  value: void 0
87
64
  });
88
-
89
65
  _classPrivateFieldInitSpec(this, _amplifyConfig, {
90
66
  writable: true,
91
67
  value: void 0
92
68
  });
93
-
94
69
  _classPrivateFieldInitSpec(this, _amplifySdk, {
95
70
  writable: true,
96
71
  value: void 0
97
72
  });
98
-
99
73
  log(`initializing client with params: baseUrl = ${baseUrl}, region = ${region}, account = ${account}`);
100
-
101
74
  _classPrivateFieldSet(this, _baseUrl, baseUrl);
102
-
103
75
  _classPrivateFieldSet(this, _accountName, account);
104
-
105
76
  const initResult = (0, _amplifyCliUtils.initSDK)({
106
77
  baseUrl: _classPrivateFieldGet(this, _baseUrl),
107
78
  username: _classPrivateFieldGet(this, _accountName)
108
79
  });
109
-
110
80
  _classPrivateFieldSet(this, _amplifyConfig, initResult.config);
111
-
112
81
  _classPrivateFieldSet(this, _amplifySdk, initResult.sdk);
113
82
  }
114
-
115
83
  async getAccountInfo() {
116
84
  var _classPrivateFieldGet2;
117
-
118
85
  // Get default teams from config.
119
- const defaultTeams = _classPrivateFieldGet(this, _amplifyConfig).get(`${(0, _amplifyCliUtils.getAuthConfigEnvSpecifier)((_classPrivateFieldGet2 = _classPrivateFieldGet(this, _amplifySdk).env) === null || _classPrivateFieldGet2 === void 0 ? void 0 : _classPrivateFieldGet2.name)}.defaultTeam`); // Fetch specified account or default account currently logged in.
120
-
86
+ const defaultTeams = _classPrivateFieldGet(this, _amplifyConfig).get(`${(0, _amplifyCliUtils.getAuthConfigEnvSpecifier)((_classPrivateFieldGet2 = _classPrivateFieldGet(this, _amplifySdk).env) === null || _classPrivateFieldGet2 === void 0 ? void 0 : _classPrivateFieldGet2.name)}.defaultTeam`);
121
87
 
88
+ // Fetch specified account or default account currently logged in.
122
89
  let accountInfo;
123
-
124
90
  if (_classPrivateFieldGet(this, _accountName)) {
125
91
  accountInfo = await _classPrivateFieldGet(this, _amplifySdk).auth.find(_classPrivateFieldGet(this, _accountName), defaultTeams);
126
-
127
92
  if (!accountInfo) {
128
93
  throw new Error(`Account "${_classPrivateFieldGet(this, _accountName)}" not found`);
129
94
  }
130
95
  }
131
-
132
96
  if (!accountInfo) {
133
97
  const accountArray = await _classPrivateFieldGet(this, _amplifySdk).auth.list({
134
98
  defaultTeams,
135
99
  validate: true
136
100
  });
137
-
138
101
  if (accountArray) {
139
102
  accountInfo = accountArray.find(nextAccount => nextAccount.default) || accountArray[0];
140
103
  }
141
- } // Make sure "subscriptions" is defined since Amplify SDK requires it. (Will throw error if missing.)
142
-
104
+ }
143
105
 
106
+ // Make sure "subscriptions" is defined since Amplify SDK requires it. (Will throw error if missing.)
144
107
  if (accountInfo && accountInfo.org && !accountInfo.org.subscriptions) {
145
108
  accountInfo.org.subscriptions = [];
146
- } // Return account info if found.
147
-
109
+ }
148
110
 
111
+ // Return account info if found.
149
112
  return accountInfo;
150
113
  }
151
-
152
114
  async createServiceAccount(options) {
153
115
  const accountInfo = await this.getAccountInfo();
154
116
  const result = await _classPrivateFieldGet(this, _amplifySdk).client.create(accountInfo, accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.org, options);
155
117
  return result.client;
156
118
  }
157
-
158
119
  async getServiceAccounts(filterRole) {
159
120
  const result = await _classPrivateFieldGet(this, _amplifySdk).client.list(await this.getAccountInfo());
160
121
  let clients = result.clients || [];
161
-
162
122
  if (filterRole) {
163
123
  log('filter clients by ', filterRole);
164
124
  clients = clients.filter(client => client === null || client === void 0 ? void 0 : client.roles.find(r => r === filterRole));
165
125
  }
166
-
167
126
  return clients;
168
127
  }
169
-
170
128
  async getTeams() {
171
129
  var _account$team, _teams$find;
172
-
173
130
  log(`getTeams`);
174
131
  const account = await this.getAccountInfo();
175
132
  const {
176
133
  teams
177
134
  } = await _classPrivateFieldGet(this, _amplifySdk).team.list(account);
178
135
  const teamGuid = ((_account$team = account.team) === null || _account$team === void 0 ? void 0 : _account$team.guid) && ((_teams$find = teams.find(team => team.guid === account.team.guid)) === null || _teams$find === void 0 ? void 0 : _teams$find.guid);
179
- return teams.map(team => ({ ...team,
136
+ return teams.map(team => ({
137
+ ...team,
180
138
  default: teamGuid && team.guid === teamGuid || !teamGuid && team.default
181
139
  }));
182
140
  }
183
-
184
141
  }
185
-
186
142
  exports.PlatformClient = PlatformClient;