@axway/axway-central-cli 2.4.1 → 2.5.3

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.
package/README.md CHANGED
@@ -456,8 +456,8 @@ USAGE: axway central create <command> [options]
456
456
  Create one or more resources from a file or stdin
457
457
 
458
458
  CREATE COMMANDS:
459
- environment Create an environment with the specified name
460
- service-account Create a service account
459
+ agent-resource Create an agent resource
460
+ environment Create an environment with the specified name
461
461
 
462
462
  CREATE OPTIONS:
463
463
  --account [value] Override your default account config
@@ -504,8 +504,6 @@ axway central create env newenv
504
504
  axway central create environment newenv -o yaml
505
505
  # create multiple resources from file
506
506
  axway central create -f ./some/folder/resources.yaml
507
- # create a service account(DOSA)
508
- axway central create service-account
509
507
  # create an agent resource
510
508
  axway central create agent-resource
511
509
  ```
@@ -5,57 +5,15 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.serviceAccount = void 0;
7
7
 
8
- var _snooplogg = _interopRequireDefault(require("snooplogg"));
9
-
10
- var _ApiCentralClient = require("../../common/ApiCentralClient");
11
-
12
- var _bashCommands = require("../../common/bashCommands");
13
-
14
- var _Renderer = _interopRequireDefault(require("../../common/Renderer"));
15
-
16
- var _helpers = require("../install/helpers");
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
- const {
21
- log
22
- } = (0, _snooplogg.default)('central: create: service-account');
23
-
24
- const action = async ({
25
- argv,
26
- console
27
- }) => {
28
- const {
29
- baseUrl,
30
- account,
31
- region
32
- } = argv;
33
- const render = new _Renderer.default(console);
34
- let isCmdError = false;
35
- const apiCentralClient = new _ApiCentralClient.ApiCentralClient({
36
- baseUrl,
37
- account,
38
- region
39
- });
40
-
41
- try {
42
- await (0, _bashCommands.isOpenSslInstalled)();
43
- const dosaName = await (0, _helpers.askServiceAccountName)();
44
- await (0, _helpers.createDosaAndCerts)(apiCentralClient, dosaName);
45
- } catch (e) {
46
- log('command error', e);
47
- render.anyError(e);
48
- isCmdError = true;
49
- } finally {
50
- log('command finished, error = ', isCmdError);
51
- if (isCmdError) process.exit(1);
52
- process.exit(0);
53
- }
8
+ const action = async ({}) => {
9
+ throw new Error('Creating a service account via "central" is no longer supported. ' + 'Use the "axway" CLI instead. ' + 'Example: "axway service-account create [options]"');
54
10
  };
55
11
 
56
12
  const serviceAccount = {
57
13
  aliases: ['service account', 'service-account', 'serviceaccount'],
58
14
  action,
59
- desc: 'Create a service account'
15
+ desc: 'Create a service account',
16
+ hidden: true // Hide this command line option since it's no longer supported.
17
+
60
18
  };
61
19
  exports.serviceAccount = serviceAccount;
@@ -106,14 +106,29 @@ ${defsManager.getDefsTableForHelpMsg()}`);
106
106
  return scope && (scope.kind && scope.kind === ((_defs$scope = defs.scope) === null || _defs$scope === void 0 ? void 0 : _defs$scope.spec.kind) || !scope.kind && !!defs.scope) || !scope && !defs.scope;
107
107
  }); // this should never happen, the filtering logic is probably invalid if true
108
108
 
