@axway/axway-central-cli 2.14.3 → 2.15.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.
@@ -37,6 +37,8 @@ var helpers = _interopRequireWildcard(require("./helpers"));
37
37
 
38
38
  var istioAgents = _interopRequireWildcard(require("./istioAgents"));
39
39
 
40
+ var saasAgents = _interopRequireWildcard(require("./saasAgents"));
41
+
40
42
  var platform = _interopRequireWildcard(require("./platform"));
41
43
 
42
44
  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); }
@@ -51,6 +53,7 @@ const {
51
53
  const localhost = 'localhost';
52
54
  exports.localhost = localhost;
53
55
  const prompts = {
56
+ hostedAgentOption: 'Will this agent be hosted by Axway',
54
57
  selectGatewayType: 'Select the type of gateway you want to connect'
55
58
  };
56
59
  exports.prompts = prompts;
@@ -61,6 +64,9 @@ const agentInstallFlows = {
61
64
  [_types.GatewayTypes.AZURE_GATEWAY]: azureAgents.AzureInstallMethods,
62
65
  [_types.GatewayTypes.ISTIO]: istioAgents.IstioInstallMethods
63
66
  };
67
+ const saasAgentInstallFlows = {
68
+ [_types.GatewayTypes.AWS_GATEWAY]: saasAgents.AWSSaaSInstallMethods
69
+ };
64
70
 
65
71
  const createConfigBackup = async (configFiles, gatewayType) => {
66
72
  // If current configurations exist, back them up
@@ -71,6 +77,16 @@ const createConfigBackup = async (configFiles, gatewayType) => {
71
77
  }
72
78
  };
73
79
 
80
+ const determineRegion = async region => {
81
+ let configurationRegion = (await (0, _utils.getConfig)())[_CliConfigManager.CliConfigKeys.REGION];
82
+
83
+ if (region) {
84
+ return region.toString();
85
+ }
86
+
87
+ return configurationRegion ? configurationRegion : _types.Regions.US;
88
+ };
89
+
74
90
  const agents = {
75
91
  action: async function ({
76
92
  argv,
@@ -107,43 +123,43 @@ const agents = {
107
123
  const accountInfo = await platformClient.getAccountInfo();
108
124
  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);
109
125
  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);
110
-
111
- if (!isCentralAdmin || !isPlatformAdmin) {
112
- if (!accountInfo || accountInfo.isPlatform) {
113
- render.error('Error: Not authorized. Account must be assigned the roles: Platform Admin, Central Admin');
114
- } else {
115
- render.error('Error: Not authorized. "Service Account" must be authorized with a user account with "Tooling Credentials" assigned the roles: Platform Admin, Central Admin');
116
- render.error('See: https://docs.axway.com/bundle/axwaycli-open-docs/page/docs/authentication/index.html#service-account-with-username-password');
117
- }
118
-
119
- process.exit(1);
120
- } // helper text
121
-
126
+ checkUserRole(isCentralAdmin, isPlatformAdmin, accountInfo, render); // helper text
122
127
 
123
128
  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`));
124
129
  let installConfig = new _types.AgentInstallConfig();
125
- installConfig.centralConfig.axwayManaged = !!axwayManaged;
126
- let configurationRegion = (await (0, _utils.getConfig)())[_CliConfigManager.CliConfigKeys.REGION]; // top priority is region option on command line, second priority is region from config file, default is US
130
+ installConfig.centralConfig.axwayManaged = !!axwayManaged; // top priority is region option on command line, second priority is region from config file, default is US
127
131
 
128
- installConfig.centralConfig.region = region ? region.toString() : configurationRegion ? configurationRegion : _types.Regions.US;
132
+ installConfig.centralConfig.region = await determineRegion(region);
129
133
  installConfig.centralConfig.singleEntryPointUrl = _types.SingleEntryPointUrls[installConfig.centralConfig.region]; // gateway type
130
134
 
131
135
  let gatewayType = await (0, _basicPrompts.askList)({
132
136
  msg: prompts.selectGatewayType,
133
137
  choices: [_types.GatewayTypes.EDGE_GATEWAY, _types.GatewayTypes.AWS_GATEWAY, _types.GatewayTypes.AZURE_GATEWAY, _types.GatewayTypes.ISTIO]
134
- }); // if gateway type is edge ask Gateway only or not
138
+ });
139
+
140
+ if (gatewayType === _types.GatewayTypes.AWS_GATEWAY) {
141
+ // hosted vs on premise
142
+ installConfig.switches.isHostedInstall = (await (0, _basicPrompts.askList)({
143
+ msg: prompts.hostedAgentOption,
144
+ choices: _types.YesNoChoices,
145
+ default: _types.YesNo.Yes
146
+ })) === _types.YesNo.Yes;
147
+ } // if gateway type is edge ask Gateway only or not
148
+
135
149
 
136
150
  if (gatewayType === _types.GatewayTypes.EDGE_GATEWAY) {
137
151
  installConfig.switches.isGatewayOnly = false;
138
152
  gatewayType = await edgeAgents.askIsGatewayOnlyMode();
139
-
140
- if (gatewayType === _types.GatewayTypes.EDGE_GATEWAY_ONLY) {
141
- installConfig.switches.isGatewayOnly = true;
142
- }
143
153
  }
144
154
 
155
+ installConfig.switches.isGatewayOnly = gatewayType === _types.GatewayTypes.EDGE_GATEWAY_ONLY;
145
156
  installConfig.gatewayType = gatewayType;
146
- const agentInstallFlow = agentInstallFlows[installConfig.gatewayType]; // Create the object of GatewayTypes -> BundleType functions
157
+ let agentInstallFlow = agentInstallFlows[installConfig.gatewayType];
158
+
159
+ if (installConfig.switches.isHostedInstall) {
160
+ agentInstallFlow = saasAgentInstallFlows[installConfig.gatewayType];
161
+ } // Create the object of GatewayTypes -> BundleType functions
162
+
147
163
 
148
164
  installConfig.bundleType = await agentInstallFlow.GetBundleType();
149
165
  installConfig.switches.isDaEnabled = installConfig.bundleType === _types.BundleType.ALL_AGENTS || installConfig.bundleType === _types.BundleType.DISCOVERY;
@@ -152,18 +168,9 @@ const agents = {
152
168
  installConfig.deploymentType = await agentInstallFlow.GetDeploymentType();
153
169
  installConfig.switches.isHelmInstall = installConfig.deploymentType === _types.AgentConfigTypes.HELM;
154
170
  installConfig.switches.isDockerInstall = installConfig.deploymentType === _types.AgentConfigTypes.DOCKERIZED;
155
- installConfig.switches.isBinaryInstall = installConfig.deploymentType === _types.AgentConfigTypes.BINARIES; // Get the version of the agents from jfrog
156
-
157
- if (agentInstallFlow.AgentNameMap) {
158
- if (installConfig.switches.isDaEnabled) {
159
- installConfig.daVersion = await helpers.getLatestAgentVersion(agentInstallFlow.AgentNameMap[_types.AgentTypes.da]);
160
- }
161
-
162
- if (installConfig.switches.isTaEnabled) {
163
- installConfig.taVersion = await helpers.getLatestAgentVersion(agentInstallFlow.AgentNameMap[_types.AgentTypes.ta]);
164
- }
165
- } // if EDGE_GATEWAY or EDGE_GATEWAY_ONLY and isDaEnabled, ask if the organization structure should replicate
171
+ installConfig.switches.isBinaryInstall = installConfig.deploymentType === _types.AgentConfigTypes.BINARIES; // Get the version of the agents from jfrog, not needed in hosted install
166
172
 
173
+ await getAgentVersions(agentInstallFlow, installConfig); // if EDGE_GATEWAY or EDGE_GATEWAY_ONLY and isDaEnabled, ask if the organization structure should replicate
167
174
 
168
175
  if ((gatewayType === _types.GatewayTypes.EDGE_GATEWAY || gatewayType === _types.GatewayTypes.EDGE_GATEWAY_ONLY) && installConfig.switches.isDaEnabled) {
169
176
  installConfig.switches.isOrgRep = await edgeAgents.askOrganizationReplication();
@@ -174,16 +181,14 @@ const agents = {
174
181
 
175
182
  installConfig.gatewayConfig = await agentInstallFlow.AskGatewayQuestions(installConfig, apiServerClient, defsManager); // traceability options
176
183
 
177
- if (installConfig.switches.isTaEnabled) {
184
+ if (installConfig.switches.isTaEnabled && !installConfig.switches.isHostedInstall) {
178
185
  installConfig.traceabilityConfig = await platform.getTraceabilityConfig(installConfig);
179
186
  } // create backup
180
187
 
181
188
 
182
189
  await createConfigBackup(agentInstallFlow.ConfigFiles, agentInstallFlow.GatewayDisplay); // run any install preprocess steps
183
190
 
184
- if (agentInstallFlow.InstallPreprocess) installConfig = await agentInstallFlow.InstallPreprocess(installConfig); // finalize Platform setup
185
-
186
- installConfig = await platform.finalizeCentralInstall(apiServerClient, platformClient, defsManager, installConfig); // finalize gateway setup and output
191
+ installConfig = await finishInstall(agentInstallFlow, installConfig, apiServerClient, platformClient, defsManager); // finalize gateway setup and output
187
192
 
188
193
  await agentInstallFlow.FinalizeGatewayInstall(installConfig, apiServerClient, defsManager);
189
194
  } catch (e) {
@@ -201,4 +206,37 @@ const agents = {
201
206
  options: { ..._types.commonCmdArgsDescription
202
207
  }
203
208
  };
204
- exports.agents = agents;
209
+ exports.agents = agents;
210
+
211
+ async function getAgentVersions(agentInstallFlow, installConfig) {
212
+ if (agentInstallFlow.AgentNameMap && !installConfig.switches.isHostedInstall && installConfig.switches.isDaEnabled) {
213
+ installConfig.daVersion = await helpers.getLatestAgentVersion(agentInstallFlow.AgentNameMap[_types.AgentTypes.da]);
214
+ }
215
+
216
+ if (agentInstallFlow.AgentNameMap && !installConfig.switches.isHostedInstall && installConfig.switches.isTaEnabled) {
217
+ installConfig.taVersion = await helpers.getLatestAgentVersion(agentInstallFlow.AgentNameMap[_types.AgentTypes.ta]);
218
+ }
219
+ }
220
+
221
+ async function finishInstall(agentInstallFlow, installConfig, apiServerClient, platformClient, defsManager) {
222
+ if (agentInstallFlow.InstallPreprocess) installConfig = await agentInstallFlow.InstallPreprocess(installConfig); // finalize Platform setup, only for non-hosted agents
223
+
224
+ if (!installConfig.switches.isHostedInstall) {
225
+ installConfig = await platform.finalizeCentralInstall(apiServerClient, platformClient, defsManager, installConfig);
226
+ }
227
+
228
+ return installConfig;
229
+ }
230
+
231
+ function checkUserRole(isCentralAdmin, isPlatformAdmin, accountInfo, render) {
232
+ if (!isCentralAdmin || !isPlatformAdmin) {
233
+ if (!accountInfo || accountInfo.isPlatform) {
234
+ render.error('Error: Not authorized. Account must be assigned the roles: Platform Admin, Central Admin');
235
+ } else {
236
+ render.error('Error: Not authorized. "Service Account" must be authorized with a user account with "Tooling Credentials" assigned the roles: Platform Admin, Central Admin');
237
+ render.error('See: https://docs.axway.com/bundle/axwaycli-open-docs/page/docs/authentication/index.html#service-account-with-username-password');
238
+ }
239
+
240
+ process.exit(1);
241
+ }
242
+ }
@@ -33,7 +33,7 @@ const {
33
33
  const daImage = `${_types.PublicDockerRepoBaseUrl}${_types.BasePaths.DockerAgentPublicRepo}/${_types.AgentNames.AWS_DA}`;
34
34
  const taImage = `${_types.PublicDockerRepoBaseUrl}${_types.BasePaths.DockerAgentPublicRepo}/${_types.AgentNames.AWS_TA}`; // DeploymentTypes - ways the agents may be deployed with an AWS APIGW setup
35
35
 
36
- let DeploymentTypes; // AWSRegions - base set of regions, may use option outside this list
36
+ let DeploymentTypes; // EC2InstanceTypes - instance types allowed in cloud formation document
37
37
 
38
38
  exports.DeploymentTypes = DeploymentTypes;
39
39
 
@@ -43,18 +43,6 @@ exports.DeploymentTypes = DeploymentTypes;
43
43
  DeploymentTypes["OTHER"] = "Other";
44
44
  })(DeploymentTypes || (exports.DeploymentTypes = DeploymentTypes = {}));
45
45
 
46
- var AWSRegions; // EC2InstanceTypes - instance types allowed in cloud formation document
47
-
48
- (function (AWSRegions) {
49
- AWSRegions["US_EAST_1"] = "us-east-1";
50
- AWSRegions["US_EAST_2"] = "us-east-2";
51
- AWSRegions["US_WEST_1"] = "us-west-1";
52
- AWSRegions["US_WEST_2"] = "us-west-2";
53
- AWSRegions["EU_WEST_1"] = "eu-west-1";
54
- AWSRegions["EU_WEST_2"] = "eu-west-2";
55
- AWSRegions["EU_WEST_3"] = "eu-west-3";
56
- })(AWSRegions || (AWSRegions = {}));
57
-
58
46
  var EC2InstanceTypes;
59
47
 
60
48
  (function (EC2InstanceTypes) {
@@ -101,8 +89,6 @@ const AWSPrompts = {
101
89
  EC2_TYPE: 'Select the EC2 instance type',
102
90
  KEY_PAIR: 'Enter the EC2 KeyPair name that will be used to connect via SSH to the EC2 instance',
103
91
  PUBLIC_IP: 'Assign a Public IP Address to this, only change if your VPC has a NAT Gateway',
104
- REGION_INPUT: 'Enter an AWS Region',
105
- REGION_LIST: 'Select an AWS Region',
106
92
  SECURITY_GROUP: 'Enter the Security Group for the EC2 Instance of ECS Container',
107
93
  SETUP_APIGW_CW: 'The Amazon API Gateway service requires a role to write usage logs to Cloud Watch. Do you want to configure that?',
108
94
  SSH_LOCATION: 'Enter the IP address range that can be used to SSH to the EC2 instances',
@@ -131,46 +117,6 @@ const askConfigType = async () => {
131
117
 
132
118
  exports.askConfigType = askConfigType;
133
119
 
134
- const askAWSRegion = async (region = '') => {
135
- let answer = await (0, _basicPrompts.askList)({
136
- msg: AWSPrompts.REGION_LIST,
137
- default: region,
138
- choices: [{
139
- name: 'Enter an AWS Region not on the list',
140
- value: 'CREATE_NEW'
141
- }, {
142
- name: AWSRegions.US_EAST_1,
143
- value: AWSRegions.US_EAST_1
144
- }, {
145
- name: AWSRegions.US_EAST_2,
146
- value: AWSRegions.US_EAST_2
147
- }, {
148
- name: AWSRegions.US_WEST_1,
149
- value: AWSRegions.US_WEST_1
150
- }, {
151
- name: AWSRegions.US_WEST_2,
152
- value: AWSRegions.US_WEST_2
153
- }, {
154
- name: AWSRegions.EU_WEST_1,
155
- value: AWSRegions.EU_WEST_1
156
- }, {
157
- name: AWSRegions.EU_WEST_2,
158
- value: AWSRegions.EU_WEST_2
159
- }, {
160
- name: AWSRegions.EU_WEST_3,
161
- value: AWSRegions.EU_WEST_3
162
- }]
163
- });
164
-
165
- if (answer === 'CREATE_NEW') {
166
- return await (0, _basicPrompts.askInput)({
167
- msg: AWSPrompts.REGION_INPUT
168
- });
169
- } else {
170
- return answer;
171
- }
172
- };
173
-
174
120
  const askDeployment = async () => {
175
121
  return (0, _basicPrompts.askList)({
176
122
  msg: AWSPrompts.DEPLOYMENT,
@@ -340,7 +286,7 @@ async function configureECSDeployment(awsAgentValues) {
340
286
 
341
287
  const gatewayConnectivity = async installConfig => {
342
288
  console.log('\nCONNECTION TO AMAZON API GATEWAY:');
343
- console.log(_chalk.default.gray(`You need credentials for executing the AWS CLI commands.\n` + `The Discovery Agents need to connect to the Amazon (AWS) API Gateway to discover API's for publishing to Amplify Central and/or the Unified Catalog.\n` + `The Traceability Agent needs to connect to the AWS API Gateway for the collection of transaction headers.\n` + `These headers will be formatted and fowarded to the Amplify Central Observer.\n` + `We recommend to use two different set of credentials: one for AWS CLI and one for the agents`)); // DeploymentType
289
+ console.log(_chalk.default.gray(`You need credentials for executing the AWS CLI commands.\n` + `The Discovery Agent needs to connect to the Amazon (AWS) API Gateway to discover API's for publishing to Amplify Central and/or the Unified Catalog.\n` + `The Traceability Agent needs to connect to the AWS API Gateway for the collection of transaction headers.\n` + `These headers will be formatted and forwarded to the Amplify Central Observer.\n` + `We recommend to use two different set of credentials: one for AWS CLI and one for the agents`)); // DeploymentType
344
290
 
345
291
  const deploymentType = await askDeployment();
346
292
  let awsAgentValues = new helpers.AWSAgentValues(deploymentType);
@@ -361,7 +307,7 @@ const gatewayConnectivity = async installConfig => {
361
307
  } // AWS Region
362
308
 
363
309
 
364
- awsAgentValues.region = await askAWSRegion(); // S3 bucket
310
+ awsAgentValues.region = await helpers.askAWSRegion(); // S3 bucket
365
311
 
366
312
  awsAgentValues.cloudFormationConfig.AgentResourcesBucket = await (0, _basicPrompts.askInput)({
367
313
  msg: AWSPrompts.S3_BUCKET,
@@ -517,7 +463,7 @@ ${_chalk.default.cyan(` aws ssm put-parameter --type SecureString --name ${aw
517
463
  let s3BaseIncludes = '';
518
464
  s3BaseFiles.forEach(value => s3BaseIncludes += `--include "${value}" `); // if region is AWS default, 'us-east-1', region unnecessary in cloudformation template url
519
465
 
520
- const s3Region = awsAgentValues.region === AWSRegions.US_EAST_1 ? `s3` : `s3.${awsAgentValues.region}`;
466
+ const s3Region = awsAgentValues.region === _types.AWSRegions.US_EAST_1 ? `s3` : `s3.${awsAgentValues.region}`;
521
467
  return `
522
468
  To complete the install, run the following AWS CLI command:
523
469
  - Create, if necessary, and upload all files to your S3 bucket
@@ -667,7 +613,6 @@ const AWSInstallMethods = {
667
613
  exports.AWSInstallMethods = AWSInstallMethods;
668
614
  const testables = {
669
615
  DeploymentTypes,
670
- AWSRegions,
671
616
  AWSPrompts,
672
617
  EC2InstanceTypes,
673
618
  unzipCFContinuousDiscoveryZip,
@@ -3,10 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.createSecret = exports.createNewAgentResource = exports.createDosaAndCerts = exports.createByResourceType = exports.createBackUpConfigs = void 0;
6
+ exports.createSecret = exports.createNewDataPlaneSecretResource = exports.createNewDataPlaneResource = exports.createNewAgentResource = exports.createDosaAndCerts = exports.createByResourceType = exports.createBackUpConfigs = void 0;
7
7
 
8
8
  var _chalk = _interopRequireDefault(require("chalk"));
9
9
 
10
+ var _snooplogg = _interopRequireDefault(require("snooplogg"));
11
+
10
12
  var _fsExtra = _interopRequireDefault(require("fs-extra"));
11
13
 
12
14
  var _bashCommands = require("../../../common/bashCommands");
@@ -19,6 +21,10 @@ var _types = require("../../../common/types");
19
21
 
20
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
23
 
24
+ const {
25
+ log
26
+ } = (0, _snooplogg.default)('central: install: helpers: creators');
27
+
22
28
  const createBackUpConfigs = async configFiles => {
23
29
  let fileExist = false;
24
30
  let dateTimeStamp = new Date().toISOString().slice(0, 10).concat(' ').concat(new Date().toLocaleTimeString('it-IT')).replace(/:\s*/g, '.');
@@ -86,7 +92,13 @@ const createByResourceType = async (client, defsManager, name, resourceType, res
86
92
  if (!result.data) {
87
93
  var _result$error;
88
94
 
89
- throw Error(`Cannot create a new ${resourceType.toLowerCase()}${(_result$error = result.error) !== null && _result$error !== void 0 && _result$error.length ? `: ${result.error[0].detail}` : '.'}`);
95
+ const errMsg = `cannot create a new ${resourceType.toLowerCase()}`;
96
+
97
+ if ((_result$error = result.error) !== null && _result$error !== void 0 && _result$error.length) {
98
+ throw Error(`${errMsg}: ${result.error[0].detail}.`);
99
+ } else {
100
+ throw Error(`${errMsg}.`);
101
+ }
90
102
  } else {
91
103
  console.log(`New ${resourceType.toLowerCase()} "${result.data.name}" has been successfully created.`);
92
104
  }
@@ -96,41 +108,167 @@ const createByResourceType = async (client, defsManager, name, resourceType, res
96
108
 
97
109
  exports.createByResourceType = createByResourceType;
98
110
 
99
- const createNewAgentResource = async (client, defsManager, envName, dataPlaneType, agentResource, agentType, owningTeam, agentName) => {
111
+ const createNewAgentResource = async (client, defsManager, envName, dataPlaneType, agentResource, agentType, owningTeam, agentName, dataPlaneName, frequency, queue) => {
100
112
  console.log(`Creating a new ${agentResource}, with data plane type: ${dataPlaneType}.`); // NOTE: only a first found set is used
101
113
 
102
114
  const defs = defsManager.findDefsByWord(agentType);
103
115
 
104
116
  if (!defs) {
105
117
  throw Error(`the server doesn't have a resource type "${agentType}"`);
118
+ } // create the dataplane object
119
+
120
+
121
+ let withSubResources = false;
122
+ let dataplane = {};
123
+
124
+ if (dataPlaneName) {
125
+ dataplane.name = dataPlaneName;
126
+ withSubResources = true;
127
+ }
128
+
129
+ if (frequency) {
130
+ dataplane.frequency = frequency;
131
+ }
132
+
133
+ if (queue) {
134
+ dataplane.queueDiscovery = queue;
106
135
  }
107
136
 
108
137
  const result = await client.createResource({
109
138
  // @ts-ignore payload
110
139
  resource: {
111
- name: agentName,
140
+ title: agentName,
112
141
  spec: {
113
142
  dataplaneType: dataPlaneType,
114
143
  config: {
115
144
  owningTeam: owningTeam
116
145
  }
117
- }
146
+ },
147
+ dataplane: dataplane
118
148
  },
119
149
  resourceDef: defs[0].resource,
120
150
  scopeDef: defs[0].scope ? defs[0].scope : undefined,
121
- scopeName: envName
151
+ scopeName: envName,
152
+ withSubResources: withSubResources
122
153
  });
123
154
 
124
155
  if (!result.data) {
125
156
  var _result$error2;
126
157
 
127
- throw Error(`Cannot create a new agent ${(_result$error2 = result.error) !== null && _result$error2 !== void 0 && _result$error2.length ? `: ${result.error[0].detail}` : '.'}`);
158
+ const errMsg = `cannot create a new agent`;
159
+
160
+ if ((_result$error2 = result.error) !== null && _result$error2 !== void 0 && _result$error2.length) {
161
+ throw Error(`${errMsg}: ${result.error[0].detail}.`);
162
+ } else {
163
+ throw Error(`${errMsg}.`);
164
+ }
128
165
  } else {
129
166
  console.log(`New agent of type "${defs[0].resource.name}" named "${result.data.name}" has been successfully created.`);
130
167
  }
131
168
 
132
169
  return result.data.name;
133
170
  };
171
+ /**
172
+ * @description Helper func to create a new DataPlane resource
173
+ * @param client API Service Client
174
+ * @param defsManager Definition Manager
175
+ * @param envName Environment Name
176
+ * @param dataPlaneType DataPlane Type
177
+ */
178
+
179
+
180
+ exports.createNewAgentResource = createNewAgentResource;
181
+
182
+ const createNewDataPlaneResource = async (client, defsManager, envName, dataPlaneType) => {
183
+ console.log(`Creating a new Dataplane resource, with type: ${dataPlaneType}.`); // NOTE: only a first found set is used
184
+
185
+ const defs = defsManager.findDefsByWord("dp");
186
+
187
+ if (!defs) {
188
+ throw Error(`the server doesn't have a resource type "Dataplane"`);
189
+ }
190
+
191
+ const result = await client.createResource({
192
+ // @ts-ignore payload
193
+ resource: {
194
+ title: dataPlaneType + " Dataplane",
195
+ spec: {
196
+ type: dataPlaneType
197
+ }
198
+ },
199
+ resourceDef: defs[0].resource,
200
+ scopeDef: defs[0].scope ? defs[0].scope : undefined,
201
+ scopeName: envName
202
+ });
203
+
204
+ if (!result.data) {
205
+ var _result$error3;
206
+
207
+ const errMsg = `cannot create a new dataplane`;
208
+
209
+ if ((_result$error3 = result.error) !== null && _result$error3 !== void 0 && _result$error3.length) {
210
+ throw Error(`${errMsg}: ${result.error[0].detail}.`);
211
+ } else {
212
+ throw Error(`${errMsg}.`);
213
+ }
214
+ } else {
215
+ console.log(`New dataplane of type "${defs[0].resource.name}" named "${result.data.name}" has been successfully created.`);
216
+ }
217
+
218
+ return result.data;
219
+ };
220
+ /**
221
+ * @description Helper func to create a new DataPlane resource
222
+ * @param client API Service Client
223
+ * @param defsManager Definition Manager
224
+ * @param envName Environment Name
225
+ * @param dataPlaneName DataPlane Name
226
+ * @param accessData Encrypted Access Data
227
+ */
228
+
229
+
230
+ exports.createNewDataPlaneResource = createNewDataPlaneResource;
231
+
232
+ const createNewDataPlaneSecretResource = async (client, defsManager, envName, dataPlaneType, dataPlaneName, accessData) => {
233
+ console.log(`Creating a new DataplaneSecret resource.`); // NOTE: only a first found set is used
234
+
235
+ const defs = defsManager.findDefsByWord("dps");
236
+
237
+ if (!defs) {
238
+ throw Error(`the server doesn't have a resource type "DataplaneSecret"`);
239
+ }
240
+
241
+ const result = await client.createResource({
242
+ // @ts-ignore payload
243
+ resource: {
244
+ title: dataPlaneType + " Dataplane Secret",
245
+ spec: {
246
+ dataplane: dataPlaneName,
247
+ data: accessData
248
+ }
249
+ },
250
+ resourceDef: defs[0].resource,
251
+ scopeDef: defs[0].scope ? defs[0].scope : undefined,
252
+ scopeName: envName
253
+ });
254
+ log(result);
255
+
256
+ if (!result.data) {
257
+ var _result$error4;
258
+
259
+ const errMsg = `cannot create a new agent`;
260
+
261
+ if ((_result$error4 = result.error) !== null && _result$error4 !== void 0 && _result$error4.length) {
262
+ throw Error(`${errMsg}: ${result.error[0].detail}.`);
263
+ } else {
264
+ throw Error(`${errMsg}.`);
265
+ }
266
+ } else {
267
+ console.log(`New secret of type "${defs[0].resource.name}" named "${result.data.name}" has been successfully created.`);
268
+ }
269
+
270
+ return result.data;
271
+ };
134
272
  /**
135
273
  * @description Helper func to check for existing secret, and clean up old secret before creating a new one.
136
274
  * @param namespace Namespace to create the secret in.
@@ -139,7 +277,7 @@ const createNewAgentResource = async (client, defsManager, envName, dataPlaneTyp
139
277
  */
140
278
 
141
279
 
142
- exports.createNewAgentResource = createNewAgentResource;
280
+ exports.createNewDataPlaneSecretResource = createNewDataPlaneSecretResource;
143
281
 
144
282
  const createSecret = async (namespace, secretName, createFunc) => {
145
283
  const secrets = await _Kubectl.kubectl.get('secrets', `-n ${namespace} ${secretName}`); // NotFound errors are ok. Throw an error for anything else.
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.deleteByResourceType = void 0;
7
+
8
+ var _chalk = _interopRequireDefault(require("chalk"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ const deleteByResourceType = async (client, defsManager, name, resourceType, resourceShortName, scopeName = '') => {
13
+ console.log(`Creating a new ${resourceType}`); // NOTE: only a first found set is used
14
+
15
+ const defs = defsManager.findDefsByWord(resourceShortName);
16
+
17
+ if (!defs) {
18
+ throw Error(`the server doesn't have a resource type "${resourceType}"`);
19
+ }
20
+
21
+ const result = await client.deleteResourceByName({
22
+ // @ts-ignore resource is not important for the test`
23
+ resourceName: name,
24
+ // @ts-ignore resourceDef is not important for the test
25
+ resourceDef: defs[0].resource,
26
+ scopeDef: defs[0].scope ? defs[0].scope : undefined,
27
+ scopeName: defs[0].scope ? scopeName || name : undefined
28
+ });
29
+
30
+ if (!result.data) {
31
+ var _result$error;
32
+
33
+ const errMsg = `error deleting resource ${resourceType.toLowerCase()}`;
34
+
35
+ if ((_result$error = result.error) !== null && _result$error !== void 0 && _result$error.length) {
36
+ console.log(_chalk.default.redBright(`${errMsg}: ${result.error[0].detail}.`));
37
+ } else {
38
+ console.log(_chalk.default.redBright(`${errMsg}.`));
39
+ }
40
+ } else {
41
+ console.log(`New ${resourceType.toLowerCase()} "${result.data.name}" has been successfully deleted.`);
42
+ }
43
+ };
44
+
45
+ exports.deleteByResourceType = deleteByResourceType;
@@ -24,6 +24,20 @@ var _stream = _interopRequireDefault(require("stream"));
24
24
 
25
25
  var _util = _interopRequireDefault(require("util"));
26
26
 
27
+ var _deleters = require("./deleters");
28
+
29
+ Object.keys(_deleters).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
32
+ if (key in exports && exports[key] === _deleters[key]) return;
33
+ Object.defineProperty(exports, key, {
34
+ enumerable: true,
35
+ get: function () {
36
+ return _deleters[key];
37
+ }
38
+ });
39
+ });
40
+
27
41
  var _creators = require("./creators");
28
42
 
29
43
  Object.keys(_creators).forEach(function (key) {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.transactionLoggingMessages = exports.serviceAccountNameAlreadyExists = exports.selectServiceAccount = exports.selectIngestionProtocol = exports.secretAlreadyExists = exports.namespaceAlreadyExists = exports.k8sClusterMessages = exports.envMessages = exports.enterServiceAccountName = exports.enterPublicKeyPath = exports.enterPrivateKeyPath = exports.enterNamespaceName = exports.createNamespace = exports.createGatewayAgentCredsSecret = exports.createAmplifyAgentKeysSecret = exports.askToEnableTransactionLogging = exports.askServiceAccountName = exports.askPublicKeyPath = exports.askPublicAndPrivateKeysPath = exports.askPrivateKeyPath = exports.askNamespace = exports.askK8sClusterName = exports.askIngestionProtocol = exports.askForSecretName = exports.askEnvironmentName = exports.askDosaClientId = exports.askBundleType = exports.askAgentName = exports.agentMessages = void 0;
6
+ exports.transactionLoggingMessages = exports.serviceAccountNameAlreadyExists = exports.selectServiceAccount = exports.selectIngestionProtocol = exports.selectAWSRegion = exports.secretAlreadyExists = exports.namespaceAlreadyExists = exports.k8sClusterMessages = exports.envMessages = exports.enterServiceAccountName = exports.enterPublicKeyPath = exports.enterPrivateKeyPath = exports.enterNamespaceName = exports.enterAWSRegion = exports.createNamespace = exports.createGatewayAgentCredsSecret = exports.createAmplifyAgentKeysSecret = exports.askToEnableTransactionLogging = exports.askServiceAccountName = exports.askPublicKeyPath = exports.askPublicAndPrivateKeysPath = exports.askPrivateKeyPath = exports.askNamespace = exports.askK8sClusterName = exports.askIngestionProtocol = exports.askForSecretName = exports.askEnvironmentName = exports.askDosaClientId = exports.askBundleType = exports.askAgentName = exports.askAWSRegion = exports.agentMessages = void 0;
7
7
 
8
8
  var _chalk = _interopRequireDefault(require("chalk"));
9
9
 
@@ -75,6 +75,35 @@ const selectIngestionProtocol = 'Select Traceability protocol';
75
75
  exports.selectIngestionProtocol = selectIngestionProtocol;
76
76
  const serviceAccountNameAlreadyExists = 'Service account already exists. Please enter a new name.';
77
77
  exports.serviceAccountNameAlreadyExists = serviceAccountNameAlreadyExists;
78
+ const selectAWSRegion = 'Select an AWS Region';
79
+ exports.selectAWSRegion = selectAWSRegion;
80
+ const enterAWSRegion = 'Enter an AWS Region';
81
+ exports.enterAWSRegion = enterAWSRegion;
82
+
83
+ const askAWSRegion = async (region = '') => {
84
+ let regions = Object.values(_types.AWSRegions).map(str => ({
85
+ name: str,
86
+ value: str
87
+ }));
88
+ let answer = await (0, _basicPrompts.askList)({
89
+ msg: selectAWSRegion,
90
+ default: region,
91
+ choices: [{
92
+ name: 'Enter an AWS Region not on the list',
93
+ value: 'CREATE_NEW'
94
+ }, ...regions]
95
+ });
96
+
97
+ if (answer === 'CREATE_NEW') {
98
+ return await (0, _basicPrompts.askInput)({
99
+ msg: enterAWSRegion
100
+ });
101
+ } else {
102
+ return answer;
103
+ }
104
+ };
105
+
106
+ exports.askAWSRegion = askAWSRegion;
78
107
 
79
108
  const askServiceAccountName = async serviceAccountNames => {
80
109
  console.warn(_chalk.default.yellow(`WARNING: Creating a new service account will overwrite any existing "private_key.pem" and "public_key.pem" files in this directory`));
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.resourceRegex = exports.percentageRegex = exports.namespaceRegex = exports.invalidResourceMsg = exports.invalidPercentage = exports.invalidNamespace = exports.invalidDosaName = exports.invalidDomainName = exports.dosaRegex = exports.domainNameRegex = exports.AzureRegexPatterns = exports.AWSRegexPatterns = void 0;
6
+ exports.resourceRegex = exports.percentageRegex = exports.namespaceRegex = exports.invalidResourceMsg = exports.invalidPercentage = exports.invalidNamespace = exports.invalidDosaName = exports.invalidDomainName = exports.frequencyRegex = exports.dosaRegex = exports.domainNameRegex = exports.AzureRegexPatterns = exports.AWSRegexPatterns = void 0;
7
7
  const resourceRegex = '^(?:[a-z0-9]*(?:\\.(?=[a-z0-9])|-+(?=[a-z0-9]))?)+[a-z0-9]$';
8
8
  exports.resourceRegex = resourceRegex;
9
9
  const namespaceRegex = '^[a-z0-9]?(?:[-a-z0-9]*[a-z0-9]){1,100}?$';
@@ -14,6 +14,8 @@ const dosaRegex = '^[\\w\\s-()[\\]]{1,100}$';
14
14
  exports.dosaRegex = dosaRegex;
15
15
  const percentageRegex = '^[1-9][0-9]?$|^100$';
16
16
  exports.percentageRegex = percentageRegex;
17
+ const frequencyRegex = '^(\\d*[d])?(\\d*[h])?(\\d*[m])?$|^$';
18
+ exports.frequencyRegex = frequencyRegex;
17
19
  const invalidPercentage = 'Percentage must be an integer between 1-100';
18
20
  exports.invalidPercentage = invalidPercentage;
19
21
  const invalidDosaName = 'Account name can contain A-z 0-9 _ - ( ) [ ] and can include 1-100 characters.';
@@ -35,7 +37,10 @@ const AWSRegexPatterns = {
35
37
  AWS_REGEXP_VPC_ID: '^vpc-[0-9a-z]*$|^$',
36
38
  AWS_REGEXP_SECURITY_GROUP: '^sg-[0-9a-z]*$|^$',
37
39
  AWS_REGEXP_SUBNET: '^subnet-[0-9a-z]*$|^$',
38
- AWS_REGEXP_SSH_LOCATION: '^\\d{1,3}(\\.\\d{1,3}){3}\\/\\d{1,2}$'
40
+ AWS_REGEXP_SSH_LOCATION: '^\\d{1,3}(\\.\\d{1,3}){3}\\/\\d{1,2}$',
41
+ AWS_REGEXP_ACCESS_KEY_ID: '((?:ASIA|AKIA|AROA|AIDA)([A-Z0-7]{16}))',
42
+ AWS_REGEXP_SECRET_ACCESS_KEY: '([a-zA-Z0-9+/]{40})',
43
+ AWS_REGEXP_ROLE_ARN: '^arn:(aws[a-zA-Z-]*)?:iam::\\d{12}:role\\/?[a-zA-Z_0-9+=,.@\\-_\\/]{1,128}$'
39
44
  }; // AzureRegexPatterns - regex patters to validate user inputs
40
45
 
41
46
  exports.AWSRegexPatterns = AWSRegexPatterns;
@@ -108,14 +108,14 @@ const getCentralConfig = async (apiServerClient, platformClient, defsManager, ap
108
108
  isNew: false
109
109
  };
110
110
 
111
- if (installConfig.bundleType !== _types.BundleType.TRACEABILITY_OFFLINE) {
111
+ if (installConfig.bundleType !== _types.BundleType.TRACEABILITY_OFFLINE && !installConfig.switches.isHostedInstall) {
112
112
  centralConfig.ampcDosaInfo = await helpers.askDosaClientId(platformClient);
113
113
  } // Get the DA Agent name
114
114
 
115
115
 
116
116
  centralConfig.daAgentName = ''; // Istio will not prompt for agent name. Remove when that ability exists
117
117
 
118
- if (installConfig.switches.isDaEnabled) {
118
+ if (installConfig.switches.isDaEnabled && !installConfig.switches.isHostedInstall) {
119
119
  centralConfig.daAgentName = await helpers.askAgentName(apiServerClient, defsManager, _types.AgentTypes.da, centralConfig.ampcEnvInfo.name);
120
120
  } // Get the TA Agent name
121
121
 
@@ -0,0 +1,281 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.testables = exports.AWSSaaSInstallMethods = void 0;
7
+
8
+ var _chalk = _interopRequireDefault(require("chalk"));
9
+
10
+ var _snooplogg = _interopRequireDefault(require("snooplogg"));
11
+
12
+ var _basicPrompts = require("../../common/basicPrompts");
13
+
14
+ var _types = require("../../common/types");
15
+
16
+ var helpers = _interopRequireWildcard(require("./helpers"));
17
+
18
+ var _crypto = _interopRequireDefault(require("crypto"));
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
+
24
+ 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
+
28
+ const {
29
+ log
30
+ } = (0, _snooplogg.default)('central: install: agents: saas');
31
+
32
+ class SaasAgentValues {
33
+ constructor() {
34
+ _defineProperty(this, "frequency", void 0);
35
+
36
+ _defineProperty(this, "queue", void 0);
37
+
38
+ _defineProperty(this, "centralConfig", void 0);
39
+
40
+ this.frequency = '';
41
+ this.queue = false;
42
+ this.centralConfig = new _types.CentralAgentConfig();
43
+ }
44
+
45
+ getAccessData() {
46
+ return "";
47
+ }
48
+
49
+ }
50
+
51
+ class SaasAWSAgentValues extends SaasAgentValues {
52
+ constructor() {
53
+ super();
54
+
55
+ _defineProperty(this, "authType", void 0);
56
+
57
+ _defineProperty(this, "accessKey", void 0);
58
+
59
+ _defineProperty(this, "secretKey", void 0);
60
+
61
+ _defineProperty(this, "region", void 0);
62
+
63
+ _defineProperty(this, "assumeRole", void 0);
64
+
65
+ _defineProperty(this, "externalID", void 0);
66
+
67
+ this.authType = AWSAuthType.ASSUME;
68
+ this.accessKey = '';
69
+ this.secretKey = '';
70
+ this.region = '';
71
+ this.assumeRole = '';
72
+ this.externalID = '';
73
+ }
74
+
75
+ getAccessData() {
76
+ let data = JSON.stringify({
77
+ region: this.region,
78
+ roleARN: this.assumeRole,
79
+ externalID: this.externalID
80
+ });
81
+
82
+ if (this.authType == AWSAuthType.KEYS) {
83
+ data = JSON.stringify({
84
+ region: this.region,
85
+ accessKeyID: this.accessKey,
86
+ secretAccessKey: this.secretKey
87
+ });
88
+ }
89
+
90
+ return data;
91
+ }
92
+
93
+ } // ConfigFiles - all the config file that are used in the setup
94
+
95
+
96
+ const ConfigFiles = {}; // AWSAuthType - how the agent will authenticate to AWS
97
+
98
+ var AWSAuthType; // AWSSaaSPrompts - all AWS Saas prompts to the user for input
99
+
100
+ (function (AWSAuthType) {
101
+ AWSAuthType["ASSUME"] = "AssumeRole Policy";
102
+ AWSAuthType["KEYS"] = "Access and Secret Keys";
103
+ })(AWSAuthType || (AWSAuthType = {}));
104
+
105
+ const SaasPrompts = {
106
+ AUTHENTICATION_TYPE: 'Authenticate with an AssumeRole Policy or an Access Key ID and Secret Access Key',
107
+ ACCESS_KEY: 'Enter the AWS Access Key ID the agent will use',
108
+ SECRET_KEY: 'Enter the AWS Secret Access Key the agent will use',
109
+ ASSUME_ROLE: 'Enter the role ARN that the agent will Assume',
110
+ EXTERNAL_ID: 'Enter the external ID the Assume Role expects',
111
+ FREQUENCY: 'How often should the discovery run, leave blank for integrating in CI/CD process',
112
+ QUEUE: 'Do you want to run the agent immediately during install'
113
+ };
114
+
115
+ const askBundleType = async () => {
116
+ return _types.BundleType.DISCOVERY;
117
+ };
118
+
119
+ const askConfigType = async () => {
120
+ return _types.AgentConfigTypes.HOSTED;
121
+ }; //
122
+ // Complex prompts
123
+ //
124
+
125
+
126
+ const askForAWSCredentials = async hostedAgentValues => {
127
+ hostedAgentValues.region = await helpers.askAWSRegion();
128
+ log("gathering access details for aws"); // Ask Auth type
129
+
130
+ hostedAgentValues.authType = await (0, _basicPrompts.askList)({
131
+ msg: SaasPrompts.AUTHENTICATION_TYPE,
132
+ default: AWSAuthType.ASSUME,
133
+ choices: [{
134
+ name: AWSAuthType.ASSUME,
135
+ value: AWSAuthType.ASSUME
136
+ }, {
137
+ name: AWSAuthType.KEYS,
138
+ value: AWSAuthType.KEYS
139
+ }]
140
+ });
141
+ console.log(_chalk.default.blue("Please refer to docs.axway.com for information on creating the necessary AWS IAM policies"));
142
+
143
+ if (hostedAgentValues.authType === AWSAuthType.ASSUME) {
144
+ log("using an assume role policy authentication"); // get assume role arn
145
+
146
+ hostedAgentValues.assumeRole = await (0, _basicPrompts.askInput)({
147
+ msg: SaasPrompts.ASSUME_ROLE,
148
+ defaultValue: hostedAgentValues.assumeRole !== '' ? hostedAgentValues.assumeRole : undefined,
149
+ validate: (0, _basicPrompts.validateRegex)(helpers.AWSRegexPatterns.AWS_REGEXP_ROLE_ARN, helpers.invalidValueExampleErrMsg('assume role arn', 'arn:aws:iam::000000000000:role/name-of-role'))
150
+ }); // get external id
151
+
152
+ hostedAgentValues.externalID = await (0, _basicPrompts.askInput)({
153
+ msg: SaasPrompts.EXTERNAL_ID,
154
+ defaultValue: hostedAgentValues.externalID !== '' ? hostedAgentValues.externalID : undefined
155
+ });
156
+ } else {
157
+ log("using key and secret authentication"); // get access key
158
+
159
+ hostedAgentValues.accessKey = await (0, _basicPrompts.askInput)({
160
+ msg: SaasPrompts.ACCESS_KEY,
161
+ defaultValue: hostedAgentValues.accessKey !== '' ? hostedAgentValues.accessKey : undefined,
162
+ validate: (0, _basicPrompts.validateRegex)(helpers.AWSRegexPatterns.AWS_REGEXP_ACCESS_KEY_ID, helpers.invalidValueExampleErrMsg('access key id', 'AKIAIOSFODNN7EXAMPLE'))
163
+ }); // get secret access key
164
+
165
+ hostedAgentValues.secretKey = await (0, _basicPrompts.askInput)({
166
+ msg: SaasPrompts.SECRET_KEY,
167
+ defaultValue: hostedAgentValues.secretKey !== '' ? hostedAgentValues.secretKey : undefined,
168
+ validate: (0, _basicPrompts.validateRegex)(helpers.AWSRegexPatterns.AWS_REGEXP_SECRET_ACCESS_KEY, helpers.invalidValueExampleErrMsg('secret access key', 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY'))
169
+ });
170
+ }
171
+
172
+ return hostedAgentValues;
173
+ }; // @ts-ignore
174
+
175
+
176
+ const gatewayConnectivity = async installConfig => {
177
+ console.log('\nCONNECTION TO AMAZON API GATEWAY:');
178
+ console.log(_chalk.default.gray(`The Discovery Agent needs to connect to the AWS API Gateway to discover API's for publishing to Amplify Central`)); // DeploymentType
179
+
180
+ let hostedAgentValues = new SaasAgentValues();
181
+
182
+ if (installConfig.gatewayType === _types.GatewayTypes.AWS_GATEWAY) {
183
+ // AWS connection details
184
+ hostedAgentValues = new SaasAWSAgentValues();
185
+ hostedAgentValues = await askForAWSCredentials(hostedAgentValues);
186
+ } // Ask to queue discovery now
187
+
188
+
189
+ log("getting the frequency and if the agent should run now");
190
+ console.log(_chalk.default.gray(`XXdXXhXXm format, where 30m = 30 minutes, 1h = 1 hour, 7d = 7 days, and 7d1h30m = 7 days 1 hour and 30 minutes`));
191
+ hostedAgentValues.frequency = await (0, _basicPrompts.askInput)({
192
+ msg: SaasPrompts.FREQUENCY,
193
+ validate: (0, _basicPrompts.validateRegex)(helpers.frequencyRegex, helpers.invalidValueExampleErrMsg('frequency', '3d5h12m')),
194
+ allowEmptyInput: true
195
+ });
196
+ hostedAgentValues.queue = (await (0, _basicPrompts.askList)({
197
+ msg: SaasPrompts.QUEUE,
198
+ default: _types.YesNo.No,
199
+ choices: _types.YesNoChoices
200
+ })) === _types.YesNo.Yes;
201
+ return hostedAgentValues;
202
+ };
203
+
204
+ const generateOutput = async installConfig => {
205
+ return `Install complete of hosted agent for ${installConfig.gatewayType} region`;
206
+ };
207
+
208
+ const createEncryptedAccessData = async (hostedAgentValues, dataplaneRes) => {
209
+ var _dataplaneRes$securit, _dataplaneRes$securit2;
210
+
211
+ // grab key from data plane resource
212
+ let key = ((_dataplaneRes$securit = dataplaneRes.security) === null || _dataplaneRes$securit === void 0 ? void 0 : _dataplaneRes$securit.encryptionKey) || "";
213
+ let hash = ((_dataplaneRes$securit2 = dataplaneRes.security) === null || _dataplaneRes$securit2 === void 0 ? void 0 : _dataplaneRes$securit2.encryptionHash) || "";
214
+
215
+ if (key === "" || hash === "") {
216
+ throw Error(`cannot encrypt access data as the encryption key info was incomplete`);
217
+ }
218
+
219
+ let encData = _crypto.default.publicEncrypt({
220
+ key: key,
221
+ padding: _crypto.default.constants.RSA_PKCS1_OAEP_PADDING,
222
+ oaepHash: hash
223
+ }, Buffer.from(hostedAgentValues.getAccessData()));
224
+
225
+ return encData.toString("base64");
226
+ };
227
+
228
+ const completeInstall = async (installConfig, apiServerClient, defsManager) => {
229
+ /**
230
+ * Create agent resources
231
+ */
232
+ let awsAgentValues = installConfig.gatewayConfig; // create the environment, if necessary
233
+
234
+ installConfig.centralConfig.environment = installConfig.centralConfig.ampcEnvInfo.isNew ? await helpers.createByResourceType(apiServerClient, defsManager, installConfig.centralConfig.ampcEnvInfo.name, 'Environment', 'env', {
235
+ axwayManaged: installConfig.centralConfig.axwayManaged,
236
+ production: installConfig.centralConfig.production
237
+ }) : installConfig.centralConfig.ampcEnvInfo.name; // create the data plane resource
238
+
239
+ let dataplaneRes = await helpers.createNewDataPlaneResource(apiServerClient, defsManager, installConfig.centralConfig.environment, _types.GatewayTypeToDataPlane[installConfig.gatewayType]); // create data plane secret resource
240
+
241
+ try {
242
+ await helpers.createNewDataPlaneSecretResource(apiServerClient, defsManager, installConfig.centralConfig.environment, _types.GatewayTypeToDataPlane[installConfig.gatewayType], dataplaneRes.name, await createEncryptedAccessData(awsAgentValues, dataplaneRes));
243
+ } catch (error) {
244
+ console.log(_chalk.default.redBright("rolling back installation. Please check the credential data before re-running install"));
245
+
246
+ if (installConfig.centralConfig.ampcEnvInfo.isNew) {
247
+ await helpers.deleteByResourceType(apiServerClient, defsManager, installConfig.centralConfig.ampcEnvInfo.name, 'Environment', 'env');
248
+ } else {
249
+ await helpers.deleteByResourceType(apiServerClient, defsManager, dataplaneRes.name, "Dataplane", "dp", installConfig.centralConfig.environment);
250
+ }
251
+
252
+ return;
253
+ } // create discovery agent resource
254
+
255
+
256
+ 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, awsAgentValues.frequency, awsAgentValues.queue);
257
+ console.log(await generateOutput(installConfig));
258
+ };
259
+
260
+ const AWSSaaSInstallMethods = {
261
+ GetBundleType: askBundleType,
262
+ GetDeploymentType: askConfigType,
263
+ AskGatewayQuestions: gatewayConnectivity,
264
+ FinalizeGatewayInstall: completeInstall,
265
+ ConfigFiles: [],
266
+ AgentNameMap: {
267
+ [_types.AgentTypes.da]: _types.AgentNames.AWS_DA,
268
+ [_types.AgentTypes.ta]: _types.AgentNames.AWS_TA
269
+ },
270
+ GatewayDisplay: _types.GatewayTypes.AWS_GATEWAY
271
+ }; // These are the items that are not exported, but need to be for testing
272
+
273
+ exports.AWSSaaSInstallMethods = AWSSaaSInstallMethods;
274
+ const testables = {
275
+ SaasAgentValues,
276
+ SaasAWSAgentValues,
277
+ AWSAuthType,
278
+ SaasPrompts,
279
+ ConfigFiles
280
+ };
281
+ exports.testables = testables;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.docsUrl = exports.commonCmdArgsDescription = exports.cliVersionHeader = exports.YesNoChoices = exports.YesNo = exports.WAIT_TIMEOUT = exports.TrueFalseChoices = exports.TrueFalse = exports.TraceabilityConfig = exports.SingleEntryPointUrls = exports.Regions = exports.PublicRepoUrl = exports.PublicDockerRepoBaseUrl = exports.Protocol = exports.ProdBaseUrls = exports.Platforms = exports.OutputTypes = exports.MAX_TABLE_STRING_LENGTH = exports.MAX_FILE_SIZE = exports.MAX_CACHE_FILE_SIZE = exports.LoggingSource = exports.KindTypes = exports.Kind = exports.IstioProfileChoices = exports.IstioInstallValues = exports.IstioAgentValues = exports.IngestionProtocolToHosts = exports.IngestionProtocol = exports.IngestionHostsHTTP = exports.IngestionHosts = exports.IngestionHTTPHosts = exports.GatewayTypes = exports.GatewayTypeToDataPlane = exports.GatewayMode = exports.EnvironmentConfigInfo = exports.DosaAccount = exports.DataPlaneNames = exports.DOSAConfigInfo = exports.ConfigTypes = exports.CloudFormationConfig = exports.Certificate = exports.CentralAgentConfig = exports.CACHE_FILE_TTL_MILLISECONDS = exports.BundleType = exports.BasePaths = exports.AuthUrls = exports.AgentTypes = exports.AgentResourceKind = exports.AgentNames = exports.AgentInstallSwitches = exports.AgentInstallConfig = exports.AgentConfigTypes = exports.APICDeployments = exports.ABORT_TIMEOUT = void 0;
6
+ exports.docsUrl = exports.commonCmdArgsDescription = exports.cliVersionHeader = exports.YesNoChoices = exports.YesNo = exports.WAIT_TIMEOUT = exports.TrueFalseChoices = exports.TrueFalse = exports.TraceabilityConfig = exports.SingleEntryPointUrls = exports.SaaSGatewayTypes = exports.Regions = exports.PublicRepoUrl = exports.PublicDockerRepoBaseUrl = exports.Protocol = exports.ProdBaseUrls = exports.Platforms = exports.OutputTypes = exports.MAX_TABLE_STRING_LENGTH = exports.MAX_FILE_SIZE = exports.MAX_CACHE_FILE_SIZE = exports.LoggingSource = exports.KindTypes = exports.Kind = exports.IstioProfileChoices = exports.IstioInstallValues = exports.IstioAgentValues = exports.IngestionProtocolToHosts = exports.IngestionProtocol = exports.IngestionHostsHTTP = exports.IngestionHosts = exports.IngestionHTTPHosts = exports.GatewayTypes = exports.GatewayTypeToDataPlane = exports.GatewayMode = exports.EnvironmentConfigInfo = exports.DosaAccount = exports.DataPlaneNames = exports.DOSAConfigInfo = exports.ConfigTypes = exports.CloudFormationConfig = exports.Certificate = exports.CentralAgentConfig = exports.CACHE_FILE_TTL_MILLISECONDS = exports.BundleType = exports.BasePaths = exports.AuthUrls = exports.AgentTypes = exports.AgentResourceKind = exports.AgentNames = exports.AgentInstallSwitches = exports.AgentInstallConfig = exports.AgentConfigTypes = exports.AWSRegions = exports.APICDeployments = exports.ABORT_TIMEOUT = void 0;
7
7
 
8
8
  var _dataService = require("./dataService");
9
9
 
@@ -244,6 +244,7 @@ let AgentConfigTypes;
244
244
  exports.AgentConfigTypes = AgentConfigTypes;
245
245
 
246
246
  (function (AgentConfigTypes) {
247
+ AgentConfigTypes["HOSTED"] = "Hosted";
247
248
  AgentConfigTypes["BINARIES"] = "Binaries";
248
249
  AgentConfigTypes["DOCKERIZED"] = "Dockerized";
249
250
  AgentConfigTypes["HELM"] = "Helm";
@@ -298,6 +299,13 @@ exports.GatewayTypes = GatewayTypes;
298
299
  GatewayTypes["EDGE_GATEWAY_ONLY"] = "Amplify API Gateway only";
299
300
  })(GatewayTypes || (exports.GatewayTypes = GatewayTypes = {}));
300
301
 
302
+ let SaaSGatewayTypes;
303
+ exports.SaaSGatewayTypes = SaaSGatewayTypes;
304
+
305
+ (function (SaaSGatewayTypes) {
306
+ SaaSGatewayTypes[SaaSGatewayTypes["AWS_GATEWAY"] = 0] = "AWS_GATEWAY";
307
+ })(SaaSGatewayTypes || (exports.SaaSGatewayTypes = SaaSGatewayTypes = {}));
308
+
301
309
  let DataPlaneNames;
302
310
  exports.DataPlaneNames = DataPlaneNames;
303
311
 
@@ -328,7 +336,8 @@ exports.AgentResourceKind = AgentResourceKind;
328
336
  AgentResourceKind["ta"] = "TraceabilityAgent";
329
337
  })(AgentResourceKind || (exports.AgentResourceKind = AgentResourceKind = {}));
330
338
 
331
- let AgentTypes;
339
+ let AgentTypes; // AWSRegions - base set of regions, may use option outside this list
340
+
332
341
  exports.AgentTypes = AgentTypes;
333
342
 
334
343
  (function (AgentTypes) {
@@ -336,6 +345,19 @@ exports.AgentTypes = AgentTypes;
336
345
  AgentTypes["ta"] = "ta";
337
346
  })(AgentTypes || (exports.AgentTypes = AgentTypes = {}));
338
347
 
348
+ let AWSRegions;
349
+ exports.AWSRegions = AWSRegions;
350
+
351
+ (function (AWSRegions) {
352
+ AWSRegions["US_EAST_1"] = "us-east-1";
353
+ AWSRegions["US_EAST_2"] = "us-east-2";
354
+ AWSRegions["US_WEST_1"] = "us-west-1";
355
+ AWSRegions["US_WEST_2"] = "us-west-2";
356
+ AWSRegions["EU_WEST_1"] = "eu-west-1";
357
+ AWSRegions["EU_WEST_2"] = "eu-west-2";
358
+ AWSRegions["EU_WEST_3"] = "eu-west-3";
359
+ })(AWSRegions || (exports.AWSRegions = AWSRegions = {}));
360
+
339
361
  class EnvironmentConfigInfo {
340
362
  constructor() {
341
363
  _defineProperty(this, "name", void 0);
@@ -442,6 +464,8 @@ class AgentInstallSwitches {
442
464
 
443
465
  _defineProperty(this, "isTaEnabled", void 0);
444
466
 
467
+ _defineProperty(this, "isHostedInstall", void 0);
468
+
445
469
  _defineProperty(this, "isHelmInstall", void 0);
446
470
 
447
471
  _defineProperty(this, "isGatewayOnly", void 0);
@@ -454,6 +478,7 @@ class AgentInstallSwitches {
454
478
 
455
479
  this.isDaEnabled = false;
456
480
  this.isTaEnabled = false;
481
+ this.isHostedInstall = false;
457
482
  this.isHelmInstall = false;
458
483
  this.isGatewayOnly = false;
459
484
  this.isDockerInstall = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axway/axway-central-cli",
3
- "version": "2.14.3",
3
+ "version": "2.15.0-rc.0",
4
4
  "description": "Manage APIs, services and publish to the Unified Catalog",
5
5
  "homepage": "https://platform.axway.com",
6
6
  "author": {
@@ -30,7 +30,8 @@
30
30
  "test:c": "yarn test:cov",
31
31
  "test:w": "yarn test -w --watch-extensions ts",
32
32
  "type-check": "tsc -p tsconfig.build.json",
33
- "start": "nodemon --watch src -e yaml,ts,js,json -i *.spec.ts --exec npm run build"
33
+ "start": "nodemon --watch src -e yaml,ts,js,json -i *.spec.ts --exec npm run build",
34
+ "sonar": "bash sonar.sh"
34
35
  },
35
36
  "main": "./dist/main.js",
36
37
  "amplify": {
@@ -41,7 +42,9 @@
41
42
  "name": "central"
42
43
  },
43
44
  "dependencies": {
44
- "@axway/amplify-cli-utils": "^5.0.10",
45
+ "@axway/amplify-cli-utils": "^5.0.11",
46
+ "@sideway/formula": "^3.0.1",
47
+ "@xmldom/xmldom": "^0.8.7",
45
48
  "chalk": "^4.1.2",
46
49
  "cli-kit": "^1.16.0",
47
50
  "dayjs": "^1.11.2",
@@ -50,11 +53,14 @@
50
53
  "form-data": "^4.0.0",
51
54
  "fs-extra": "^10.1.0",
52
55
  "handlebars": "^4.7.7",
56
+ "http-cache-semantics": "^4.1.1",
53
57
  "inquirer": "^8.2.4",
54
58
  "js-yaml": "^4.1.0",
59
+ "json5": "^2.2.3",
55
60
  "lodash": "^4.17.21",
56
61
  "node-cache": "^5.1.2",
57
- "npm-check-updates": "^12.5.12",
62
+ "npm": "^9.6.4",
63
+ "npm-check-updates": "^16.10.8",
58
64
  "ora": "^5.4.1",
59
65
  "promise-limit": "^2.7.0",
60
66
  "semver": "^7.3.7",
@@ -77,23 +83,23 @@
77
83
  "@types/js-yaml": "^4.0.5",
78
84
  "@types/lodash": "^4.14.182",
79
85
  "@types/mocha": "^9.1.1",
80
- "@types/node": "^17.0.23",
86
+ "@types/node": "^18.15.11",
81
87
  "@types/rx": "^4.1.2",
82
88
  "@types/semver": "^7.3.10",
83
- "@types/sinon": "^10.0.11",
89
+ "@types/sinon": "^10.0.14",
84
90
  "@types/tmp": "^0.2.3",
85
- "@types/update-notifier": "^5.1.0",
91
+ "@types/update-notifier": "^6.0.2",
86
92
  "@types/uuid": "^8.3.4",
87
93
  "babel-plugin-lodash": "^3.3.4",
88
- "chai": "^4.3.6",
94
+ "chai": "^4.3.7",
89
95
  "chai-as-promised": "^7.1.1",
90
96
  "core-js": "^3.22.8",
91
97
  "mocha": "^9.2.2",
92
- "nock": "^13.2.4",
98
+ "nock": "^13.3.0",
93
99
  "nodemon": "^2.0.18",
94
100
  "nyc": "^15.1.0",
95
101
  "prettier": "^2.6.2",
96
- "sinon": "^11.1.2",
102
+ "sinon": "^15.0.3",
97
103
  "source-map-support": "^0.5.21",
98
104
  "ts-mocha": "^10.0.0",
99
105
  "typescript": "^4.7.2"