@axway/axway-central-cli 2.17.0 → 2.18.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 +41 -70
  18. package/dist/commands/install/apigeexSaasAgents.js +33 -96
  19. package/dist/commands/install/awsAgents.js +87 -137
  20. package/dist/commands/install/awsSaasAgents.js +48 -140
  21. package/dist/commands/install/azureAgents.js +37 -77
  22. package/dist/commands/install/edgeAgents.js +15 -108
  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 +38 -115
  36. package/dist/commands/install/platform.js +18 -50
  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 +117 -342
  56. package/dist/common/utils.js +37 -99
  57. package/dist/main.js +0 -2
  58. package/package.json +2 -2
@@ -0,0 +1,286 @@
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(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
14
+ 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; }
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 a File Path within the repository that the agent will use',
92
+ FILE_PATTERNS: 'Enter a File Pattern that the agent will use (Optional)',
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 a file name must match to be discovered"));
194
+ while (askFilePatterns) {
195
+ const pattern = await (0, _basicPrompts.askInput)({
196
+ msg: SaasPrompts.FILE_PATTERNS,
197
+ allowEmptyInput: true
198
+ });
199
+ if (pattern.trim() !== "") {
200
+ hostedAgentValues.filePatterns.push(pattern);
201
+ askFilePatterns = (await (0, _basicPrompts.askList)({
202
+ msg: SaasPrompts.ENTER_MORE_PATTERNS,
203
+ default: _types.YesNo.No,
204
+ choices: _types.YesNoChoices
205
+ })) === _types.YesNo.Yes;
206
+ } else {
207
+ askFilePatterns = false;
208
+ }
209
+ }
210
+ return hostedAgentValues;
211
+ };
212
+ const generateOutput = async installConfig => {
213
+ return `Install complete of hosted agent for ${installConfig.gatewayType} region`;
214
+ };
215
+ const createEncryptedAccessData = async (hostedAgentValues, dataplaneRes) => {
216
+ var _dataplaneRes$securit, _dataplaneRes$securit2;
217
+ // grab key from data plane resource
218
+ let key = ((_dataplaneRes$securit = dataplaneRes.security) === null || _dataplaneRes$securit === void 0 ? void 0 : _dataplaneRes$securit.encryptionKey) || "";
219
+ let hash = ((_dataplaneRes$securit2 = dataplaneRes.security) === null || _dataplaneRes$securit2 === void 0 ? void 0 : _dataplaneRes$securit2.encryptionHash) || "";
220
+ if (key === "" || hash === "") {
221
+ throw Error(`cannot encrypt access data as the encryption key info was incomplete`);
222
+ }
223
+ console.log(hostedAgentValues.getAccessData());
224
+ let encData = _crypto.default.publicEncrypt({
225
+ key: key,
226
+ padding: _crypto.default.constants.RSA_PKCS1_OAEP_PADDING,
227
+ oaepHash: hash
228
+ }, Buffer.from(hostedAgentValues.getAccessData()));
229
+ return encData.toString("base64");
230
+ };
231
+ const completeInstall = async (installConfig, apiServerClient, defsManager) => {
232
+ /**
233
+ * Create agent resources
234
+ */
235
+ console.log("\n");
236
+ let gitHubAgentValues = installConfig.gatewayConfig;
237
+
238
+ // create the environment, if necessary
239
+ installConfig.centralConfig.environment = installConfig.centralConfig.ampcEnvInfo.isNew ? await helpers.createByResourceType(apiServerClient, defsManager, installConfig.centralConfig.ampcEnvInfo.name, 'Environment', 'env', {
240
+ axwayManaged: installConfig.centralConfig.axwayManaged,
241
+ production: installConfig.centralConfig.production
242
+ }) : installConfig.centralConfig.ampcEnvInfo.name;
243
+ if (installConfig.gatewayType === _types.GatewayTypes.GITHUB) {
244
+ gitHubAgentValues.dataplaneConfig = new GitHubDataplaneConfig(gitHubAgentValues.repositoryName, gitHubAgentValues.repositoryOwner, new GitHubFilterConfig(gitHubAgentValues.filePaths, gitHubAgentValues.filePatterns));
245
+ }
246
+
247
+ // create the data plane resource
248
+ let dataplaneRes = await helpers.createNewDataPlaneResource(apiServerClient, defsManager, installConfig.centralConfig.environment, _types.GatewayTypeToDataPlane[installConfig.gatewayType], gitHubAgentValues.dataplaneConfig);
249
+ // create data plane secret resource
250
+ try {
251
+ await helpers.createNewDataPlaneSecretResource(apiServerClient, defsManager, installConfig.centralConfig.environment, _types.GatewayTypeToDataPlane[installConfig.gatewayType], dataplaneRes.name, await createEncryptedAccessData(gitHubAgentValues, dataplaneRes));
252
+ } catch (error) {
253
+ console.log(error);
254
+ console.log(_chalk.default.redBright("rolling back installation. Please check the credential data before re-running install"));
255
+ if (installConfig.centralConfig.ampcEnvInfo.isNew) {
256
+ await helpers.deleteByResourceType(apiServerClient, defsManager, installConfig.centralConfig.ampcEnvInfo.name, 'Environment', 'env');
257
+ } else {
258
+ await helpers.deleteByResourceType(apiServerClient, defsManager, dataplaneRes.name, "Dataplane", "dp", installConfig.centralConfig.environment);
259
+ }
260
+ return;
261
+ }
262
+
263
+ // create discovery agent resource
264
+ 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);
265
+ console.log(await generateOutput(installConfig));
266
+ };
267
+ const GitHubSaaSInstallMethods = exports.GitHubSaaSInstallMethods = {
268
+ GetBundleType: askBundleType,
269
+ GetDeploymentType: askConfigType,
270
+ AskGatewayQuestions: gatewayConnectivity,
271
+ FinalizeGatewayInstall: completeInstall,
272
+ ConfigFiles: [],
273
+ AgentNameMap: {
274
+ [_types.AgentTypes.da]: _types.AgentNames.GITHUB_DA,
275
+ [_types.AgentTypes.ta]: _types.AgentNames.GITHUB_DA
276
+ },
277
+ GatewayDisplay: _types.GatewayTypes.GITHUB
278
+ };
279
+
280
+ // These are the items that are not exported, but need to be for testing
281
+ const testables = exports.testables = {
282
+ SaasAgentValues,
283
+ SaasGitHubAgentValues,
284
+ SaasPrompts,
285
+ ConfigFiles
286
+ };
@@ -4,32 +4,21 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createSecret = exports.createNewDataPlaneSecretResource = exports.createNewDataPlaneResource = exports.createNewAgentResource = exports.createDosaAndCerts = exports.createByResourceType = exports.createBackUpConfigs = void 0;
7
-
8
7
  var _chalk = _interopRequireDefault(require("chalk"));
