@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
@@ -1,283 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.testables = exports.askBundleType = exports.GitHubSaaSInstallMethods = void 0;
7
- var _chalk = _interopRequireDefault(require("chalk"));
8
- var _snooplogg = _interopRequireDefault(require("snooplogg"));
9
- var _basicPrompts = require("../../common/basicPrompts");
10
- var _types = require("../../common/types");
11
- var helpers = _interopRequireWildcard(require("./helpers"));
12
- 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; }
15
- 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); }
19
- const {
20
- log
21
- } = (0, _snooplogg.default)('central: install: agents: saas');
22
- class DataplaneConfig {
23
- constructor(type) {
24
- _defineProperty(this, "type", void 0);
25
- this.type = type || "";
26
- }
27
- }
28
- class GitHubDataplaneConfig extends DataplaneConfig {
29
- constructor(name, ownerName, filter) {
30
- super("GitHub");
31
- _defineProperty(this, "name", void 0);
32
- _defineProperty(this, "ownerName", void 0);
33
- _defineProperty(this, "filter", void 0);
34
- this.name = name;
35
- this.ownerName = ownerName;
36
- this.filter = filter;
37
- }
38
- }
39
- class GitHubFilterConfig {
40
- constructor(paths, pattern) {
41
- _defineProperty(this, "paths", void 0);
42
- _defineProperty(this, "pattern", void 0);
43
- this.paths = paths;
44
- this.pattern = pattern;
45
- }
46
- }
47
- class SaasAgentValues {
48
- constructor() {
49
- _defineProperty(this, "frequencyDA", void 0);
50
- _defineProperty(this, "queueDA", void 0);
51
- _defineProperty(this, "frequencyTA", void 0);
52
- _defineProperty(this, "dataplaneConfig", void 0);
53
- _defineProperty(this, "centralConfig", void 0);
54
- _defineProperty(this, "repositoryOwner", void 0);
55
- _defineProperty(this, "repositoryName", void 0);
56
- _defineProperty(this, "filePaths", void 0);
57
- _defineProperty(this, "filePatterns", void 0);
58
- this.frequencyDA = '';
59
- this.queueDA = false;
60
- this.frequencyTA = '';
61
- this.dataplaneConfig = new DataplaneConfig();
62
- this.centralConfig = new _types.CentralAgentConfig();
63
- this.repositoryOwner = '';
64
- this.repositoryName = '';
65
- this.filePaths = [];
66
- this.filePatterns = [];
67
- }
68
- }
69
- class SaasGitHubAgentValues extends SaasAgentValues {
70
- constructor() {
71
- super();
72
- _defineProperty(this, "accessToken", void 0);
73
- this.accessToken = '';
74
- }
75
- getAccessData() {
76
- let data = JSON.stringify({
77
- accessToken: this.accessToken
78
- });
79
- return data;
80
- }
81
- }
82
-
83
- // ConfigFiles - all the config file that are used in the setup
84
- const ConfigFiles = {};
85
-
86
- // APIGEEX SaaSPrompts - all APIGEEX Saas prompts to the user for input
87
- const SaasPrompts = {
88
- ACCESS_TOKEN: 'Enter the GitHub Access Token the agent will use',
89
- REPOSITORY_OWNER: 'Enter the GitHub Repository Owner the agent will use',
90
- REPOSITORY_NAME: 'Enter the Repository Name the agent will use',
91
- FILE_PATHS: 'Enter the File Path within the repository that the agent will use',
92
- FILE_PATTERNS: 'Enter the File Pattern that the agent will use',
93
- DA_FREQUENCY: 'How often should the discovery run, leave blank for integrating in CI/CD process',
94
- QUEUE: 'Do you want to discover immediately after installation',
95
- ENTER_MORE_PATHS: 'Do you want to enter another file path ?',
96
- ENTER_MORE_PATTERNS: 'Do you want to enter another file pattern ?'
97
- };
98
- const askBundleType = async () => {
99
- //GitHub agent has only DA
100
- return _types.BundleType.DISCOVERY;
101
- };
102
- exports.askBundleType = askBundleType;
103
- const askConfigType = async () => {
104
- return _types.AgentConfigTypes.HOSTED;
105
- };
106
- const askForGitHubCredentials = async hostedAgentValues => {
107
- log("gathering access details for GitHub");
108
- hostedAgentValues.accessToken = await (0, _basicPrompts.askInput)({
109
- msg: SaasPrompts.ACCESS_TOKEN,
110
- defaultValue: hostedAgentValues.accessToken !== '' ? hostedAgentValues.accessToken : undefined,
111
- validate: (0, _basicPrompts.validateRegex)(helpers.GitHubRegexPatterns.gitHubAccessTokenRegex, helpers.invalidValueExampleErrMsg('AccessToken', 'ghp_testTokentestTokentestTokentestToken'))
112
- });
113
- return hostedAgentValues;
114
- };
115
- const validateFrequency = () => input => {
116
- let val = (0, _basicPrompts.validateRegex)(helpers.frequencyRegex, helpers.invalidValueExampleErrMsg('frequency', '3d5h12m'))(input);
117
- if (typeof val === "string") {
118
- return val;
119
- }
120
- let r = input.toString().match(/^(\d*)m/);
121
- if (r) {
122
- // only minutes
123
- let mins = r[1];
124
- if (parseInt(mins, 10) < 30) {
125
- return "Minimum frequency is 30m";
126
- }
127
- }
128
- return true;
129
- };
130
-
131
- // @ts-ignore
132
- const gatewayConnectivity = async installConfig => {
133
- console.log('\nCONNECTION TO GitHub API GATEWAY:');
134
- console.log(_chalk.default.gray("The Discovery Agent needs to connect to the GitHub API Gateway to discover API's for publishing to Amplify Central"));
135
-
136
- // DeploymentType
137
- let hostedAgentValues = new SaasAgentValues();
138
- if (installConfig.gatewayType === _types.GatewayTypes.GITHUB) {
139
- // GitHub connection details
140
- hostedAgentValues = new SaasGitHubAgentValues();
141
- hostedAgentValues = await askForGitHubCredentials(hostedAgentValues);
142
- }
143
-
144
- // Ask to queue discovery now
145
- log("getting the frequency and if the agent should run now");
146
- 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."));
147
- hostedAgentValues.frequencyDA = await (0, _basicPrompts.askInput)({
148
- msg: SaasPrompts.DA_FREQUENCY,
149
- validate: validateFrequency(),
150
- allowEmptyInput: true
151
- });
152
- hostedAgentValues.queueDA = (await (0, _basicPrompts.askList)({
153
- msg: SaasPrompts.QUEUE,
154
- default: _types.YesNo.No,
155
- choices: _types.YesNoChoices
156
- })) === _types.YesNo.Yes;
157
-
158
- // get repository owner
159
- hostedAgentValues.repositoryOwner = await (0, _basicPrompts.askInput)({
160
- msg: SaasPrompts.REPOSITORY_OWNER,
161
- defaultValue: hostedAgentValues.repositoryOwner !== '' ? hostedAgentValues.repositoryOwner : undefined,
162
- validate: (0, _basicPrompts.validateRegex)(helpers.GitHubRegexPatterns.gitHubRepositoryOwnerRegex, helpers.invalidValueExampleErrMsg('Repository Owner', 'axway-github-owner'))
163
- });
164
-
165
- // get repository name
166
- hostedAgentValues.repositoryName = await (0, _basicPrompts.askInput)({
167
- msg: SaasPrompts.REPOSITORY_NAME,
168
- defaultValue: hostedAgentValues.repositoryName !== '' ? hostedAgentValues.repositoryName : undefined,
169
- validate: (0, _basicPrompts.validateRegex)(helpers.GitHubRegexPatterns.gitHubRepositoryOwnerRegex, helpers.invalidValueExampleErrMsg('Repository Name', 'axway-github-repo-name'))
170
- });
171
-
172
- // get File Paths
173
-
174
- let askFilePaths = true;
175
- console.log(_chalk.default.gray("An array of paths within the repository that the agent will gather files for looking for specs"));
176
- while (askFilePaths) {
177
- const path = await (0, _basicPrompts.askInput)({
178
- msg: SaasPrompts.FILE_PATHS,
179
- allowEmptyInput: false,
180
- validate: (0, _basicPrompts.validateRegex)(helpers.GitHubRegexPatterns.gitHubFilePathRegex, helpers.invalidValueExampleErrMsg('File Path', '/apis'))
181
- });
182
- hostedAgentValues.filePaths.push(path);
183
- askFilePaths = (await (0, _basicPrompts.askList)({
184
- msg: SaasPrompts.ENTER_MORE_PATHS,
185
- default: _types.YesNo.No,
186
- choices: _types.YesNoChoices
187
- })) === _types.YesNo.Yes;
188
- }
189
-
190
- // get File Patterns
191
-
192
- let askFilePatterns = true;
193
- console.log(_chalk.default.gray("An array of regular expressions that when a file name passes any of the the a spec file will be used to create an api service"));
194
- while (askFilePatterns) {
195
- const pattern = await (0, _basicPrompts.askInput)({
196
- msg: SaasPrompts.FILE_PATTERNS,
197
- allowEmptyInput: true
198
- });
199
- hostedAgentValues.filePatterns.push(pattern);
200
- askFilePatterns = (await (0, _basicPrompts.askList)({
201
- msg: SaasPrompts.ENTER_MORE_PATTERNS,
202
- default: _types.YesNo.No,
203
- choices: _types.YesNoChoices
204
- })) === _types.YesNo.Yes;
205
- }
206
- return hostedAgentValues;
207
- };
208
- const generateOutput = async installConfig => {
209
- return `Install complete of hosted agent for ${installConfig.gatewayType} region`;
210
- };
211
- const createEncryptedAccessData = async (hostedAgentValues, dataplaneRes) => {
212
- var _dataplaneRes$securit, _dataplaneRes$securit2;
213
- // grab key from data plane resource
214
- let key = ((_dataplaneRes$securit = dataplaneRes.security) === null || _dataplaneRes$securit === void 0 ? void 0 : _dataplaneRes$securit.encryptionKey) || "";
215
- let hash = ((_dataplaneRes$securit2 = dataplaneRes.security) === null || _dataplaneRes$securit2 === void 0 ? void 0 : _dataplaneRes$securit2.encryptionHash) || "";
216
- if (key === "" || hash === "") {
217
- throw Error(`cannot encrypt access data as the encryption key info was incomplete`);
218
- }
219
- console.log(hostedAgentValues.getAccessData());
220
- let encData = _crypto.default.publicEncrypt({
221
- key: key,
222
- padding: _crypto.default.constants.RSA_PKCS1_OAEP_PADDING,
223
- oaepHash: hash
224
- }, Buffer.from(hostedAgentValues.getAccessData()));
225
- return encData.toString("base64");
226
- };
227
- const completeInstall = async (installConfig, apiServerClient, defsManager) => {
228
- /**
229
- * Create agent resources
230
- */
231
- console.log("\n");
232
- let gitHubAgentValues = installConfig.gatewayConfig;
233
-
234
- // create the environment, if necessary
235
- installConfig.centralConfig.environment = installConfig.centralConfig.ampcEnvInfo.isNew ? await helpers.createByResourceType(apiServerClient, defsManager, installConfig.centralConfig.ampcEnvInfo.name, 'Environment', 'env', {
236
- axwayManaged: installConfig.centralConfig.axwayManaged,
237
- production: installConfig.centralConfig.production
238
- }) : installConfig.centralConfig.ampcEnvInfo.name;
239
- if (installConfig.gatewayType === _types.GatewayTypes.GITHUB) {
240
- gitHubAgentValues.dataplaneConfig = new GitHubDataplaneConfig(gitHubAgentValues.repositoryName, gitHubAgentValues.repositoryOwner, new GitHubFilterConfig(gitHubAgentValues.filePaths, gitHubAgentValues.filePatterns));
241
- }
242
-
243
- // create the data plane resource
244
- let dataplaneRes = await helpers.createNewDataPlaneResource(apiServerClient, defsManager, installConfig.centralConfig.environment, _types.GatewayTypeToDataPlane[installConfig.gatewayType], gitHubAgentValues.dataplaneConfig);
245
- console.log(dataplaneRes);
246
- // create data plane secret resource
247
- try {
248
- await helpers.createNewDataPlaneSecretResource(apiServerClient, defsManager, installConfig.centralConfig.environment, _types.GatewayTypeToDataPlane[installConfig.gatewayType], dataplaneRes.name, await createEncryptedAccessData(gitHubAgentValues, dataplaneRes));
249
- } catch (error) {
250
- console.log(error);
251
- console.log(_chalk.default.redBright("rolling back installation. Please check the credential data before re-running install"));
252
- if (installConfig.centralConfig.ampcEnvInfo.isNew) {
253
- await helpers.deleteByResourceType(apiServerClient, defsManager, installConfig.centralConfig.ampcEnvInfo.name, 'Environment', 'env');
254
- } else {
255
- await helpers.deleteByResourceType(apiServerClient, defsManager, dataplaneRes.name, "Dataplane", "dp", installConfig.centralConfig.environment);
256
- }
257
- return;
258
- }
259
-
260
- // create discovery agent resource
261
- 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, gitHubAgentValues.frequencyDA, gitHubAgentValues.queueDA);
262
- console.log(await generateOutput(installConfig));
263
- };
264
- const GitHubSaaSInstallMethods = exports.GitHubSaaSInstallMethods = {
265
- GetBundleType: askBundleType,
266
- GetDeploymentType: askConfigType,
267
- AskGatewayQuestions: gatewayConnectivity,
268
- FinalizeGatewayInstall: completeInstall,
269
- ConfigFiles: [],
270
- AgentNameMap: {
271
- [_types.AgentTypes.da]: _types.AgentNames.GITHUB_DA,
272
- [_types.AgentTypes.ta]: _types.AgentNames.GITHUB_DA
273
- },
274
- GatewayDisplay: _types.GatewayTypes.GITHUB
275
- };
276
-
277
- // These are the items that are not exported, but need to be for testing
278
- const testables = exports.testables = {
279
- SaasAgentValues,
280
- SaasGitHubAgentValues,
281
- SaasPrompts,
282
- ConfigFiles
283
- };