109
- if (!matchingDefs.length) throw Error(`can't find matching resource definitions.`); // Prompt the confirmation if action will be executed on multiple resources
110
-
111
- if (!yes && matchingDefs.length > 1) {
112
- if ((await (0, _basicPrompts.askList)({
113
- msg: 'The resource may exist in many scopes, and multiple entities might be deleted. Do you want to continue?',
114
- choices: _types.YesNoChoices,
115
- default: _types.YesNo.Yes
116
- })) === _types.YesNo.No) process.exit(1);
109
+ if (!matchingDefs.length) throw Error(`can't find matching resource definitions.`); // Ask user if it's okay to delete unless the "--yes" option is set.
110
+ // Note: Only prompt if it ends up deleting multiple associated resources.
111
+
112
+ if (!yes) {
113
+ let result = _types.YesNo.Yes;
114
+
115
+ if (!scope) {
116
+ result = await (0, _basicPrompts.askList)({
117
+ msg: 'Deleting this will delete all resources under its scope. Are you sure you want to do this?',
118
+ choices: _types.YesNoChoices,
119
+ default: _types.YesNo.No
120
+ });
121
+ } else if (matchingDefs.length > 1) {
122
+ result = await (0, _basicPrompts.askList)({
123
+ msg: 'The resource may exist in many scopes, and multiple entities might be deleted. Do you want to continue?',
124
+ choices: _types.YesNoChoices,
125
+ default: _types.YesNo.No
126
+ });
127
+ }
128
+
129
+ if (result === _types.YesNo.No) {
130
+ process.exit(1);
131
+ }
117
132
  }
118
133
 
119
134
  render.startSpin(`Deleting resources${wait ? ' and waiting for them to be deleted' : ''}`);
@@ -9,8 +9,6 @@ var _chalk = _interopRequireDefault(require("chalk"));
9
9
 
10
10
  var _snooplogg = _interopRequireDefault(require("snooplogg"));
11
11
 
12
- var _ApiCentralClient = require("../../common/ApiCentralClient");
13
-
14
12
  var _ApiServerClient = require("../../common/ApiServerClient");
15
13
 
16
14
  var _basicPrompts = require("../../common/basicPrompts");
@@ -84,12 +82,7 @@ const agents = {
84
82
  const render = new _Renderer.default(console);
85
83
 
86
84
  try {
87
- // initiate clients
88
- const apiCentralClient = new _ApiCentralClient.ApiCentralClient({
89
- baseUrl,
90
- account,
91
- region
92
- });
85
+ // initialize clients
93
86
  const apiServerClient = new _ApiServerClient.ApiServerClient({
94
87
  baseUrl,
95
88
  account,
@@ -144,7 +137,7 @@ const agents = {
144
137
  } // get platform connectivity
145
138
 
146
139
 
147
- installConfig.centralConfig = await platform.getCentralConfig(apiCentralClient, apiServerClient, platformClient, defsManager, apicDeployment, installConfig); // Create the object of GatewayTypes -> GatewayConnectivity functions
140
+ installConfig.centralConfig = await platform.getCentralConfig(apiServerClient, platformClient, defsManager, apicDeployment, installConfig); // Create the object of GatewayTypes -> GatewayConnectivity functions
148
141
 
149
142
  installConfig.gatewayConfig = await agentInstallFlow.AskGatewayQuestions(installConfig, apiServerClient, defsManager); // traceability options
150
143
 
@@ -157,7 +150,7 @@ const agents = {
157
150
 
158
151
  if (agentInstallFlow.InstallPreprocess) installConfig = await agentInstallFlow.InstallPreprocess(installConfig); // finalize platform setup
159
152
 
160
- installConfig = await platform.finalizeCentralInstall(apiCentralClient, apiServerClient, platformClient, defsManager, installConfig); // finalize gateway setup and output
153
+ installConfig = await platform.finalizeCentralInstall(apiServerClient, platformClient, defsManager, installConfig); // finalize gateway setup and output
161
154
 
162
155
  await agentInstallFlow.FinalizeGatewayInstall(installConfig, apiServerClient, defsManager);
163
156
  } catch (e) {
@@ -317,7 +317,7 @@ const completeInstall = async installConfig => {
317
317
 
318
318
  await helpers.createSecret(v7AgentValues.namespace.name, helpers.amplifyAgentsKeysSecret, async () => {
319
319
  if (installConfig.centralConfig.ampcDosaInfo.isNew) {
320
- console.log(_cliKit.chalk.yellow(`The secret '${helpers.amplifyAgentsKeysSecret}' will be created with the same "private_key.pem" and "public_key.pem" that was auto generated to create the DOSA Account.`));
320
+ console.log(_cliKit.chalk.yellow(`The secret '${helpers.amplifyAgentsKeysSecret}' will be created with the same "private_key.pem" and "public_key.pem" that was auto generated to create the Service Account.`));
321
321
  }
322
322
 
323
323
  await helpers.createAmplifyAgentKeysSecret(v7AgentValues.namespace.name, helpers.amplifyAgentsKeysSecret, 'public_key', v7AgentValues.centralConfig.dosaAccount.publicKey, 'private_key', v7AgentValues.centralConfig.dosaAccount.privateKey);
@@ -13,6 +13,8 @@ var _bashCommands = require("../../../common/bashCommands");
13
13
 
14
14
  var _Kubectl = require("../../../common/Kubectl");
15
15
 
16
+ var _PlatformClient = require("../../../common/PlatformClient");
17
+
16
18
  var _types = require("../../../common/types");
17
19
 
18
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -48,18 +50,15 @@ const createDosaAndCerts = async (client, name) => {
48
50
 
49
51
  const publicCert = _fsExtra.default.readFileSync(publicKey).toString();
50
52
 
51
- const result = await client.createDOSAAccount(name, publicCert);
52
-
53
- if (!result.data) {
54
- var _result$error;
55
-
56
- throw Error(`Cannot create service account${(_result$error = result.error) !== null && _result$error !== void 0 && _result$error.length ? `: ${result.error[0].title}` : '.'}`);
57
- } else {
58
- console.log(_chalk.default.green(`New service account "${result.data.name}" with clientId "${result.data.clientId}" has been successfully created.`));
59
- console.log(_chalk.default.green(`The private key has been placed at ${privateKey}\nThe public key has been placed at ${publicKey}`));
60
- }
61
-
62
- return new _types.DosaAccount(result.data.clientId, publicKey, privateKey);
53
+ const account = await client.createServiceAccount({
54
+ name: name,
55
+ desc: name,
56
+ publicKey: publicCert,
57
+ roles: [_PlatformClient.PlatformServiceAccountRole.ApiCentralAdmin]
58
+ });
59
+ console.log(_chalk.default.green(`New service account "${account.name}" with clientId "${account.client_id}" has been successfully created.`));
60
+ console.log(_chalk.default.green(`The private key has been placed at ${privateKey}\nThe public key has been placed at ${publicKey}`));
61
+ return new _types.DosaAccount(account.client_id, publicKey, privateKey);
63
62
  };
64
63
 
65
64
  exports.createDosaAndCerts = createDosaAndCerts;
@@ -85,9 +84,9 @@ const createByResourceType = async (client, defsManager, name, resourceType, res
85
84
  });
86
85
 
87
86
  if (!result.data) {
88
- var _result$error2;
87
+ var _result$error;
89
88
 
90
- throw Error(`Cannot create a new ${resourceType.toLowerCase()}${(_result$error2 = result.error) !== null && _result$error2 !== void 0 && _result$error2.length ? `: ${result.error[0].detail}` : '.'}`);
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}` : '.'}`);
91
90
  } else {
92
91
  console.log(`New ${resourceType.toLowerCase()} "${result.data.name}" has been successfully created.`);
93
92
  }
@@ -123,9 +122,9 @@ const createNewAgentResource = async (client, defsManager, envName, dataPlaneTyp
123
122
  });
124
123
 
125
124
  if (!result.data) {
126
- var _result$error3;
125
+ var _result$error2;
127
126
 
128
- throw Error(`Cannot create a new agent ${(_result$error3 = result.error) !== null && _result$error3 !== void 0 && _result$error3.length ? `: ${result.error[0].detail}` : '.'}`);
127
+ throw Error(`Cannot create a new agent ${(_result$error2 = result.error) !== null && _result$error2 !== void 0 && _result$error2.length ? `: ${result.error[0].detail}` : '.'}`);
129
128
  } else {
130
129
  console.log(`New agent of type "${defs[0].resource.name}" named "${result.data.name}" has been successfully created.`);
131
130
  }
@@ -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.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
 
@@ -61,7 +61,7 @@ const secretAlreadyExists = 'Secret already exists. Please enter a new name.';
61
61
  exports.secretAlreadyExists = secretAlreadyExists;
62
62
  const enterNamespaceName = 'Enter a new namespace name';
63
63
  exports.enterNamespaceName = enterNamespaceName;
64
- const selectServiceAccount = 'Select a service account (DOSA)';
64
+ const selectServiceAccount = 'Select a service account';
65
65
  exports.selectServiceAccount = selectServiceAccount;
66
66
  const enterServiceAccountName = 'Enter a new service account name';
67
67
  exports.enterServiceAccountName = enterServiceAccountName;
@@ -71,13 +71,15 @@ 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 serviceAccountNames => {
78
+ 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`));
77
79
  const name = await (0, _basicPrompts.askInput)({
78
80
  msg: enterServiceAccountName,
79
81
  defaultValue: cliNowString,
80
- validate: (0, _basicPrompts.validateRegex)(_regex.dosaRegex, _regex.invalidDosaName)
82
+ validate: (0, _basicPrompts.runValidations)((0, _basicPrompts.validateInputIsNew)(serviceAccountNames, serviceAccountNameAlreadyExists), (0, _basicPrompts.validateRegex)(_regex.dosaRegex, _regex.invalidDosaName))
81
83
  });
82
84
  return name;
83
85
  };
@@ -85,33 +87,37 @@ const askServiceAccountName = async () => {
85
87
  exports.askServiceAccountName = askServiceAccountName;
86
88
 
87
89
  const askDosaClientId = async (client, showWarning = true) => {
88
- const res = await client.getServiceAccounts();
89
- if (!res.data) throw Error('Get service accounts error.');
90
- const answer = await (0, _basicPrompts.askList)({
90
+ // Fetch all existing service accounts.
91
+ const serviceAccounts = await client.getServiceAccounts();
92
+ const serviceAccountNames = serviceAccounts.map(nextAccount => nextAccount.name); // Ask user to select an existing service account or create a new one.
93
+
94
+ const selectedName = await (0, _basicPrompts.askList)({
91
95
  msg: selectServiceAccount,
92
96
  choices: [{
93
- name: 'Create a new account',
97
+ name: 'Create a new service account',
94
98
  value: 'CREATE_NEW'
95
- }, new _inquirer.default.Separator(), ...res.data.map(a => a.name), new _inquirer.default.Separator()]
99
+ }, new _inquirer.default.Separator(), ...serviceAccountNames, new _inquirer.default.Separator()]
96
100
  });
97
101
 
98
- if (answer === 'CREATE_NEW') {
99
- const name = await askServiceAccountName();
102
+ if (selectedName === 'CREATE_NEW') {
103
+ // We're going to create a new service account. Ask for a unique name. (We'll create it later.)
104
+ const name = await askServiceAccountName(serviceAccountNames);
100
105
  return {
101
106
  clientId: null,
102
107
  name,
103
108
  isNew: true
104
109
  };
105
110
  } else {
106
- const dosa = res.data.find(a => a.name === answer);
107
-
111
+ // We're using an existing service account. Notify user to make its keys available to the agents.
108
112
  if (showWarning) {
109
113
  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.'));
110
- }
114
+ } // Fetch selected service account's client ID and return info about it.
115
+
111
116
 
117
+ const selectedAccount = serviceAccounts.find(nextAccount => nextAccount.name === selectedName);
112
118
  return {
113
- clientId: dosa.clientId,
114
- name: dosa.name,
119
+ clientId: selectedAccount === null || selectedAccount === void 0 ? void 0 : selectedAccount.client_id,
120
+ name: selectedName,
115
121
  isNew: false
116
122
  };
117
123
  }
@@ -233,7 +239,7 @@ const askEnvironmentName = async (client, defsManager, isAxwayManaged = null) =>
233
239
  choices: [{
234
240
  name: envMessages.createNewEnvironment,
235
241
  value: 'CREATE_NEW'
236
- }, new _inquirer.default.Separator(), ...envs.map(e => e.name), new _inquirer.default.Separator()]
242
+ }, new _inquirer.default.Separator(), ...envs.map(e => e.name).sort((name1, name2) => name1.localeCompare(name2)), new _inquirer.default.Separator()]
237
243
  });
238
244
 
239
245
  if (answer === 'CREATE_NEW') {
@@ -321,11 +327,11 @@ const askAgentName = async (client, defsManager, agentType, scopeName) => {
321
327
  };
322
328
  /**
323
329
  * @description Create a secret that contains a public & private key pair for agents to connect to central.
324
- * If a user is creating a new DOSA account, then the keys should be passed in as args.
325
- * If they are using an existing account, then the user will be prompted for the keys that created the DOSA account.
330
+ * If a user is creating a new service account, then the keys should be passed in as args.
331
+ * If they are using an existing account, then the user will be prompted for the keys that created the service account.
326
332
  * @param namespace The namespace to create the secret in.
327
333
  * @param secretName The name of the secret.
328
- * @param publicKey The file path to the public key attached to the chosen DOSA.
334
+ * @param publicKey The file path to the public key attached to the chosen service account.
329
335
  * @param privateKey The file path to the corresponding private key.
330
336
  */
331
337
 
@@ -384,7 +390,7 @@ const askPrivateKeyPath = async () => await (0, _basicPrompts.askInput)({
384
390
  exports.askPrivateKeyPath = askPrivateKeyPath;
385
391
 
386
392
  const askPublicAndPrivateKeysPath = async () => {
387
- console.log(_chalk.default.yellow('Please provide the same "private_key.pem" and "public_key.pem" that was used to create the selected DOSA Account.'));
393
+ console.log(_chalk.default.yellow('Please provide the same "private_key.pem" and "public_key.pem" that was used to create the selected Service Account.'));
388
394
  const publicKey = await askPublicKeyPath();
389
395
  const privateKey = await askPrivateKeyPath();
390
396
  return [publicKey, privateKey];
@@ -71,7 +71,7 @@ als:
71
71
  # distinguishes events between apic deployments
72
72
  apicDeployment: {{centralConfig.deployment}}
73
73
 
74
- # DOSA client ID
74
+ # service account client ID
75
75
  clientID: {{centralConfig.dosaAccount.clientId}}
76
76
 
77
77
  # condor ingestion endpoint
@@ -85,7 +85,7 @@ als:
85
85
  per_api: true
86
86
  reportAllErrors: {{traceabilityConfig.samplingReportAllErrors}}
87
87
 
88
- # name of the secret containing the public & private keys used by the provided DOSA client ID
88
+ # name of the secret containing the public & private keys used by the provided service account client ID
89
89
  keysSecretName: {{istioAgentValues.keysSecretName}}
90
90
  publishHeaders: true
91
91
 
@@ -93,7 +93,7 @@ als:
93
93
 
94
94
  # discovers API Documentation
95
95
  ada:
96
- # DOSA client ID
96
+ # service account client ID
97
97
  clientID: {{centralConfig.dosaAccount.clientId}}
98
98
 
99
99
  # name of the K8SCluster the agent is connected to
@@ -101,12 +101,12 @@ ada:
101
101
  command: apis
102
102
  enabled: {{istioAgentValues.discoveryEnabled}}
103
103
 
104
- # name of the secret containing the public & private keys used by the provided DOSA client ID
104
+ # name of the secret containing the public & private keys used by the provided service account client ID
105
105
  keysSecretName: {{istioAgentValues.keysSecretName}}
106
106
 
107
107
  # discovers running pods/services
108
108
  rda:
109
- # DOSA client ID
109
+ # service account client ID
110
110
  clientID: {{centralConfig.dosaAccount.clientId}}
111
111
 
112
112
  # name of the connected K8SCluster
@@ -114,7 +114,7 @@ rda:
114
114
  command: resources
115
115
  enabled: {{istioAgentValues.discoveryEnabled}}
116
116
 
117
- # name of the secret containing the public & private keys used by the provided DOSA client ID
117
+ # name of the secret containing the public & private keys used by the provided service account client ID
118
118
  keysSecretName: {{istioAgentValues.keysSecretName}}
119
119
 
120
120
  # to enable deployment of demo list service with agent installation. Set to true to install the demo service
@@ -398,11 +398,11 @@ const createHybridOverride = overrides => {
398
398
  exports.createHybridOverride = createHybridOverride;
399
399
 
400
400
  const installPreprocess = async installConfig => {
401
- // name of the dosa account, and if it is new or not
401
+ // name of the service account, and if it is new or not
402
402
  if (!installConfig.centralConfig.ampcDosaInfo.isNew) {
403
403
  [installConfig.centralConfig.dosaAccount.publicKey, installConfig.centralConfig.dosaAccount.privateKey] = await helpers.askPublicAndPrivateKeysPath();
404
404
  } else {
405
- console.log(_chalk.default.yellow(`The secret will be created with the same "private_key.pem" and "public_key.pem" that will be auto generated to create the DOSA Account, following the completion of these prompts.`));
405
+ console.log(_chalk.default.yellow(`The secret will be created with the same "private_key.pem" and "public_key.pem" that will be auto generated to create the Service Account, following the completion of these prompts.`));
406
406
  }
407
407
 
408
408
  return installConfig;
@@ -424,7 +424,7 @@ const completeInstall = async (installConfig, apiServerClient, defsManager) => {
424
424
 
425
425
  await helpers.createSecret(istioValues.istioAgentValues.namespace.name, helpers.amplifyAgentsKeysSecret, async () => {
426
426
  if (installConfig.centralConfig.ampcDosaInfo.isNew) {
427
- console.log(_chalk.default.yellow(`The secret '${helpers.amplifyAgentsKeysSecret}' will be created with the same "private_key.pem" and "public_key.pem" that was auto generated to create the DOSA Account.`));
427
+ console.log(_chalk.default.yellow(`The secret '${helpers.amplifyAgentsKeysSecret}' will be created with the same "private_key.pem" and "public_key.pem" that was auto generated to create the Service Account.`));
428
428
  }
429
429
 
430
430
  await helpers.createAmplifyAgentKeysSecret(istioValues.istioAgentValues.namespace.name, helpers.amplifyAgentsKeysSecret, 'publicKey', istioValues.centralConfig.dosaAccount.publicKey, 'privateKey', istioValues.centralConfig.dosaAccount.privateKey);
@@ -37,7 +37,7 @@ const askTeamName = async client => {
37
37
  if (!res.data) throw Error('Get teams error.');
38
38
  return (0, _basicPrompts.askList)({
39
39
  msg: helpers.envMessages.selectTeam,
40
- choices: res.data.result.map(t => t.name),
40
+ choices: res.data.result.map(t => t.name).sort((name1, name2) => name1.localeCompare(name2)),
41
41
  default: (_res$data$result$find = res.data.result.find(t => t.default)) === null || _res$data$result$find === void 0 ? void 0 : _res$data$result$find.name
42
42
  });
43
43
  };
@@ -82,12 +82,12 @@ const getTraceabilityConfig = async installConfig => {
82
82
 
83
83
  exports.getTraceabilityConfig = getTraceabilityConfig;
84
84
 
85
- const getCentralConfig = async (apiCentralClient, apiServerClient, platformClient, defsManager, apicDeployment, installConfig) => {
85
+ const getCentralConfig = async (apiServerClient, platformClient, defsManager, apicDeployment, installConfig) => {
86
86
  // initiate CentralAgentConfig
87
87
  let centralConfig = installConfig.centralConfig;
88
88
  await centralConfig.setBaseHost();
89
89
  centralConfig.authUrl = `${_CoreConfigController.CoreConfigController.getAuthUrl()}/auth`;
90
- centralConfig.region = String(apiCentralClient.region || (await (0, _utils.getConfig)())[_types.ConfigTypes.REGION] || _types.Regions.US).toUpperCase();
90
+ centralConfig.region = String(apiServerClient.region || (await (0, _utils.getConfig)())[_types.ConfigTypes.REGION] || _types.Regions.US).toUpperCase();
91
91
  centralConfig.deployment = apicDeployment || getApicDeployment(centralConfig.region, _CoreConfigController.CoreConfigController.getEnv()); // apic config
92
92
 
93
93
  console.log('\nCONNECTION TO AMPLIFY PLATFORM:');
@@ -104,7 +104,7 @@ const getCentralConfig = async (apiCentralClient, apiServerClient, platformClien
104
104
  };
105
105
 
106
106
  if (installConfig.bundleType !== _types.BundleType.TRACEABILITY_OFFLINE) {
107
- centralConfig.ampcDosaInfo = await helpers.askDosaClientId(apiCentralClient);
107
+ centralConfig.ampcDosaInfo = await helpers.askDosaClientId(platformClient);
108
108
  } // Get the DA Agent name
109
109
 
110
110
 
@@ -126,14 +126,14 @@ const getCentralConfig = async (apiCentralClient, apiServerClient, platformClien
126
126
 
127
127
  exports.getCentralConfig = getCentralConfig;
128
128
 
129
- const finalizeCentralInstall = async (apiCentralClient, apiServerClient, platformClient, defsManager, installConfig) => {
129
+ const finalizeCentralInstall = async (apiServerClient, platformClient, defsManager, installConfig) => {
130
130
  /**
131
131
  * Create agent resources
132
132
  */
133
133
  console.log('Creating agent resources');
134
134
 
135
135
  if (installConfig.centralConfig.ampcDosaInfo.isNew) {
136
- installConfig.centralConfig.dosaAccount = await helpers.createDosaAndCerts(apiCentralClient, installConfig.centralConfig.ampcDosaInfo.name);
136
+ installConfig.centralConfig.dosaAccount = await helpers.createDosaAndCerts(platformClient, installConfig.centralConfig.ampcDosaInfo.name);
137
137
  } else {
138
138
  installConfig.centralConfig.dosaAccount.clientId = installConfig.centralConfig.ampcDosaInfo.clientId;
139
139
  }
@@ -62,7 +62,7 @@ class CoreConfigController {
62
62
  // https://jira.axway.com/browse/APIGOV-20818
63
63
  log(`getAuthInfo, clientId value passed, trying to find a matching account`);
64
64
  const list = await sdk.auth.list({
65
- verify: true
65
+ validate: true
66
66
  });
67
67
  const matchingAccount = list.find(a => a.auth.clientId === clientId);
68
68
  if (matchingAccount) CoreConfigController.devOpsAccount = await sdk.auth.find(matchingAccount.name);
@@ -74,7 +74,7 @@ class CoreConfigController {
74
74
  // ELSE: trying to get any authenticated account
75
75
  log(`getAuthInfo, account value not passed, trying to find default/any match`);
76
76
  const list = await sdk.auth.list({
77
- verify: true
77
+ validate: true
78
78
  });
79
79
  log(`getAuthInfo, authenticated accounts found: ${list.length}`);
80
80
 
@@ -3,21 +3,76 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.PlatformClient = void 0;
6
+ exports.PlatformTeamMemberRole = exports.PlatformServiceAccountRole = exports.PlatformClient = exports.PlatformAuthMethod = void 0;
7
7
 
8
8
  var _snooplogg = _interopRequireDefault(require("snooplogg"));
9
9
 
10
+ var _amplifyCliUtils = require("@axway/amplify-cli-utils");
11
+
10
12
  var _dataService = require("./dataService");
11
13
 
12
14
  var _types = require("./types");
13
15
 
14
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
17
 
16
- 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; }
18
+ function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
19
+
20
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
21
+
22
+ function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
23
+
24
+ function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
25
+
26
+ function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
27
+
28
+ function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
29
+
30
+ function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
17
31
 
18
32
  const {
19
33
  log
20
34
  } = (0, _snooplogg.default)('central:class.PlatformClient');
35
+ let PlatformAuthMethod;
36
+ exports.PlatformAuthMethod = PlatformAuthMethod;
37
+
38
+ (function (PlatformAuthMethod) {
39
+ PlatformAuthMethod["Certificate"] = "certificate";
40
+ PlatformAuthMethod["Secret"] = "secret";
41
+ })(PlatformAuthMethod || (exports.PlatformAuthMethod = PlatformAuthMethod = {}));
42
+
43
+ let PlatformServiceAccountRole;
44
+ exports.PlatformServiceAccountRole = PlatformServiceAccountRole;
45
+
46
+ (function (PlatformServiceAccountRole) {
47
+ PlatformServiceAccountRole["ApiCentralAdmin"] = "api_central_admin";
48
+ PlatformServiceAccountRole["FlowCentralAccessManager"] = "fc_access_manager";
49
+ PlatformServiceAccountRole["FlowCentralIntegration"] = "fc_integration";
50
+ PlatformServiceAccountRole["FlowCentralITAdmin"] = "fc_it_admin";
51
+ PlatformServiceAccountRole["FlowCentralProductsAdmin"] = "fc_products_admin";
52
+ PlatformServiceAccountRole["FlowCentralSpecOps"] = "fc_spec_ops";
53
+ PlatformServiceAccountRole["FlowCentralSubscriptionApprover"] = "fc_subscriptionapprover";
54
+ PlatformServiceAccountRole["FlowCentralSubscriptionSpecialist"] = "fc_subscriptionspecialist";
55
+ PlatformServiceAccountRole["FlowCentralTemplatePublisher"] = "fc_templatepublisher";
56
+ PlatformServiceAccountRole["FlowCentralCftAdmin"] = "fc_cft_admin";
57
+ })(PlatformServiceAccountRole || (exports.PlatformServiceAccountRole = PlatformServiceAccountRole = {}));
58
+
59
+ let PlatformTeamMemberRole;
60
+ exports.PlatformTeamMemberRole = PlatformTeamMemberRole;
61
+
62
+ (function (PlatformTeamMemberRole) {
63
+ PlatformTeamMemberRole["Admin"] = "administrator";
64
+ PlatformTeamMemberRole["Developer"] = "developer";
65
+ PlatformTeamMemberRole["Consumer"] = "consumer";
66
+ PlatformTeamMemberRole["CatalogManager"] = "catalog_manager";
67
+ })(PlatformTeamMemberRole || (exports.PlatformTeamMemberRole = PlatformTeamMemberRole = {}));
68
+
69
+ var _baseUrl = /*#__PURE__*/new WeakMap();
70
+
71
+ var _accountName = /*#__PURE__*/new WeakMap();
72
+
73
+ var _amplifyConfig = /*#__PURE__*/new WeakMap();
74
+
75
+ var _amplifySdk = /*#__PURE__*/new WeakMap();
21
76
 
22
77
  class PlatformClient {
23
78
  constructor({
@@ -25,16 +80,82 @@ class PlatformClient {
25
80
  region,
26
81
  account
27
82
  } = {}) {
28
- _defineProperty(this, "baseUrl", void 0);
83
+ _classPrivateFieldInitSpec(this, _baseUrl, {
84
+ writable: true,
85
+ value: void 0
86
+ });
87
+
88
+ _classPrivateFieldInitSpec(this, _accountName, {
89
+ writable: true,
90
+ value: void 0
91
+ });
92
+
93
+ _classPrivateFieldInitSpec(this, _amplifyConfig, {
94
+ writable: true,
95
+ value: void 0
96
+ });
97
+
98
+ _classPrivateFieldInitSpec(this, _amplifySdk, {
99
+ writable: true,
100
+ value: void 0
101
+ });
29
102
 
30
- _defineProperty(this, "account", void 0);
103
+ log(`initializing client with params: baseUrl = ${baseUrl}, region = ${region}, account = ${account}`);
31
104
 
32
- _defineProperty(this, "region", void 0);
105
+ _classPrivateFieldSet(this, _baseUrl, baseUrl);
33
106
 
34
- log(`initializing client with params: baseUrl = ${baseUrl}, region = ${region}, account = ${account}`);
35
- this.baseUrl = baseUrl;
36
- this.account = account;
37
- this.region = region;
107
+ _classPrivateFieldSet(this, _accountName, account);
108
+
109
+ const initResult = (0, _amplifyCliUtils.initSDK)({
110
+ baseUrl: _classPrivateFieldGet(this, _baseUrl),
111
+ username: _classPrivateFieldGet(this, _accountName)
112
+ });
113
+
114
+ _classPrivateFieldSet(this, _amplifyConfig, initResult.config);
115
+
116
+ _classPrivateFieldSet(this, _amplifySdk, initResult.sdk);
117
+ }
118
+
119
+ async getAccountInfo() {
120
+ var _classPrivateFieldGet2;
121
+
122
+ // Get default teams from config.
123
+ const defaultTeams = _classPrivateFieldGet(this, _amplifyConfig).get(`${(0, _amplifyCliUtils.getAuthConfigEnvSpecifier)((_classPrivateFieldGet2 = _classPrivateFieldGet(this, _amplifySdk).env) === null || _classPrivateFieldGet2 === void 0 ? void 0 : _classPrivateFieldGet2.name)}.defaultTeam`); // Fetch specified account or default account currently logged in.
124
+
125
+
126
+ let accountInfo;
127
+
128
+ if (_classPrivateFieldGet(this, _accountName)) {
129
+ accountInfo = await _classPrivateFieldGet(this, _amplifySdk).auth.find(_classPrivateFieldGet(this, _accountName), defaultTeams);
130
+ } else {
131
+ const accountArray = await _classPrivateFieldGet(this, _amplifySdk).auth.list({
132
+ defaultTeams,
133
+ validate: true
134
+ });
135
+
136
+ if (accountArray && accountArray.length > 0) {
137
+ accountInfo = accountArray.find(nextAccount => nextAccount.default) || accountArray[0];
138
+ }
139
+ } // Make sure "subscriptions" is defined since Amplify SDK requires it. (Will throw error if missing.)
140
+
141
+
142
+ if (accountInfo && accountInfo.org && !accountInfo.org.subscriptions) {
143
+ accountInfo.org.subscriptions = [];
144
+ } // Return account info if found.
145
+
146
+
147
+ return accountInfo;
148
+ }
149
+
150
+ async createServiceAccount(options) {
151
+ const accountInfo = await this.getAccountInfo();
152
+ const result = await _classPrivateFieldGet(this, _amplifySdk).client.create(accountInfo, accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.org, options);
153
+ return result.client;
154
+ }
155
+
156
+ async getServiceAccounts() {
157
+ const result = await _classPrivateFieldGet(this, _amplifySdk).client.list(await this.getAccountInfo());
158
+ return result.clients || [];
38
159
  }
39
160
 
40
161
  async getTeams() {
@@ -46,9 +167,9 @@ class PlatformClient {
46
167
 
47
168
  try {
48
169
  const service = await (0, _dataService.dataService)({
49
- baseUrl: this.baseUrl,
170
+ baseUrl: _classPrivateFieldGet(this, _baseUrl),
50
171
  basePath: _types.BasePaths.Platform,
51
- account: this.account
172
+ account: _classPrivateFieldGet(this, _accountName)
52
173
  }); // Not using "getWithPagination" method here because /teams API does not support pagination
53
174
 
54
175
  const response = await service.get('/team');
@@ -84,6 +84,36 @@ const handleResponse = response => {
84
84
  return /application\/json/.test(response.headers['content-type']) ? JSON.parse(response.body) : response.body;
85
85
  };
86
86
 
87
+ const updateRequestError = err => {
88
+ var _err$response;
89
+
90
+ // Do not change given object if it's a timeout error.
91
+ if (err instanceof _got.TimeoutError) {
92
+ return;
93
+ } // If we have a JSON HTTP body, then turn it into a dictionary.
94
+
95
+
96
+ let jsonBody = null;
97
+
98
+ if (err instanceof _got.RequestError && (_err$response = err.response) !== null && _err$response !== void 0 && _err$response.body) {
99
+ jsonBody = handleResponse(err.response);
100
+ } // Turn given Error object into an "ApiServerError" or "ApiServerErrorResponse" object.
101
+
102
+
103
+ if (!jsonBody) {
104
+ // No response message received. Could be any kind of exception error.
105
+ // Turn given error into an "ApiServerErrorResponse" object.
106
+ err.errors = [err];
107
+ } else if (typeof jsonBody.code === 'number' && typeof jsonBody.description === 'string') {
108
+ // We received a "Platform" server error response.
109
+ err.status = jsonBody.code;
110
+ err.detail = jsonBody.description;
111
+ } else {
112
+ // Assume we received a "Central" server error response which should already conform to "ApiServerError".
113
+ Object.assign(err, jsonBody);
114
+ }
115
+ };
116
+
87
117
  const dataService = async ({
88
118
  account,
89
119
  baseUrl,
@@ -124,14 +154,7 @@ const dataService = async ({
124
154
 
125
155
  return response;
126
156
  } catch (err) {
127
- if (!(err instanceof _got.TimeoutError)) {
128
- var _err$response;
129
-
130
- Object.assign(err, ((_err$response = err.response) === null || _err$response === void 0 ? void 0 : _err$response.body) && handleResponse(err.response) || {
131
- errors: [err]
132
- });
133
- }
134
-
157
+ updateRequestError(err);
135
158
  throw err;
136
159
  }
137
160
  };
@@ -250,14 +273,7 @@ const dataService = async ({
250
273
  stream.on('error', reject);
251
274
  });
252
275
  } catch (err) {
253
- if (!(err instanceof _got.TimeoutError)) {
254
- var _err$response2;
255
-
256
- Object.assign(err, ((_err$response2 = err.response) === null || _err$response2 === void 0 ? void 0 : _err$response2.body) && handleResponse(err.response) || {
257
- errors: [err]
258
- });
259
- }
260
-
276
+ updateRequestError(err);
261
277
  throw err;
262
278
  }
263
279
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axway/axway-central-cli",
3
- "version": "2.4.1",
3
+ "version": "2.5.3",
4
4
  "description": "Manage APIs, services and publish to the Unified Catalog",
5
5
  "homepage": "https://platform.axway.com",
6
6
  "author": {
@@ -41,7 +41,7 @@
41
41
  "name": "central"
42
42
  },
43
43
  "dependencies": {
44
- "@axway/amplify-cli-utils": "^5.0.2",
44
+ "@axway/amplify-cli-utils": "^5.0.3",
45
45
  "chalk": "^4.1.2",
46
46
  "cli-kit": "^1.14.1",
47
47
  "dayjs": "^1.10.7",
@@ -1,114 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ApiCentralClient = void 0;
7
-
8
- var _snooplogg = _interopRequireDefault(require("snooplogg"));
9
-
10
- var _dataService = require("./dataService");
11
-
12
- var _types = require("./types");
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- 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; }
17
-
18
- const {
19
- log
20
- } = (0, _snooplogg.default)('central:class.ApiCentralClient');
21
-
22
- class ApiCentralClient {
23
- constructor({
24
- baseUrl,
25
- region,
26
- account
27
- }) {
28
- _defineProperty(this, "baseUrl", void 0);
29
-
30
- _defineProperty(this, "region", void 0);
31
-
32
- _defineProperty(this, "account", void 0);
33
-
34
- log(`initializing client with params: baseUrl = ${baseUrl}, region = ${region}, account = ${account}`);
35
- this.baseUrl = baseUrl;
36
- this.account = account;
37
- this.region = region;
38
- }
39
- /**
40
- * Create DOSA account.
41
- * @param accountName name of dosa account (can be non-unique)
42
- * @param publicKey public .pem file content
43
- */
44
-
45
-
46
- async createDOSAAccount(accountName, publicKey) {
47
- log(`createDOSAAccount`);
48
- const result = {
49
- data: null,
50
- error: null
51
- };
52
-
53
- try {
54
- const service = await (0, _dataService.dataService)({
55
- baseUrl: this.baseUrl,
56
- basePath: _types.BasePaths.ApiCentral,
57
- account: this.account,
58
- region: this.region
59
- });
60
- const payload = {
61
- generateKeypair: false,
62
- pemEncodedPublicKey: publicKey.replace(/(\r\n)/gm, '\n'),
63
- serviceAccountName: accountName,
64
- serviceAccountType: 'DOSA'
65
- };
66
- const response = await service.post('/serviceAccounts', payload);
67
- result.data = response;
68
- } catch (e) {
69
- log('createDOSAAccount, error: ', e); // expecting only a valid ApiServer error response here
70
- // re-throw if something different, so it should be handled by command's catch block.
71
-
72
- if (e.errors && Array.isArray(e.errors)) {
73
- result.error = e.errors;
74
- } else throw e;
75
- }
76
-
77
- return result;
78
- }
79
- /**
80
- * List service accounts.
81
- */
82
-
83
-
84
- async getServiceAccounts() {
85
- log(`getServiceAccounts`);
86
- const result = {
87
- data: null,
88
- error: null
89
- };
90
-
91
- try {
92
- const service = await (0, _dataService.dataService)({
93
- baseUrl: this.baseUrl,
94
- basePath: _types.BasePaths.ApiCentral,
95
- account: this.account,
96
- region: this.region
97
- });
98
- const response = await service.getWithPagination(`/serviceAccounts`, 'type==SA&sort=modifyTime%2CDESC');
99
- result.data = response;
100
- } catch (e) {
101
- log('getServiceAccounts, error: ', e); // expecting only a valid ApiServer error response here
102
- // re-throw if something different, so it should be handled by command's catch block.
103
-
104
- if (e.errors && Array.isArray(e.errors)) {
105
- result.error = e.errors;
106
- } else throw e;
107
- }
108
-
109
- return result;
110
- }
111
-
112
- }
113
-
114
- exports.ApiCentralClient = ApiCentralClient;