@axway/axway-central-cli 2.3.0-rc.4 → 2.5.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.
@@ -9,16 +9,14 @@ var _cliKit = require("cli-kit");
9
9
 
10
10
  var _snooplogg = _interopRequireDefault(require("snooplogg"));
11
11
 
12
- var _ora = _interopRequireDefault(require("ora"));
13
-
14
- var _TmpFile = _interopRequireDefault(require("../../common/TmpFile"));
15
-
16
12
  var _dataService = require("../../common/dataService");
17
13
 
18
- var _errorHandler = require("../../common/errorHandler");
14
+ var _Renderer = _interopRequireDefault(require("../../common/Renderer"));
19
15
 
20
16
  var _resultsRenderers = require("../../common/resultsRenderers");
21
17
 
18
+ var _TmpFile = _interopRequireDefault(require("../../common/TmpFile"));
19
+
22
20
  var _utils = require("../../common/utils");
23
21
 
24
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -33,28 +31,26 @@ const action = async ({
33
31
  }) => {
34
32
  const {
35
33
  baseUrl,
36
- clientId,
34
+ account,
37
35
  name,
38
36
  output,
39
37
  region
40
38
  } = argv;
41
39
  log(`editing ${name} env`);
42
40
  let file;
43
- const spinner = process.env['DEBUG'] || !!output ? null : (0, _ora.default)({
44
- spinner: 'dots3',
45
- text: `Fetching details of "environment/${name}".`
46
- }).start();
41
+ let commandIsSuccessful = true;
42
+ const render = new _Renderer.default(console, output).startSpin(`Fetching details of "environment/${name}".`);
47
43
 
48
44
  try {
49
45
  const service = await (0, _dataService.dataService)({
50
46
  baseUrl,
51
- clientId,
47
+ account,
52
48
  region
53
49
  });
54
50
  let response = await service.get(`/management/v1alpha1/environments/${name}`);
55
51
  file = new _TmpFile.default(response); // stop spinner or it will interfere stdio of editor
56
52
 
57
- spinner && spinner.stop();
53
+ render.stopSpin();
58
54
  const {
59
55
  isUpdated
60
56
  } = await file.edit();
@@ -63,22 +59,25 @@ const action = async ({
63
59
  // intentionally taking just first doc even if user will provide more in the same file while editing.
64
60
  const doc = (0, _utils.LEGACY_loadAndVerifySpecs)(file.path)[0];
65
61
  response = await service.put(`/management/v1alpha1/environments/${name}`, doc);
66
- spinner && spinner.succeed((0, _cliKit.chalk)`{greenBright "environment/${name}" has successfully been edited.}`); // render result if output flag has been provided
62
+ render.success((0, _cliKit.chalk)`{greenBright "environment/${name}" has successfully been edited.}`); // render result if output flag has been provided
67
63
 
68
64
  output && (0, _resultsRenderers.renderResponse)(console, response, output);
69
65
  } else {
70
66
  log('no changes has been made to file');
71
- spinner && spinner.warn((0, _cliKit.chalk)`{yellow Edit cancelled, no changes made.}`);
67
+ render.error('Edit cancelled, no changes made.');
72
68
  file.delete();
69
+ commandIsSuccessful = false;
73
70
  }
74
71
  } catch (e) {
75
72
  log('command error', e);
76
73
  file && console.log(`A copy of your changes has been stored to "${file.path}".`);
77
- (0, _errorHandler.handleErrors)(console, e, spinner);
74
+ render.anyError(e);
75
+ commandIsSuccessful = false;
78
76
  } finally {
79
- log('command successful');
80
- file && file.delete();
81
- spinner && spinner.stop();
77
+ log(`command finished, success = ${commandIsSuccessful}`);
78
+ file && commandIsSuccessful && file.delete();
79
+ render.stopSpin();
80
+ !commandIsSuccessful && process.exit(1);
82
81
  }
83
82
  };
84
83
 
@@ -49,7 +49,7 @@ const get = {
49
49
  attribute,
50
50
  baseUrl,
51
51
  cache,
52
- clientId,
52
+ account,
53
53
  region,
54
54
  tag,
55
55
  title
@@ -65,7 +65,12 @@ const get = {
65
65
 
66
66
  try {
67
67
  // get specs and allowed words
68
- const client = new _ApiServerClient.ApiServerClient(baseUrl, clientId, region, cache);
68
+ const client = new _ApiServerClient.ApiServerClient({
69
+ baseUrl,
70
+ account,
71
+ region,
72
+ useCache: cache
73
+ });
69
74
  const defsManager = await new _DefinitionsManager.DefinitionsManager(client).init();
70
75
  const scope = (0, _utils.parseScopeParam)(argv.scope);
71
76
  const formattedFilter = (0, _utils.transformSimpleFilters)(title, attribute, tag);
@@ -74,7 +74,7 @@ const agents = {
74
74
  }) {
75
75
  const {
76
76
  baseUrl,
77
- clientId,
77
+ account,
78
78
  region,
79
79
  apicDeployment,
80
80
  cache,
@@ -85,9 +85,22 @@ const agents = {
85
85
 
86
86
  try {
87
87
  // initiate clients
88
- const apiCentralClient = new _ApiCentralClient.ApiCentralClient(baseUrl, clientId, region);
89
- const apiServerClient = new _ApiServerClient.ApiServerClient(baseUrl, clientId, region, cache);
90
- const platformClient = new _PlatformClient.PlatformClient(baseUrl, clientId, region);
88
+ const apiCentralClient = new _ApiCentralClient.ApiCentralClient({
89
+ baseUrl,
90
+ account,
91
+ region
92
+ });
93
+ const apiServerClient = new _ApiServerClient.ApiServerClient({
94
+ baseUrl,
95
+ account,
96
+ region,
97
+ useCache: cache
98
+ });
99
+ const platformClient = new _PlatformClient.PlatformClient({
100
+ baseUrl,
101
+ account,
102
+ region
103
+ });
91
104
  const defsManager = await new _DefinitionsManager.DefinitionsManager(apiServerClient).init(); // helper text
92
105
 
93
106
  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`));
@@ -19,19 +19,19 @@ const {
19
19
  log
20
20
  } = (0, _snooplogg.default)('central: install: agents: helpers');
21
21
 
22
- const getListByResource = async (client, defsManager, resourceType, resourceShortName, scopeName = '', query = '') => {
22
+ const getListByResource = async input => {
23
23
  // NOTE: only a first found set is used
24
- const defs = defsManager.findDefsByWord(resourceShortName);
24
+ const defs = input.defsManager.findDefsByWord(input.resourceShortName);
25
25
 
26
26
  if (!defs) {
27
- throw Error(`the server doesn't have a resource type "${resourceType}"`);
27
+ throw Error(`the server doesn't have a resource type "${input.resourceType}"`);
28
28
  }
29
29
 
30
- return client.getResourcesList({
30
+ return input.client.getResourcesList({
31
31
  resourceDef: defs[0].resource,
32
32
  scopeDef: defs[0].scope ? defs[0].scope : undefined,
33
- scopeName: scopeName ? scopeName : undefined,
34
- query: query
33
+ scopeName: input.scopeName,
34
+ query: input.query
35
35
  });
36
36
  }; // Note: forcing it to use apicentral client id
37
37
 
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.transactionLoggingMessages = 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.secretAlreadyExists = exports.namespaceAlreadyExists = exports.k8sClusterMessages = exports.fetchServiceAccount = 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;
7
7
 
8
8
  var _chalk = _interopRequireDefault(require("chalk"));
9
9
 
@@ -71,39 +71,50 @@ const enterPrivateKeyPath = 'Enter the file path to the private key';
71
71
  exports.enterPrivateKeyPath = enterPrivateKeyPath;
72
72
  const selectIngestionProtocol = 'Select Traceability protocol';
73
73
  exports.selectIngestionProtocol = selectIngestionProtocol;
74
+ const serviceAccountNameAlreadyExists = 'Service account already exists. Please enter a new name.';
75
+ exports.serviceAccountNameAlreadyExists = serviceAccountNameAlreadyExists;
74
76
 
75
- const askServiceAccountName = async () => {
76
- console.warn(_chalk.default.yellow(`WARNING: Creating a new DOSA account will overwrite any existing "private_key.pem" and "public_key.pem" files in this directory`));
77
+ const askServiceAccountName = async serviceAccounts => {
78
+ console.warn(_chalk.default.yellow(`WARNING: Creating a new DOSA account will overwrite any existing "private_key.pem" and "public_key.pem" files in this directory`)); // map to get sa names
79
+
80
+ const serviceAccountNames = serviceAccounts.map(a => a.name);
77
81
  const name = await (0, _basicPrompts.askInput)({
78
82
  msg: enterServiceAccountName,
79
83
  defaultValue: cliNowString,
80
- validate: (0, _basicPrompts.validateRegex)(_regex.dosaRegex, _regex.invalidDosaName)
84
+ validate: (0, _basicPrompts.runValidations)((0, _basicPrompts.validateInputIsNew)(serviceAccountNames, serviceAccountNameAlreadyExists), (0, _basicPrompts.validateRegex)(_regex.dosaRegex, _regex.invalidDosaName))
81
85
  });
82
86
  return name;
83
87
  };
84
88
 
85
89
  exports.askServiceAccountName = askServiceAccountName;
86
90
 
87
- const askDosaClientId = async (client, showWarning = true) => {
91
+ const fetchServiceAccount = async client => {
88
92
  const res = await client.getServiceAccounts();
89
93
  if (!res.data) throw Error('Get service accounts error.');
94
+ return res.data;
95
+ };
96
+
97
+ exports.fetchServiceAccount = fetchServiceAccount;
98
+
99
+ const askDosaClientId = async (client, showWarning = true) => {
100
+ const serviceAccounts = await fetchServiceAccount(client);
90
101
  const answer = await (0, _basicPrompts.askList)({
91
102
  msg: selectServiceAccount,
92
103
  choices: [{
93
104
  name: 'Create a new account',
94
105
  value: 'CREATE_NEW'
95
- }, new _inquirer.default.Separator(), ...res.data.map(a => a.name), new _inquirer.default.Separator()]
106
+ }, new _inquirer.default.Separator(), ...serviceAccounts.map(a => a.name), new _inquirer.default.Separator()]
96
107
  });
97
108
 
98
109
  if (answer === 'CREATE_NEW') {
99
- const name = await askServiceAccountName();
110
+ const name = await askServiceAccountName(serviceAccounts);
100
111
  return {
101
112
  clientId: null,
102
113
  name,
103
114
  isNew: true
104
115
  };
105
116
  } else {
106
- const dosa = res.data.find(a => a.name === answer);
117
+ const dosa = serviceAccounts.find(a => a.name === answer);
107
118
 
108
119
  if (showWarning) {
109
120
  console.log(_chalk.default.yellow('Please make sure your "private_key.pem" and "public_key.pem" files for the selected service account are copied to the folder location of the agents.'));
@@ -189,21 +200,37 @@ const askEnvironmentName = async (client, defsManager, isAxwayManaged = null) =>
189
200
  // do not filter any environments
190
201
  const {
191
202
  data: allEnvs
192
- } = await (0, _getters.getListByResource)(client, defsManager, 'Environment', 'env', '');
203
+ } = await (0, _getters.getListByResource)({
204
+ client,
205
+ defsManager,
206
+ resourceType: 'Environment',
207
+ resourceShortName: 'env'
208
+ });
193
209
  if (!allEnvs) throw Error(envMessages.getEnvironmentsError);
194
210
  envs = allEnvs;
195
211
  } else {
196
212
  // Get only the axway managed environments
197
213
  const {
198
214
  data: axwayManagedEnvs
199
- } = await (0, _getters.getListByResource)(client, defsManager, 'Environment', 'env', '', 'spec.axwayManaged==true');
215
+ } = await (0, _getters.getListByResource)({
216
+ client,
217
+ defsManager,
218
+ resourceType: 'Environment',
219
+ resourceShortName: 'env',
220
+ query: 'spec.axwayManaged==true'
221
+ });
200
222
  if (!axwayManagedEnvs) throw Error(envMessages.getEnvironmentsError);
201
223
  envs = axwayManagedEnvs;
202
224
 
203
225
  if (!isAxwayManaged) {
204
226
  const {
205
227
  data: allEnvs
206
- } = await (0, _getters.getListByResource)(client, defsManager, 'Environment', 'env', '');
228
+ } = await (0, _getters.getListByResource)({
229
+ client,
230
+ defsManager,
231
+ resourceType: 'Environment',
232
+ resourceShortName: 'env'
233
+ });
207
234
  if (!allEnvs) throw Error(envMessages.getEnvironmentsError); // Remove any axway managed envs from the array when isAxwayManaged is false
208
235
 
209
236
  envs = allEnvs.filter(env => {
@@ -243,7 +270,12 @@ exports.askEnvironmentName = askEnvironmentName;
243
270
  const askK8sClusterName = async (client, defsManager) => {
244
271
  const {
245
272
  data: k8sCluster
246
- } = await (0, _getters.getListByResource)(client, defsManager, 'K8SCluster', 'k8sc');
273
+ } = await (0, _getters.getListByResource)({
274
+ client,
275
+ defsManager,
276
+ resourceType: 'K8SCluster',
277
+ resourceShortName: 'k8sc'
278
+ });
247
279
  if (!k8sCluster) throw Error(k8sClusterMessages.getK8sClustersError);
248
280
  const name = await (0, _basicPrompts.askInput)({
249
281
  msg: k8sClusterMessages.enterK8sClusterName,
@@ -258,14 +290,14 @@ exports.askK8sClusterName = askK8sClusterName;
258
290
  const askAgentName = async (client, defsManager, agentType, scopeName) => {
259
291
  var _agents;
260
292
 
261
- let resourceLongName;
293
+ let resourceType;
262
294
  let resourceShortName;
263
295
  let msg;
264
296
 
265
297
  switch (agentType) {
266
298
  case _types.AgentTypes.da:
267
299
  {
268
- resourceLongName = 'DiscoveryAgent';
300
+ resourceType = 'DiscoveryAgent';
269
301
  resourceShortName = 'da';
270
302
  msg = agentMessages.enterDiscoveryAgentName;
271
303
  break;
@@ -273,7 +305,7 @@ const askAgentName = async (client, defsManager, agentType, scopeName) => {
273
305
 
274
306
  case _types.AgentTypes.ta:
275
307
  {
276
- resourceLongName = 'TraceabilityAgent';
308
+ resourceType = 'TraceabilityAgent';
277
309
  resourceShortName = 'ta';
278
310
  msg = agentMessages.enterTraceabilityAgentName;
279
311
  break;
@@ -282,13 +314,19 @@ const askAgentName = async (client, defsManager, agentType, scopeName) => {
282
314
 
283
315
  let {
284
316
  data: agents
285
- } = await (0, _getters.getListByResource)(client, defsManager, resourceLongName, resourceShortName, scopeName); // if there are no agents scoped to the env, make the agents list blank to validate against
317
+ } = await (0, _getters.getListByResource)({
318
+ client,
319
+ defsManager,
320
+ resourceType,
321
+ resourceShortName,
322
+ scopeName
323
+ }); // if there are no agents scoped to the env, make the agents list blank to validate against
286
324
 
287
325
  agents = (_agents = agents) !== null && _agents !== void 0 ? _agents : [];
288
326
  const name = await (0, _basicPrompts.askInput)({
289
327
  msg: msg,
290
328
  defaultValue: cliNowString,
291
- validate: (0, _basicPrompts.runValidations)((0, _basicPrompts.validateInputIsNew)(agents.map(a => a.name), agentMessages.agentAlreadyExists), (0, _basicPrompts.validateRegex)(_regex.resourceRegex, (0, _regex.invalidResourceMsg)(resourceLongName)))
329
+ validate: (0, _basicPrompts.runValidations)((0, _basicPrompts.validateInputIsNew)(agents.map(a => a.name), agentMessages.agentAlreadyExists), (0, _basicPrompts.validateRegex)(_regex.resourceRegex, (0, _regex.invalidResourceMsg)(resourceType)))
292
330
  });
293
331
  return name;
294
332
  };
@@ -79,6 +79,12 @@ als:
79
79
  condorSslVerification: full
80
80
  enabled: {{istioAgentValues.alsEnabled}}
81
81
 
82
+ # sampling configuration
83
+ sampling:
84
+ percentage: {{traceabilityConfig.samplingPercentage}}
85
+ per_api: true
86
+ reportAllErrors: {{traceabilityConfig.samplingReportAllErrors}}
87
+
82
88
  # name of the secret containing the public & private keys used by the provided DOSA client ID
83
89
  keysSecretName: {{istioAgentValues.keysSecretName}}
84
90
  publishHeaders: true
@@ -60,18 +60,15 @@ const getTraceabilityConfig = async installConfig => {
60
60
  traceabilityConfig.usageReportingOffline = installConfig.bundleType === _types.BundleType.TRACEABILITY_OFFLINE; // Do not ask Traceability questions in offline mode
61
61
 
62
62
  if (!traceabilityConfig.usageReportingOffline) {
63
- console.log('\nCONNECTION TO TRACEABILITY MODULE:'); // Will remove this logic check once sampling is added to ISTIO. For now, suppress askToEnableTransactionLogging
64
-
65
- if (installConfig.gatewayType !== _types.GatewayTypes.ISTIO) {
66
- const {
67
- enabled,
68
- samplingPercentage,
69
- shouldReportAllErrors
70
- } = await helpers.askToEnableTransactionLogging();
71
- traceabilityConfig.enabled = enabled;
72
- traceabilityConfig.samplingPercentage = samplingPercentage;
73
- traceabilityConfig.samplingReportAllErrors = shouldReportAllErrors;
74
- }
63
+ console.log('\nCONNECTION TO TRACEABILITY MODULE:');
64
+ const {
65
+ enabled,
66
+ samplingPercentage,
67
+ shouldReportAllErrors
68
+ } = await helpers.askToEnableTransactionLogging();
69
+ traceabilityConfig.enabled = enabled;
70
+ traceabilityConfig.samplingPercentage = samplingPercentage;
71
+ traceabilityConfig.samplingReportAllErrors = shouldReportAllErrors;
75
72
 
76
73
  if (traceabilityConfig.enabled) {
77
74
  const traceabilityProtocol = await helpers.askIngestionProtocol();
@@ -38,6 +38,7 @@ const action = async ({
38
38
  const {
39
39
  baseUrl,
40
40
  clientId,
41
+ account,
41
42
  force,
42
43
  json,
43
44
  proxyDefinition,
@@ -55,6 +56,7 @@ const action = async ({
55
56
  baseUrl,
56
57
  basePath: _types.BasePaths.Aggregator,
57
58
  clientId,
59
+ account,
58
60
  region
59
61
  });
60
62
  const body = new _formData.default();
@@ -21,6 +21,7 @@ const proxies = {
21
21
  },
22
22
  desc: 'Manage API proxies',
23
23
  options: { ..._types.commonCmdArgsDescription,
24
+ '--client-id [value]': `Override your DevOps account's client ID`,
24
25
  '--json': 'Show JSON output'
25
26
  }
26
27
  };
@@ -38,6 +38,7 @@ const action = async ({
38
38
  const {
39
39
  baseUrl,
40
40
  clientId,
41
+ account,
41
42
  region,
42
43
  json,
43
44
  proxyDefinition,
@@ -56,6 +57,7 @@ const action = async ({
56
57
  baseUrl,
57
58
  basePath: _types.BasePaths.Aggregator,
58
59
  clientId,
60
+ account,
59
61
  region
60
62
  });
61
63
  const body = new _formData.default();
@@ -20,16 +20,20 @@ const {
20
20
  } = (0, _snooplogg.default)('central:class.ApiCentralClient');
21
21
 
22
22
  class ApiCentralClient {
23
- constructor(baseUrl, clientId, region) {
23
+ constructor({
24
+ baseUrl,
25
+ region,
26
+ account
27
+ }) {
24
28
  _defineProperty(this, "baseUrl", void 0);
25
29
 
26
- _defineProperty(this, "clientId", void 0);
27
-
28
30
  _defineProperty(this, "region", void 0);
29
31
 
30
- log(`initializing client with params: baseUrl = ${baseUrl}, clientId = ${clientId}, region = ${region}`);
32
+ _defineProperty(this, "account", void 0);
33
+
34
+ log(`initializing client with params: baseUrl = ${baseUrl}, region = ${region}, account = ${account}`);
31
35
  this.baseUrl = baseUrl;
32
- this.clientId = clientId;
36
+ this.account = account;
33
37
  this.region = region;
34
38
  }
35
39
  /**
@@ -50,7 +54,7 @@ class ApiCentralClient {
50
54
  const service = await (0, _dataService.dataService)({
51
55
  baseUrl: this.baseUrl,
52
56
  basePath: _types.BasePaths.ApiCentral,
53
- clientId: this.clientId,
57
+ account: this.account,
54
58
  region: this.region
55
59
  });
56
60
  const payload = {
@@ -88,7 +92,7 @@ class ApiCentralClient {
88
92
  const service = await (0, _dataService.dataService)({
89
93
  baseUrl: this.baseUrl,
90
94
  basePath: _types.BasePaths.ApiCentral,
91
- clientId: this.clientId,
95
+ account: this.account,
92
96
  region: this.region
93
97
  });
94
98
  const response = await service.getWithPagination(`/serviceAccounts`, 'type==SA&sort=modifyTime%2CDESC');