9
-
10
8
  var _snooplogg = _interopRequireDefault(require("snooplogg"));
11
-
12
9
  var _fsExtra = _interopRequireDefault(require("fs-extra"));
13
-
14
10
  var _bashCommands = require("../../../common/bashCommands");
15
-
16
11
  var _Kubectl = require("../../../common/Kubectl");
17
-
18
12
  var _PlatformClient = require("../../../common/PlatformClient");
19
-
20
13
  var _types = require("../../../common/types");
21
-
22
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
-
24
15
  const {
25
16
  log
26
17
  } = (0, _snooplogg.default)('central: install: helpers: creators');
27
-
28
18
  const createBackUpConfigs = async configFiles => {
29
19
  let fileExist = false;
30
20
  let dateTimeStamp = new Date().toISOString().slice(0, 10).concat(' ').concat(new Date().toLocaleTimeString('it-IT')).replace(/:\s*/g, '.');
31
21
  const backupDate = `${dateTimeStamp}-`;
32
-
33
22
  for (let configFile of configFiles) {
34
23
  if (_fsExtra.default.existsSync(configFile)) {
35
24
  fileExist = true;
@@ -41,21 +30,16 @@ const createBackUpConfigs = async configFiles => {
41
30
  });
42
31
  }
43
32
  }
44
-
45
33
  return fileExist;
46
34
  };
47
-
48
35
  exports.createBackUpConfigs = createBackUpConfigs;
