@axway/axway-central-cli 2.17.0-rc.5 → 2.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/dist/cli.js +28 -6
  2. package/dist/commands/apply/index.js +24 -9
  3. package/dist/commands/completion/index.js +9 -3
  4. package/dist/commands/config/common/index.js +11 -2
  5. package/dist/commands/config/index.js +7 -2
  6. package/dist/commands/config/list.js +6 -2
  7. package/dist/commands/config/set.js +31 -4
  8. package/dist/commands/config/unset.js +12 -2
  9. package/dist/commands/create/agentResource.js +32 -12
  10. package/dist/commands/create/environment.js +16 -6
  11. package/dist/commands/create/index.js +26 -9
  12. package/dist/commands/create/serviceAccount.js +6 -2
  13. package/dist/commands/delete/index.js +33 -15
  14. package/dist/commands/edit/environment.js +21 -6
  15. package/dist/commands/edit/index.js +8 -4
  16. package/dist/commands/get/index.js +44 -27
  17. package/dist/commands/install/agents.js +73 -44
  18. package/dist/commands/install/apigeexSaasAgents.js +98 -35
  19. package/dist/commands/install/awsAgents.js +139 -89
  20. package/dist/commands/install/awsSaasAgents.js +142 -50
  21. package/dist/commands/install/azureAgents.js +79 -39
  22. package/dist/commands/install/edgeAgents.js +110 -17
  23. package/dist/commands/install/helpers/creators.js +70 -17
  24. package/dist/commands/install/helpers/deleters.js +11 -2
  25. package/dist/commands/install/helpers/getters.js +30 -4
  26. package/dist/commands/install/helpers/index.js +48 -13
  27. package/dist/commands/install/helpers/inputs.js +98 -26
  28. package/dist/commands/install/helpers/regex.js +34 -29
  29. package/dist/commands/install/helpers/templates/awsTemplates.js +23 -6
  30. package/dist/commands/install/helpers/templates/azureTemplates.js +24 -5
  31. package/dist/commands/install/helpers/templates/edgeTemplates.js +38 -7
  32. package/dist/commands/install/helpers/templates/istioTemplates.js +16 -5
  33. package/dist/commands/install/index.js +10 -4
  34. package/dist/commands/install/istioAgents.js +117 -40
  35. package/dist/commands/install/platform.js +52 -20
  36. package/dist/commands/proxies/create.js +18 -2
  37. package/dist/commands/proxies/index.js +8 -4
  38. package/dist/commands/proxies/promote.js +21 -2
  39. package/dist/common/ApiServerClient.js +173 -64
  40. package/dist/common/CacheController.js +32 -11
  41. package/dist/common/CliConfigManager.js +27 -14
  42. package/dist/common/CompositeError.js +30 -6
  43. package/dist/common/CoreConfigController.js +40 -18
  44. package/dist/common/DefinitionsManager.js +76 -29
  45. package/dist/common/Kubectl.js +25 -2
  46. package/dist/common/PlatformClient.js +63 -19
  47. package/dist/common/Renderer.js +87 -25
  48. package/dist/common/TmpFile.js +28 -11
  49. package/dist/common/bashCommands.js +22 -3
  50. package/dist/common/basicPrompts.js +43 -8
  51. package/dist/common/dataService.js +50 -22
  52. package/dist/common/errorHandler.js +9 -0
  53. package/dist/common/resultsRenderers.js +42 -10
  54. package/dist/common/types.js +341 -116
  55. package/dist/common/utils.js +99 -37
  56. package/dist/main.js +2 -0
  57. package/package.json +2 -2
  58. package/dist/commands/install/gitHubSaasAgents.js +0 -283
@@ -4,66 +4,94 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.prompts = exports.localhost = exports.agents = void 0;
7
+
7
8
  var _chalk = _interopRequireDefault(require("chalk"));
9
+
8
10
  var _snooplogg = _interopRequireDefault(require("snooplogg"));
11
+
9
12
  var _ApiServerClient = require("../../common/ApiServerClient");
13
+
10
14
  var _basicPrompts = require("../../common/basicPrompts");
15
+
11
16
  var _CoreConfigController = require("../../common/CoreConfigController");
17
+
12
18
  var _DefinitionsManager = require("../../common/DefinitionsManager");
19
+
13
20
  var _PlatformClient = require("../../common/PlatformClient");
21
+
14
22
  var _CliConfigManager = require("../../common/CliConfigManager");
23
+
15
24
  var _Renderer = _interopRequireDefault(require("../../common/Renderer"));
25
+
16
26
  var _types = require("../../common/types");
27
+
17
28
  var _utils = require("../../common/utils");
29
+
18
30
  var awsAgents = _interopRequireWildcard(require("./awsAgents"));
19
- var gitHubAgents = _interopRequireWildcard(require("./gitHubSaasAgents"));
31
+
20
32
  var azureAgents = _interopRequireWildcard(require("./azureAgents"));
33
+
21
34
  var edgeAgents = _interopRequireWildcard(require("./edgeAgents"));
35
+
22
36
  var apigeeSaaSAgents = _interopRequireWildcard(require("./apigeexSaasAgents"));
37
+
23
38
  var helpers = _interopRequireWildcard(require("./helpers"));
39
+
24
40
  var istioAgents = _interopRequireWildcard(require("./istioAgents"));
41
+
25
42
  var saasAgents = _interopRequireWildcard(require("./awsSaasAgents"));
43
+
26
44
  var platform = _interopRequireWildcard(require("./platform"));
27
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
28
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
45
+
46
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
47
+
48
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
49
+
29
50
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
51
+
30
52
  const {
31
53
  log
32
54
  } = (0, _snooplogg.default)('central: install: agents');
33
- const localhost = exports.localhost = 'localhost';
34
- const prompts = exports.prompts = {
55
+ const localhost = 'localhost';
56
+ exports.localhost = localhost;
57
+ const prompts = {
35
58
  hostedAgentOption: 'Will this be an embedded agent',
36
59
  selectGatewayType: 'Select the type of gateway you want to connect'
37
60
  };
61
+ exports.prompts = prompts;
38
62
  const agentInstallFlows = {
39
63
  [_types.GatewayTypes.EDGE_GATEWAY]: edgeAgents.EdgeInstallMethods,
40
64
  [_types.GatewayTypes.EDGE_GATEWAY_ONLY]: edgeAgents.EdgeGWOnlyInstallMethods,
41
65
  [_types.GatewayTypes.AWS_GATEWAY]: awsAgents.AWSInstallMethods,
42
66
  [_types.GatewayTypes.APIGEEX_GATEWAY]: apigeeSaaSAgents.APIGEEXSaaSInstallMethods,
43
- [_types.GatewayTypes.GITHUB]: gitHubAgents.GitHubSaaSInstallMethods,
44
67
  [_types.GatewayTypes.AZURE_GATEWAY]: azureAgents.AzureInstallMethods,
45
68
  [_types.GatewayTypes.ISTIO]: istioAgents.IstioInstallMethods
46
69
  };
47
70
  const saasAgentInstallFlows = {
48
71
  [_types.GatewayTypes.AWS_GATEWAY]: saasAgents.AWSSaaSInstallMethods,
49
- [_types.GatewayTypes.APIGEEX_GATEWAY]: apigeeSaaSAgents.APIGEEXSaaSInstallMethods,
50
- [_types.GatewayTypes.GITHUB]: gitHubAgents.GitHubSaaSInstallMethods
72
+ [_types.GatewayTypes.APIGEEX_GATEWAY]: apigeeSaaSAgents.APIGEEXSaaSInstallMethods
51
73
  };
74
+
52
75
  const createConfigBackup = async (configFiles, gatewayType) => {
53
76
  // If current configurations exist, back them up
54
77
  const configsExist = await helpers.createBackUpConfigs(configFiles);
78
+
55
79
  if (configsExist) {
56
80
  console.log(`\nCreated configuration backups for ${gatewayType}`);
57
81
  }
58
82
  };
83
+
59
84
  const determineRegion = async region => {
60
85
  let configurationRegion = (await (0, _utils.getConfig)())[_CliConfigManager.CliConfigKeys.REGION];
86
+
61
87
  if (region) {
62
88
  return region.toString();
63
89
  }
90
+
64
91
  return configurationRegion ? configurationRegion : _types.Regions.US;
65
92
  };
66
- const agents = exports.agents = {
93
+
94
+ const agents = {
67
95
  action: async function ({
68
96
  argv,
69
97
  console
@@ -78,8 +106,10 @@ const agents = exports.agents = {
78
106
  } = argv;
79
107
  let isCmdError = false;
80
108
  const render = new _Renderer.default(console);
109
+
81
110
  try {
82
111
  var _accountInfo$roles, _accountInfo$roles2;
112
+
83
113
  // initialize clients
84
114
  const apiServerClient = new _ApiServerClient.ApiServerClient({
85
115
  baseUrl,
@@ -92,26 +122,24 @@ const agents = exports.agents = {
92
122
  account,
93
123
  region
94
124
  });
95
- const defsManager = await new _DefinitionsManager.DefinitionsManager(apiServerClient).init();
125
+ const defsManager = await new _DefinitionsManager.DefinitionsManager(apiServerClient).init(); // Verify account has permission to create an environment and service account.
96
126
 
97
- // Verify account has permission to create an environment and service account.
98
127
  const accountInfo = await platformClient.getAccountInfo();
99
128
  const isCentralAdmin = accountInfo === null || accountInfo === void 0 ? void 0 : (_accountInfo$roles = accountInfo.roles) === null || _accountInfo$roles === void 0 ? void 0 : _accountInfo$roles.includes(_CoreConfigController.AccountRole.ApiCentralAdmin);
100
129
  const isPlatformAdmin = accountInfo === null || accountInfo === void 0 ? void 0 : (_accountInfo$roles2 = accountInfo.roles) === null || _accountInfo$roles2 === void 0 ? void 0 : _accountInfo$roles2.includes(_CoreConfigController.AccountRole.PlatformAdmin);
101
- checkUserRole(isCentralAdmin, isPlatformAdmin, accountInfo, render);
130
+ checkUserRole(isCentralAdmin, isPlatformAdmin, accountInfo, render); // helper text
102
131
 
103
- // helper text
104
132
  console.log(_chalk.default.gray(`This command configures and installs the agents so that you can manage your gateway environment within the Amplify Platform.\n`));
105
133
  let installConfig = new _types.AgentInstallConfig();
106
- installConfig.centralConfig.axwayManaged = !!axwayManaged;
134
+ installConfig.centralConfig.axwayManaged = !!axwayManaged; // top priority is region option on command line, second priority is region from config file, default is US
107
135
 
108
- // top priority is region option on command line, second priority is region from config file, default is US
109
136
  installConfig.centralConfig.region = await determineRegion(region);
110
137
  installConfig.centralConfig.singleEntryPointUrl = _types.SingleEntryPointUrls[installConfig.centralConfig.region];
111
138
  let gatewayType = await (0, _basicPrompts.askList)({
112
139
  msg: prompts.selectGatewayType,
113
140
  choices: Object.values(_types.GatewayTypes).filter(v => v !== _types.GatewayTypes.EDGE_GATEWAY_ONLY)
114
141
  });
142
+
115
143
  if (gatewayType === _types.GatewayTypes.AWS_GATEWAY) {
116
144
  // hosted vs on premise
117
145
  installConfig.switches.isHostedInstall = (await (0, _basicPrompts.askList)({
@@ -120,59 +148,55 @@ const agents = exports.agents = {
120
148
  default: _types.YesNo.Yes
121
149
  })) === _types.YesNo.Yes;
122
150
  }
123
- if (gatewayType === _types.GatewayTypes.GITHUB || gatewayType === _types.GatewayTypes.APIGEEX_GATEWAY) {
151
+
152
+ if (gatewayType === _types.GatewayTypes.APIGEEX_GATEWAY) {
124
153
  installConfig.switches.isHostedInstall = true;
125
- }
154
+ } // if gateway type is edge ask Gateway only or not
155
+
126
156
 
127
- // if gateway type is edge ask Gateway only or not
128
157
  if (gatewayType === _types.GatewayTypes.EDGE_GATEWAY) {
129
158
  installConfig.switches.isGatewayOnly = false;
130
159
  gatewayType = await edgeAgents.askIsGatewayOnlyMode();
131
160
  }
161
+
132
162
  installConfig.switches.isGatewayOnly = gatewayType === _types.GatewayTypes.EDGE_GATEWAY_ONLY;
133
163
  installConfig.gatewayType = gatewayType;
134
164
  let agentInstallFlow = agentInstallFlows[installConfig.gatewayType];
165
+
135
166
  if (installConfig.switches.isHostedInstall) {
136
167
  agentInstallFlow = saasAgentInstallFlows[installConfig.gatewayType];
137
- }
168
+ } // Create the object of GatewayTypes -> BundleType functions
169
+
138
170
 
139
- // Create the object of GatewayTypes -> BundleType functions
140
171
  installConfig.bundleType = await agentInstallFlow.GetBundleType();
141
172
  installConfig.switches.isDaEnabled = installConfig.bundleType === _types.BundleType.ALL_AGENTS || installConfig.bundleType === _types.BundleType.DISCOVERY;
142
- installConfig.switches.isTaEnabled = installConfig.bundleType === _types.BundleType.ALL_AGENTS || installConfig.bundleType === _types.BundleType.TRACEABILITY || installConfig.bundleType === _types.BundleType.TRACEABILITY_OFFLINE;
173
+ installConfig.switches.isTaEnabled = installConfig.bundleType === _types.BundleType.ALL_AGENTS || installConfig.bundleType === _types.BundleType.TRACEABILITY || installConfig.bundleType === _types.BundleType.TRACEABILITY_OFFLINE; // Create the object of GatewayTypes -> BundleType functions
143
174
 
144
- // Create the object of GatewayTypes -> BundleType functions
145
175
  installConfig.deploymentType = await agentInstallFlow.GetDeploymentType();
146
176
  installConfig.switches.isHelmInstall = installConfig.deploymentType === _types.AgentConfigTypes.HELM;
147
177
  installConfig.switches.isDockerInstall = installConfig.deploymentType === _types.AgentConfigTypes.DOCKERIZED;
148
- installConfig.switches.isBinaryInstall = installConfig.deploymentType === _types.AgentConfigTypes.BINARIES;
178
+ installConfig.switches.isBinaryInstall = installConfig.deploymentType === _types.AgentConfigTypes.BINARIES; // Get the version of the agents from jfrog, not needed in hosted install
149
179
 
150
- // Get the version of the agents from jfrog, not needed in hosted install
151
- await getAgentVersions(agentInstallFlow, installConfig);
180
+ await getAgentVersions(agentInstallFlow, installConfig); // if EDGE_GATEWAY or EDGE_GATEWAY_ONLY and isDaEnabled, ask if the organization structure should replicate
152
181
 
153
- // if EDGE_GATEWAY or EDGE_GATEWAY_ONLY and isDaEnabled, ask if the organization structure should replicate
154
182
  if ((gatewayType === _types.GatewayTypes.EDGE_GATEWAY || gatewayType === _types.GatewayTypes.EDGE_GATEWAY_ONLY) && installConfig.switches.isDaEnabled) {
155
183
  installConfig.switches.isOrgRep = await edgeAgents.askOrganizationReplication();
156
- }
184
+ } // get platform connectivity
185
+
157
186
 
158
- // get platform connectivity
159
- installConfig.centralConfig = await platform.getCentralConfig(apiServerClient, platformClient, defsManager, apicDeployment, installConfig);
187
+ installConfig.centralConfig = await platform.getCentralConfig(apiServerClient, platformClient, defsManager, apicDeployment, installConfig); // Create the object of GatewayTypes -> GatewayConnectivity functions
160
188
 
161
- // Create the object of GatewayTypes -> GatewayConnectivity functions
162
- installConfig.gatewayConfig = await agentInstallFlow.AskGatewayQuestions(installConfig, apiServerClient, defsManager);
189
+ installConfig.gatewayConfig = await agentInstallFlow.AskGatewayQuestions(installConfig, apiServerClient, defsManager); // traceability options
163
190
 
164
- // traceability options
165
191
  if (installConfig.switches.isTaEnabled && !installConfig.switches.isHostedInstall) {
166
192
  installConfig.traceabilityConfig = await platform.getTraceabilityConfig(installConfig);
167
- }
193
+ } // create backup
194
+
168
195
 
169
- // create backup
170
- await createConfigBackup(agentInstallFlow.ConfigFiles, agentInstallFlow.GatewayDisplay);
196
+ await createConfigBackup(agentInstallFlow.ConfigFiles, agentInstallFlow.GatewayDisplay); // run any install preprocess steps
171
197
 
172
- // run any install preprocess steps
173
- installConfig = await finishInstall(agentInstallFlow, installConfig, apiServerClient, platformClient, defsManager);
198
+ installConfig = await finishInstall(agentInstallFlow, installConfig, apiServerClient, platformClient, defsManager); // finalize gateway setup and output
174
199
 
175
- // finalize gateway setup and output
176
200
  await agentInstallFlow.FinalizeGatewayInstall(installConfig, apiServerClient, defsManager);
177
201
  } catch (e) {
178
202
  log('command error', e);
@@ -180,33 +204,37 @@ const agents = exports.agents = {
180
204
  render.anyError(e);
181
205
  } finally {
182
206
  log('command complete');
183
- if (isCmdError) process.exit(1);
184
- // not sure why explicit exit is needed, seems like download is causing it to hang for 10-20 sec
207
+ if (isCmdError) process.exit(1); // not sure why explicit exit is needed, seems like download is causing it to hang for 10-20 sec
208
+
185
209
  process.exit(0);
186
210
  }
187
211
  },
188
212
  desc: 'Amplify API Gateway / Amazon API Gateway / Azure API Gateway / Istio',
189
- options: {
190
- ..._types.commonCmdArgsDescription
213
+ options: { ..._types.commonCmdArgsDescription
191
214
  }
192
215
  };
216
+ exports.agents = agents;
217
+
193
218
  async function getAgentVersions(agentInstallFlow, installConfig) {
194
219
  if (agentInstallFlow.AgentNameMap && !installConfig.switches.isHostedInstall && installConfig.switches.isDaEnabled) {
195
220
  installConfig.daVersion = await helpers.getLatestAgentVersion(agentInstallFlow.AgentNameMap[_types.AgentTypes.da]);
196
221
  }
222
+
197
223
  if (agentInstallFlow.AgentNameMap && !installConfig.switches.isHostedInstall && installConfig.switches.isTaEnabled) {
198
224
  installConfig.taVersion = await helpers.getLatestAgentVersion(agentInstallFlow.AgentNameMap[_types.AgentTypes.ta]);
199
225
  }
200
226
  }
227
+
201
228
  async function finishInstall(agentInstallFlow, installConfig, apiServerClient, platformClient, defsManager) {
202
- if (agentInstallFlow.InstallPreprocess) installConfig = await agentInstallFlow.InstallPreprocess(installConfig);
229
+ if (agentInstallFlow.InstallPreprocess) installConfig = await agentInstallFlow.InstallPreprocess(installConfig); // finalize Platform setup, only for non-hosted agents
203
230
 
204
- // finalize Platform setup, only for non-hosted agents
205
231
  if (!installConfig.switches.isHostedInstall) {
206
232
  installConfig = await platform.finalizeCentralInstall(apiServerClient, platformClient, defsManager, installConfig);
207
233
  }
234
+
208
235
  return installConfig;
209
236
  }
237
+
210
238
  function checkUserRole(isCentralAdmin, isPlatformAdmin, accountInfo, render) {
211
239
  if (!isCentralAdmin || !isPlatformAdmin) {
212
240
  if (!accountInfo || accountInfo.isPlatform) {
@@ -215,6 +243,7 @@ function checkUserRole(isCentralAdmin, isPlatformAdmin, accountInfo, render) {
215
243
  render.error('Error: Not authorized. "Service Account" must be authorized with a user account with "Tooling Credentials" assigned the roles: Platform Admin, Central Admin');
216
244
  render.error('See: https://docs.axway.com/bundle/axwaycli-open-docs/page/docs/authentication/index.html#service-account-with-username-password');
217
245
  }
246
+
218
247
  process.exit(1);
219
248
  }
220
249
  }
@@ -4,61 +4,94 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.testables = exports.askBundleType = exports.APIGEEXSaaSInstallMethods = void 0;
7
+
7
8
  var _chalk = _interopRequireDefault(require("chalk"));
9
+
8
10
  var _snooplogg = _interopRequireDefault(require("snooplogg"));
11
+
9
12
  var _basicPrompts = require("../../common/basicPrompts");
13
+
10
14
  var _types = require("../../common/types");
15
+
11
16
  var helpers = _interopRequireWildcard(require("./helpers"));
17
+
12
18
  var _crypto = _interopRequireDefault(require("crypto"));
13
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
14
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
19
+
20
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
+
22
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
+
15
24
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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); }
25
+
26
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
27
+
19
28
  const {
20
29
  log
21
30
  } = (0, _snooplogg.default)('central: install: agents: saas');
31
+
22
32
  class DataplaneConfig {
23
33
  constructor(type) {
24
34
  _defineProperty(this, "type", void 0);
35
+
25
36
  this.type = type || "";
26
37
  }
38
+
27
39
  }
40
+
28
41
  class APIGEEXDataplaneConfig extends DataplaneConfig {
29
42
  constructor(projectID, developerEmail, mode) {
30
43
  super("Apigee");
44
+
31
45
  _defineProperty(this, "projectId", void 0);
46
+
32
47
  _defineProperty(this, "developerEmail", void 0);
48
+
33
49
  _defineProperty(this, "mode", void 0);
50
+
34
51
  this.projectId = projectID;
35
52
  this.developerEmail = developerEmail;
36
53
  this.mode = mode;
37
54
  }
55
+
38
56
  }
57
+
39
58
  class SaasAgentValues {
40
59
  constructor() {
41
60
  _defineProperty(this, "frequencyDA", void 0);
61
+
42
62
  _defineProperty(this, "queueDA", void 0);
63
+
43
64
  _defineProperty(this, "frequencyTA", void 0);
65
+
44
66
  _defineProperty(this, "dataplaneConfig", void 0);
67
+
45
68
  _defineProperty(this, "centralConfig", void 0);
69
+
46
70
  this.frequencyDA = '';
47
71
  this.queueDA = false;
48
72
  this.frequencyTA = '';
49
73
  this.dataplaneConfig = new DataplaneConfig();
50
74
  this.centralConfig = new _types.CentralAgentConfig();
51
75
  }
76
+
52
77
  }
78
+
53
79
  class SaasAPIGEEXAgentValues extends SaasAgentValues {
54
80
  constructor() {
55
81
  super();
82
+
56
83
  _defineProperty(this, "authType", void 0);
84
+
57
85
  _defineProperty(this, "clientEmailAddress", void 0);
86
+
58
87
  _defineProperty(this, "credentialJSON", void 0);
88
+
59
89
  _defineProperty(this, "projectId", void 0);
90
+
60
91
  _defineProperty(this, "developerEmailAddress", void 0);
92
+
61
93
  _defineProperty(this, "mode", void 0);
94
+
62
95
  this.authType = APIGEEXAuthType.IMP_SVC_ACC;
63
96
  this.clientEmailAddress = '';
64
97
  this.credentialJSON = '';
@@ -66,26 +99,31 @@ class SaasAPIGEEXAgentValues extends SaasAgentValues {
66
99
  this.developerEmailAddress = '';
67
100
  this.mode = _types.APIGEEXDISCOVERYMODES.PROXY;
68
101
  }
102
+
69
103
  getAccessData() {
70
104
  let data = JSON.stringify({
71
105
  client_email: this.clientEmailAddress
72
106
  });
107
+
73
108
  if (this.authType == APIGEEXAuthType.ACCESS_CREDENTIAL) {
74
109
  data = JSON.stringify(this.credentialJSON);
75
110
  }
111
+
76
112
  return data;
77
113
  }
78
- }
79
114
 
80
- // ConfigFiles - all the config file that are used in the setup
81
- const ConfigFiles = {};
115
+ } // ConfigFiles - all the config file that are used in the setup
116
+
117
+
118
+ const ConfigFiles = {}; // APIGEEXAuthType - how the agent will authenticate to APIGEEX
119
+
120
+ var APIGEEXAuthType; // APIGEEX SaaSPrompts - all APIGEEX Saas prompts to the user for input
82
121
 
83
- // APIGEEXAuthType - how the agent will authenticate to APIGEEX
84
- var APIGEEXAuthType = /*#__PURE__*/function (APIGEEXAuthType) {
122
+ (function (APIGEEXAuthType) {
85
123
  APIGEEXAuthType["IMP_SVC_ACC"] = "Impersonate Service Account";
86
124
  APIGEEXAuthType["ACCESS_CREDENTIAL"] = "Access Credential";
87
- return APIGEEXAuthType;
88
- }(APIGEEXAuthType || {}); // APIGEEX SaaSPrompts - all APIGEEX Saas prompts to the user for input
125
+ })(APIGEEXAuthType || (APIGEEXAuthType = {}));
126
+
89
127
  const SaasPrompts = {
90
128
  AUTHENTICATION_TYPE: 'Authenticate with an Impersonation of a Service Account or by providing a Credential File',
91
129
  PROJECT_ID: 'Enter the APIGEE X Project ID the agent will use',
@@ -97,25 +135,28 @@ const SaasPrompts = {
97
135
  QUEUE: 'Do you want to discover immediately after installation',
98
136
  ENTER_MORE: 'Do you want to enter another {0} for {1}'
99
137
  };
138
+
100
139
  const askBundleType = async () => {
101
140
  return await (0, _basicPrompts.askList)({
102
141
  msg: helpers.agentMessages.selectAgentType,
103
142
  choices: [_types.BundleType.ALL_AGENTS, _types.BundleType.DISCOVERY]
104
143
  });
105
144
  };
145
+
106
146
  exports.askBundleType = askBundleType;
147
+
107
148
  const askConfigType = async () => {
108
149
  return _types.AgentConfigTypes.HOSTED;
109
150
  };
151
+
110
152
  const askForAPIGEEXCredentials = async hostedAgentValues => {
111
153
  log("gathering access details for apigee x");
112
154
  hostedAgentValues.projectId = await (0, _basicPrompts.askInput)({
113
155
  msg: SaasPrompts.PROJECT_ID,
114
156
  defaultValue: hostedAgentValues.projectId !== '' ? hostedAgentValues.projectId : undefined,
115
157
  validate: (0, _basicPrompts.validateRegex)(helpers.APIGEEXRegexPatterns.APIGEEX_REGEXP_PROJECT_ID, helpers.invalidValueExampleErrMsg('Project ID', 'rd-amplify-apigee-x'))
116
- });
158
+ }); // get developer email address
117
159
 
118
- // get developer email address
119
160
  hostedAgentValues.developerEmailAddress = await (0, _basicPrompts.askInput)({
120
161
  msg: SaasPrompts.DEVELOPER_EMAIL_ADDRESS,
121
162
  defaultValue: hostedAgentValues.developerEmailAddress !== '' ? hostedAgentValues.developerEmailAddress : undefined,
@@ -123,47 +164,55 @@ const askForAPIGEEXCredentials = async hostedAgentValues => {
123
164
  });
124
165
  hostedAgentValues.authType = APIGEEXAuthType.IMP_SVC_ACC;
125
166
  console.log(_chalk.default.gray("Please refer to docs.axway.com for information on creating the necessary APIGEE X IAM policies"));
167
+
126
168
  if (hostedAgentValues.authType === APIGEEXAuthType.IMP_SVC_ACC) {
127
- log("using impersonate service account authentication");
128
- // get client email address
169
+ log("using impersonate service account authentication"); // get client email address
170
+
129
171
  hostedAgentValues.clientEmailAddress = await (0, _basicPrompts.askInput)({
130
172
  msg: SaasPrompts.CLIENT_EMAIL_ADDRESS,
131
173
  defaultValue: hostedAgentValues.clientEmailAddress !== '' ? hostedAgentValues.clientEmailAddress : undefined,
132
174
  allowEmptyInput: true
133
175
  });
134
176
  }
177
+
135
178
  return hostedAgentValues;
136
179
  };
180
+
137
181
  const validateFrequency = () => input => {
138
182
  let val = (0, _basicPrompts.validateRegex)(helpers.frequencyRegex, helpers.invalidValueExampleErrMsg('frequency', '3d5h12m'))(input);
183
+
139
184
  if (typeof val === "string") {
140
185
  return val;
141
186
  }
187
+
142
188
  let r = input.toString().match(/^(\d*)m/);
189
+
143
190
  if (r) {
144
191
  // only minutes
145
192
  let mins = r[1];
193
+
146
194
  if (parseInt(mins, 10) < 30) {
147
195
  return "Minimum frequency is 30m";
148
196
  }
149
197
  }
198
+
150
199
  return true;
151
- };
200
+ }; // @ts-ignore
201
+
152
202
 
153
- // @ts-ignore
154
203
  const gatewayConnectivity = async installConfig => {
155
204
  console.log('\nCONNECTION TO APIGEE X API GATEWAY:');
156
- console.log(_chalk.default.gray("The Discovery Agent needs to connect to the APIGEE X API Gateway to discover API's for publishing to Amplify Central"));
205
+ console.log(_chalk.default.gray("The Discovery Agent needs to connect to the APIGEE X API Gateway to discover API's for publishing to Amplify Central")); // DeploymentType
157
206
 
158
- // DeploymentType
159
207
  let hostedAgentValues = new SaasAgentValues();
208
+
160
209
  if (installConfig.gatewayType === _types.GatewayTypes.APIGEEX_GATEWAY) {
161
210
  // APIGEE X connection details
162
211
  hostedAgentValues = new SaasAPIGEEXAgentValues();
163
212
  hostedAgentValues = await askForAPIGEEXCredentials(hostedAgentValues);
164
- }
213
+ } // Ask to queue discovery now
214
+
165
215
 
166
- // Ask to queue discovery now
167
216
  log("getting the frequency and if the agent should run now");
168
217
  console.log(_chalk.default.gray("\n00d00h00m format, where 30m = 30 minutes, 1h = 1 hour, 7d = 7 days, and 7d1h30m = 7 days 1 hour and 30 minutes. Minimum of 30m."));
169
218
  hostedAgentValues.frequencyDA = await (0, _basicPrompts.askInput)({
@@ -176,6 +225,7 @@ const gatewayConnectivity = async installConfig => {
176
225
  default: _types.YesNo.No,
177
226
  choices: _types.YesNoChoices
178
227
  })) === _types.YesNo.Yes;
228
+
179
229
  if (installConfig.switches.isTaEnabled) {
180
230
  console.log(_chalk.default.gray("\n00d00h00m format, where 30m = 30 minutes, 1h = 1 hour, 7d = 7 days, and 7d1h30m = 7 days 1 hour and 30 minutes. Minimum of 30m."));
181
231
  hostedAgentValues.frequencyTA = await (0, _basicPrompts.askInput)({
@@ -185,59 +235,70 @@ const gatewayConnectivity = async installConfig => {
185
235
  allowEmptyInput: true
186
236
  });
187
237
  }
238
+
188
239
  return hostedAgentValues;
189
240
  };
241
+
190
242
  const generateOutput = async installConfig => {
191
243
  return `Install complete of hosted agent for ${installConfig.gatewayType} region`;
192
244
  };
245
+
193
246
  const createEncryptedAccessData = async (hostedAgentValues, dataplaneRes) => {
194
247
  var _dataplaneRes$securit, _dataplaneRes$securit2;
248
+
195
249
  // grab key from data plane resource
196
250
  let key = ((_dataplaneRes$securit = dataplaneRes.security) === null || _dataplaneRes$securit === void 0 ? void 0 : _dataplaneRes$securit.encryptionKey) || "";
197
251
  let hash = ((_dataplaneRes$securit2 = dataplaneRes.security) === null || _dataplaneRes$securit2 === void 0 ? void 0 : _dataplaneRes$securit2.encryptionHash) || "";
252
+
198
253
  if (key === "" || hash === "") {
199
254
  throw Error(`cannot encrypt access data as the encryption key info was incomplete`);
200
255
  }
256
+
201
257
  let encData = _crypto.default.publicEncrypt({
202
258
  key: key,
203
259
  padding: _crypto.default.constants.RSA_PKCS1_OAEP_PADDING,
204
260
  oaepHash: hash
205
261
  }, Buffer.from(hostedAgentValues.getAccessData()));
262
+
206
263
  return encData.toString("base64");
207
264
  };
265
+
208
266
  const completeInstall = async (installConfig, apiServerClient, defsManager) => {
209
267
  /**
210
268
  * Create agent resources
211
269
  */
212
270
  console.log("\n");
213
- let apigeeXAgentValues = installConfig.gatewayConfig;
271
+ let apigeeXAgentValues = installConfig.gatewayConfig; // create the environment, if necessary
214
272
 
215
- // create the environment, if necessary
216
273
  installConfig.centralConfig.environment = installConfig.centralConfig.ampcEnvInfo.isNew ? await helpers.createByResourceType(apiServerClient, defsManager, installConfig.centralConfig.ampcEnvInfo.name, 'Environment', 'env', {
217
274
  axwayManaged: installConfig.centralConfig.axwayManaged,
218
275
  production: installConfig.centralConfig.production
219
276
  }) : installConfig.centralConfig.ampcEnvInfo.name;
277
+
220
278
  if (installConfig.gatewayType === _types.GatewayTypes.APIGEEX_GATEWAY) {
221
279
  apigeeXAgentValues.dataplaneConfig = new APIGEEXDataplaneConfig(apigeeXAgentValues.projectId, apigeeXAgentValues.developerEmailAddress, apigeeXAgentValues.mode);
222
- }
280
+ } // create the data plane resource
281
+
282
+
283
+ let dataplaneRes = await helpers.createNewDataPlaneResource(apiServerClient, defsManager, installConfig.centralConfig.environment, _types.GatewayTypeToDataPlane[installConfig.gatewayType], apigeeXAgentValues.dataplaneConfig); // create data plane secret resource
223
284
 
224
- // create the data plane resource
225
- let dataplaneRes = await helpers.createNewDataPlaneResource(apiServerClient, defsManager, installConfig.centralConfig.environment, _types.GatewayTypeToDataPlane[installConfig.gatewayType], apigeeXAgentValues.dataplaneConfig);
226
- // create data plane secret resource
227
285
  try {
228
286
  await helpers.createNewDataPlaneSecretResource(apiServerClient, defsManager, installConfig.centralConfig.environment, _types.GatewayTypeToDataPlane[installConfig.gatewayType], dataplaneRes.name, await createEncryptedAccessData(apigeeXAgentValues, dataplaneRes));
229
287
  } catch (error) {
230
288
  console.log(_chalk.default.redBright("rolling back installation. Please check the credential data before re-running install"));
289
+
231
290
  if (installConfig.centralConfig.ampcEnvInfo.isNew) {
232
291
  await helpers.deleteByResourceType(apiServerClient, defsManager, installConfig.centralConfig.ampcEnvInfo.name, 'Environment', 'env');
233
292
  } else {
234
293
  await helpers.deleteByResourceType(apiServerClient, defsManager, dataplaneRes.name, "Dataplane", "dp", installConfig.centralConfig.environment);
235
294
  }
295
+
236
296
  return;
237
- }
297
+ } // create discovery agent resource
298
+
238
299
 
239
- // create discovery agent resource
240
300
  installConfig.centralConfig.daAgentName = await helpers.createNewAgentResource(apiServerClient, defsManager, installConfig.centralConfig.environment, _types.GatewayTypeToDataPlane[installConfig.gatewayType], _types.AgentResourceKind.da, _types.AgentTypes.da, installConfig.centralConfig.ampcTeamName, _types.GatewayTypeToDataPlane[installConfig.gatewayType] + " Discovery Agent", dataplaneRes.name, apigeeXAgentValues.frequencyDA, apigeeXAgentValues.queueDA);
301
+
241
302
  if (installConfig.switches.isTaEnabled) {
242
303
  // create traceability agent resource
243
304
  installConfig.centralConfig.taAgentName = await helpers.createNewAgentResource(apiServerClient, defsManager, installConfig.centralConfig.environment, _types.GatewayTypeToDataPlane[installConfig.gatewayType], _types.AgentResourceKind.ta, _types.AgentTypes.ta, installConfig.centralConfig.ampcTeamName, _types.GatewayTypeToDataPlane[installConfig.gatewayType] + " Traceability Agent", dataplaneRes.name, apigeeXAgentValues.frequencyTA, false // APIGEE X TA is never triggered at install, as DA has to run prior
@@ -246,7 +307,8 @@ const completeInstall = async (installConfig, apiServerClient, defsManager) => {
246
307
 
247
308
  console.log(await generateOutput(installConfig));
248
309
  };
249
- const APIGEEXSaaSInstallMethods = exports.APIGEEXSaaSInstallMethods = {
310
+
311
+ const APIGEEXSaaSInstallMethods = {
250
312
  GetBundleType: askBundleType,
251
313
  GetDeploymentType: askConfigType,
252
314
  AskGatewayQuestions: gatewayConnectivity,
@@ -257,13 +319,14 @@ const APIGEEXSaaSInstallMethods = exports.APIGEEXSaaSInstallMethods = {
257
319
  [_types.AgentTypes.ta]: _types.AgentNames.APIGEEX_TA
258
320
  },
259
321
  GatewayDisplay: _types.GatewayTypes.APIGEEX_GATEWAY
260
- };
322
+ }; // These are the items that are not exported, but need to be for testing
261
323
 
262
- // These are the items that are not exported, but need to be for testing
263
- const testables = exports.testables = {
324
+ exports.APIGEEXSaaSInstallMethods = APIGEEXSaaSInstallMethods;
325
+ const testables = {
264
326
  SaasAgentValues,
265
327
  SaasAPIGEEXAgentValues,
266
328
  APIGEEXAuthType,
267
329
  SaasPrompts,
268
330
  ConfigFiles
269
- };
331
+ };
332
+ exports.testables = testables;