49
-
50
36
  const createDosaAndCerts = async (client, name) => {
51
37
  console.log('Creating a new service account.');
52
38
  const {
53
39
  publicKey,
54
40
  privateKey
55
41
  } = await (0, _bashCommands.createKeyPair)();
56
-
57
42
  const publicCert = _fsExtra.default.readFileSync(publicKey).toString();
58
-
59
43
  const account = await client.createServiceAccount({
60
44
  name: name,
61
45
  desc: name,
@@ -66,18 +50,14 @@ const createDosaAndCerts = async (client, name) => {
66
50
  console.log(_chalk.default.green(`The private key has been placed at ${privateKey}\nThe public key has been placed at ${publicKey}`));
67
51
  return new _types.DosaAccount(account.client_id, publicKey, privateKey);
68
52
  };
69
-
70
53
  exports.createDosaAndCerts = createDosaAndCerts;
71
-
72
54
  const createByResourceType = async (client, defsManager, name, resourceType, resourceShortName, spec = {}, scopeName = '') => {
73
- console.log(`Creating a new ${resourceType}`); // NOTE: only a first found set is used
74
-
55
+ console.log(`Creating a new ${resourceType}`);
56
+ // NOTE: only a first found set is used
75
57
  const defs = defsManager.findDefsByWord(resourceShortName);
76
-
77
58
  if (!defs) {
78
59
  throw Error(`the server doesn't have a resource type "${resourceType}"`);
79
60
  }
80
-
81
61
  const result = await client.createResource({
82
62
  // @ts-ignore payload
83
63
  resource: {
@@ -88,12 +68,9 @@ const createByResourceType = async (client, defsManager, name, resourceType, res
88
68
  scopeDef: defs[0].scope ? defs[0].scope : undefined,
89
69
  scopeName: defs[0].scope ? scopeName || name : undefined
90
70
  });
91
-
92
71
  if (!result.data) {
93
72
  var _result$error;
94
-
95
73
  const errMsg = `cannot create a new ${resourceType.toLowerCase()}`;
96
-
97
74
  if ((_result$error = result.error) !== null && _result$error !== void 0 && _result$error.length) {
98
75
  throw Error(`${errMsg}: ${result.error[0].detail}.`);
99
76
  } else {
@@ -102,30 +79,24 @@ const createByResourceType = async (client, defsManager, name, resourceType, res
102
79
  } else {
103
80
  console.log(`New ${resourceType.toLowerCase()} "${result.data.name}" has been successfully created.`);
104
81
  }
105
-
106
82
  return result.data.name;
107
83
  };
108
-
109
84
  exports.createByResourceType = createByResourceType;
110
-
111
85
  const createNewAgentResource = async (client, defsManager, envName, dataPlaneType, agentResource, agentType, owningTeam, agentName, dataPlaneName, frequency, queue, config) => {
112
- console.log(`Creating a new ${agentResource}, with data plane type: ${dataPlaneType}.`); // NOTE: only a first found set is used
113
-
86
+ console.log(`Creating a new ${agentResource}, with data plane type: ${dataPlaneType}.`);
87
+ // NOTE: only a first found set is used
114
88
  const defs = defsManager.findDefsByWord(agentType);
115
-
116
89
  if (!defs) {
117
90
  throw Error(`the server doesn't have a resource type "${agentType}"`);
118
- } // create the dataplane object
119
-
91
+ }
120
92
 
93
+ // create the dataplane object
121
94
  let withSubResources = false;
122
95
  let dataplane = {};
123
-
124
96
  if (dataPlaneName) {
125
97
  dataplane.name = dataPlaneName;
126
98
  withSubResources = true;
127
99
  }
128
-
129
100
  frequency ? dataplane.frequency = frequency : null;
130
101
  queue ? agentResource === _types.AgentResourceKind.da ? dataplane.queueDiscovery = queue : dataplane.queueTrafficCollection = queue : null;
131
102
  config ? null : config = {
@@ -146,12 +117,9 @@ const createNewAgentResource = async (client, defsManager, envName, dataPlaneTyp
146
117
  scopeName: envName,
147
118
  withSubResources: withSubResources
148
119
  });
149
-
150
120
  if (!result.data) {
151
121
  var _result$error2;
152
-
153
122
  const errMsg = `cannot create a new agent`;
154
-
155
123
  if ((_result$error2 = result.error) !== null && _result$error2 !== void 0 && _result$error2.length) {
156
124
  throw Error(`${errMsg}: ${result.error[0].detail}.`);
157
125
  } else {
@@ -160,9 +128,9 @@ const createNewAgentResource = async (client, defsManager, envName, dataPlaneTyp
160
128
  } else {
161
129
  console.log(`New agent of type "${defs[0].resource.name}" named "${result.data.name}" has been successfully created.`);
162
130
  }
163
-
164
131
  return result.data.name;
165
132
  };
133
+
166
134
  /**
167
135
  * @description Helper func to create a new DataPlane resource
168
136
  * @param client API Service Client
@@ -170,19 +138,14 @@ const createNewAgentResource = async (client, defsManager, envName, dataPlaneTyp
170
138
  * @param envName Environment Name
171
139
  * @param dataPlaneType DataPlane Type
172
140
  */
173
-
174
-
175
141
  exports.createNewAgentResource = createNewAgentResource;
176
-
177
142
  const createNewDataPlaneResource = async (client, defsManager, envName, dataPlaneType, config) => {
178
- console.log(`Creating a new Dataplane resource, with type: ${dataPlaneType}.`); // NOTE: only a first found set is used
179
-
143
+ console.log(`Creating a new Dataplane resource, with type: ${dataPlaneType}.`);
144
+ // NOTE: only a first found set is used
180
145
  const defs = defsManager.findDefsByWord("dp");
181
-
182
146
  if (!defs) {
183
147
  throw Error(`the server doesn't have a resource type "Dataplane"`);
184
148
  }
185
-
186
149
  const result = await client.createResource({
187
150
  // @ts-ignore payload
188
151
  resource: {
@@ -196,12 +159,9 @@ const createNewDataPlaneResource = async (client, defsManager, envName, dataPlan
196
159
  scopeDef: defs[0].scope ? defs[0].scope : undefined,
197
160
  scopeName: envName
198
161
  });
199
-
200
162
  if (!result.data) {
201
163
  var _result$error3;
202
-
203
164
  const errMsg = `cannot create a new dataplane`;
204
-
205
165
  if ((_result$error3 = result.error) !== null && _result$error3 !== void 0 && _result$error3.length) {
206
166
  throw Error(`${errMsg}: ${result.error[0].detail}.`);
207
167
  } else {
@@ -210,9 +170,9 @@ const createNewDataPlaneResource = async (client, defsManager, envName, dataPlan
210
170
  } else {
211
171
  console.log(`New dataplane of type "${defs[0].resource.name}" named "${result.data.name}" has been successfully created.`);
212
172
  }
213
-
214
173
  return result.data;
215
174
  };
175
+
216
176
  /**
217
177
  * @description Helper func to create a new DataPlane resource
218
178
  * @param client API Service Client
@@ -221,19 +181,14 @@ const createNewDataPlaneResource = async (client, defsManager, envName, dataPlan
221
181
  * @param dataPlaneName DataPlane Name
222
182
  * @param accessData Encrypted Access Data
223
183
  */
224
-
225
-
226
184
  exports.createNewDataPlaneResource = createNewDataPlaneResource;
227
-
228
185
  const createNewDataPlaneSecretResource = async (client, defsManager, envName, dataPlaneType, dataPlaneName, accessData) => {
229
- console.log(`Creating a new DataplaneSecret resource.`); // NOTE: only a first found set is used
230
-
186
+ console.log(`Creating a new DataplaneSecret resource.`);
187
+ // NOTE: only a first found set is used
231
188
  const defs = defsManager.findDefsByWord("dps");
232
-
233
189
  if (!defs) {
234
190
  throw Error(`the server doesn't have a resource type "DataplaneSecret"`);
235
191
  }
236
-
237
192
  const result = await client.createResource({
238
193
  // @ts-ignore payload
239
194
  resource: {
@@ -248,12 +203,9 @@ const createNewDataPlaneSecretResource = async (client, defsManager, envName, da
248
203
  scopeName: envName
249
204
  });
250
205
  log(result);
251
-
252
206
  if (!result.data) {
253
207
  var _result$error4;
254
-
255
208
  const errMsg = `cannot create a new agent`;
256
-
257
209
  if ((_result$error4 = result.error) !== null && _result$error4 !== void 0 && _result$error4.length) {
258
210
  throw Error(`${errMsg}: ${result.error[0].detail}.`);
259
211
  } else {
@@ -262,32 +214,27 @@ const createNewDataPlaneSecretResource = async (client, defsManager, envName, da
262
214
  } else {
263
215
  console.log(`New secret of type "${defs[0].resource.name}" named "${result.data.name}" has been successfully created.`);
264
216
  }
265
-
266
217
  return result.data;
267
218
  };
219
+
268
220
  /**
269
221
  * @description Helper func to check for existing secret, and clean up old secret before creating a new one.
270
222
  * @param namespace Namespace to create the secret in.
271
223
  * @param secretName The name of the secret.
272
224
  * @param createFunc A function that will create the secret
273
225
  */
274
-
275
-
276
226
  exports.createNewDataPlaneSecretResource = createNewDataPlaneSecretResource;
277
-
278
227
  const createSecret = async (namespace, secretName, createFunc) => {
279
- const secrets = await _Kubectl.kubectl.get('secrets', `-n ${namespace} ${secretName}`); // NotFound errors are ok. Throw an error for anything else.
280
-
228
+ const secrets = await _Kubectl.kubectl.get('secrets', `-n ${namespace} ${secretName}`);
229
+ // NotFound errors are ok. Throw an error for anything else.
281
230
  if (secrets.error && !secrets.error.includes('NotFound')) {
282
231
  throw Error(secrets.error);
283
- } // delete the secret if it already exists and then re-create it.
284
-
232
+ }
285
233
 
234
+ // delete the secret if it already exists and then re-create it.
286
235
  if (secrets.data.length > 0) {
287
236
  await _Kubectl.kubectl.delete('secret', `-n ${namespace} ${secretName}`);
288
237
  }
289
-
290
238
  await createFunc();
291
239
  };
292
-
293
240
  exports.createSecret = createSecret;
@@ -4,20 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.deleteByResourceType = void 0;
7
-
8
7
  var _chalk = _interopRequireDefault(require("chalk"));
9
-
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
9
  const deleteByResourceType = async (client, defsManager, name, resourceType, resourceShortName, scopeName = '') => {
13
- console.log(`Deleting ${resourceType}`); // NOTE: only a first found set is used
14
-
10
+ console.log(`Deleting ${resourceType}`);
11
+ // NOTE: only a first found set is used
15
12
  const defs = defsManager.findDefsByWord(resourceShortName);
16
-
17
13
  if (!defs) {
18
14
  throw Error(`the server doesn't have a resource type "${resourceType}"`);
19
15
  }
20
-
21
16
  const result = await client.deleteResourceByName({
22
17
  // @ts-ignore resource is not important for the test`
23
18
  resourceName: name,
@@ -26,12 +21,9 @@ const deleteByResourceType = async (client, defsManager, name, resourceType, res
26
21
  scopeDef: defs[0].scope ? defs[0].scope : undefined,
27
22
  scopeName: defs[0].scope ? scopeName || name : undefined
28
23
  });
29
-
30
24
  if (!result.data) {
31
25
  var _result$error;
32
-
33
26
  const errMsg = `error deleting resource ${resourceType.toLowerCase()}`;
34
-
35
27
  if ((_result$error = result.error) !== null && _result$error !== void 0 && _result$error.length) {
36
28
  console.log(_chalk.default.redBright(`${errMsg}: ${result.error[0].detail}.`));
37
29
  } else {
@@ -41,5 +33,4 @@ const deleteByResourceType = async (client, defsManager, name, resourceType, res
41
33
  console.log(`New ${resourceType.toLowerCase()} "${result.data.name}" has been successfully deleted.`);
42
34
  }
43
35
  };
44
-
45
36
  exports.deleteByResourceType = deleteByResourceType;