@axway/axway-central-cli 2.3.0 → 2.5.1

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.
@@ -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`));
@@ -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.'));
@@ -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');
@@ -44,18 +44,23 @@ class ApiServerClient {
44
44
  * Init temporary file if "data" is provided - write data to file (as YAML at the moment)
45
45
  * @param {object} data optional data to write while creating file
46
46
  */
47
- constructor(baseUrl, clientId, region, useCache) {
47
+ constructor({
48
+ baseUrl,
49
+ region,
50
+ account,
51
+ useCache
52
+ } = {}) {
48
53
  _defineProperty(this, "baseUrl", void 0);
49
54
 
50
- _defineProperty(this, "clientId", void 0);
51
-
52
55
  _defineProperty(this, "region", void 0);
53
56
 
54
57
  _defineProperty(this, "useCache", void 0);
55
58
 
56
- log(`initializing client with params: baseUrl = ${baseUrl}, clientId = ${clientId}, region = ${region}, useCache = ${useCache}`);
59
+ _defineProperty(this, "account", void 0);
60
+
61
+ log(`initializing client with params: baseUrl = ${baseUrl}, region = ${region}, account = ${account}, useCache = ${useCache}`);
57
62
  this.baseUrl = baseUrl;
58
- this.clientId = clientId;
63
+ this.account = account;
59
64
  this.region = region;
60
65
  this.useCache = useCache === undefined ? true : useCache; // using cache by default
61
66
  }
@@ -105,8 +110,8 @@ class ApiServerClient {
105
110
 
106
111
  const service = await (0, _dataService.dataService)({
107
112
  baseUrl: this.baseUrl,
108
- clientId: this.clientId,
109
- region: this.region
113
+ region: this.region,
114
+ account: this.account
110
115
  });
111
116
  const baseUrl = this.buildResourceBaseUrl({
112
117
  resourceDef,
@@ -232,8 +237,8 @@ class ApiServerClient {
232
237
  try {
233
238
  const service = await (0, _dataService.dataService)({
234
239
  baseUrl: this.baseUrl,
235
- clientId: this.clientId,
236
- region: this.region
240
+ region: this.region,
241
+ account: this.account
237
242
  });
238
243
  const url = this.buildResourceBaseUrl({
239
244
  resourceDef,
@@ -305,8 +310,8 @@ class ApiServerClient {
305
310
  try {
306
311
  const service = await (0, _dataService.dataService)({
307
312
  baseUrl: this.baseUrl,
308
- clientId: this.clientId,
309
- region: this.region
313
+ region: this.region,
314
+ account: this.account
310
315
  });
311
316
  const url = this.buildResourceBaseUrl({
312
317
  resourceDef,
@@ -378,8 +383,8 @@ class ApiServerClient {
378
383
  try {
379
384
  const service = await (0, _dataService.dataService)({
380
385
  baseUrl: this.baseUrl,
381
- clientId: this.clientId,
382
- region: this.region
386
+ region: this.region,
387
+ account: this.account
383
388
  });
384
389
  const url = this.buildResourceBaseUrl({
385
390
  resourceDef,
@@ -457,8 +462,8 @@ class ApiServerClient {
457
462
  try {
458
463
  const service = await (0, _dataService.dataService)({
459
464
  baseUrl: this.baseUrl,
460
- clientId: this.clientId,
461
- region: this.region
465
+ region: this.region,
466
+ account: this.account
462
467
  });
463
468
  const url = this.buildResourceBaseUrl({
464
469
  resourceDef,
@@ -507,8 +512,8 @@ class ApiServerClient {
507
512
  try {
508
513
  const service = await (0, _dataService.dataService)({
509
514
  baseUrl: this.baseUrl,
510
- clientId: this.clientId,
511
- region: this.region
515
+ region: this.region,
516
+ account: this.account
512
517
  });
513
518
  const url = this.buildResourceBaseUrl({
514
519
  resourceDef,
@@ -544,8 +549,8 @@ class ApiServerClient {
544
549
  const specs = {};
545
550
  const service = await (0, _dataService.dataService)({
546
551
  baseUrl: this.baseUrl,
547
- clientId: this.clientId,
548
- region: this.region
552
+ region: this.region,
553
+ account: this.account
549
554
  });
550
555
  const groups = await service.getWithPagination(`/definitions/${version}/groups`);
551
556
 
@@ -23,10 +23,11 @@ exports.CliConfigKeys = CliConfigKeys;
23
23
  (function (CliConfigKeys) {
24
24
  CliConfigKeys["APIC_DEPLOYMENT"] = "apic-deployment";
25
25
  CliConfigKeys["BASE_URL"] = "base-url";
26
- CliConfigKeys["CLIENT_ID"] = "client-id";
26
+ CliConfigKeys["ACCOUNT"] = "account";
27
27
  CliConfigKeys["REGION"] = "region";
28
28
  CliConfigKeys["PLATFORM"] = "platform";
29
29
  CliConfigKeys["EXTENSIONS"] = "extensions";
30
+ CliConfigKeys["CLIENT_ID"] = "client-id";
30
31
  })(CliConfigKeys || (exports.CliConfigKeys = CliConfigKeys = {}));
31
32
 
32
33
  class CliConfigManager {
@@ -34,7 +35,26 @@ class CliConfigManager {
34
35
  (0, _fsExtra.outputJsonSync)(CliConfigManager.configFilePath, values, {
35
36
  spaces: '\t'
36
37
  });
37
- } // Note: current validation is good for "unset" but for set its needed to validate the value for "extensions" (should be non-empty)
38
+ }
39
+ /**
40
+ * Temporary validator for config file content. Needed only to cleanup some values from config files for a couple of
41
+ * versions, remove it after some time.
42
+ */
43
+
44
+
45
+ validateSavedConfigKeys() {
46
+ const deprecatedKeys = [// TODO: a few other configs might be getting deprecated: https://jira.axway.com/browse/APIGOV-19737
47
+ // CliConfigKeys.PLATFORM,
48
+ CliConfigKeys.CLIENT_ID];
49
+ const keysToRemove = Object.keys(this.getAll()).filter(key => deprecatedKeys.includes(key));
50
+
51
+ if (keysToRemove.length) {
52
+ throw Error(`Following Axway Central CLI config keys has been deprecated and no longer needed: ${keysToRemove.join(', ')}
53
+ Please unset by running:
54
+ ${keysToRemove.map(key => `axway central config unset ${key}`).join('\n')}
55
+ `);
56
+ }
57
+ } // Note: current validation is good for "unset" but for "set" its needed to validate the value for "extensions" (should be non-empty)
38
58
 
39
59
 
40
60
  validate(key) {
@@ -28,61 +28,83 @@ const {
28
28
  class CoreConfigController {
29
29
  /**
30
30
  * Get authentication info
31
- * @param clientId client id to use, if not provided and nothing stored in Central CLI configs "amplify-cli" is used by default
32
- * @returns object containing token and orgId. For DOSA accounts orgId is undefined.
31
+ * @param clientId client id to use
32
+ * @returns object containing token and orgId. For service accounts orgId is undefined.
33
33
  * @throws 401 if no authenticated account found.
34
34
  */
35
35
  async getAuthInfo({
36
- accountName,
36
+ account,
37
37
  clientId
38
38
  } = {}) {
39
39
  var _CoreConfigController;
40
40
 
41
- const configCtrl = new _CliConfigManager.CliConfigManager();
42
- const devOpsClientId = clientId ? clientId : configCtrl.get(_CliConfigManager.CliConfigKeys.CLIENT_ID) || _types.defaultClientId;
43
- log(`getAuthInfo, using clientId = ${devOpsClientId}, accountName = ${accountName}`);
41
+ const configCtrl = new _CliConfigManager.CliConfigManager(); // note: remove this validator after couple of versions
44
42
 
45
- if (!CoreConfigController.devOpsAccount || CoreConfigController.devOpsAccount.auth.clientId !== devOpsClientId) {
46
- log(`getAuthInfo, no cached devOpsAccount found, or clientId does not match`);
47
- const baseUrl = configCtrl.get(_CliConfigManager.CliConfigKeys.BASE_URL);
48
- const platform = configCtrl.get(_CliConfigManager.CliConfigKeys.PLATFORM); // environment defined by using central cli "platform" or "base-url" configs if set,
43
+ configCtrl.validateSavedConfigKeys();
44
+ log(`getAuthInfo, received clientId = ${clientId}, account = ${account}`);
45
+
46
+ if (!CoreConfigController.devOpsAccount || account && CoreConfigController.devOpsAccount.name !== account) {
47
+ log(`getAuthInfo, no cached devOpsAccount found, or account name does not match`);
48
+ const baseUrl = configCtrl.get(_CliConfigManager.CliConfigKeys.BASE_URL); // environment defined by using central cli "base-url" or axway "env" configs if set,
49
49
  // otherwise its undefined (equals to prod)
50
50
 
51
- const env = platform || (!baseUrl || baseUrl === _types.ProdBaseUrls.US || baseUrl === _types.ProdBaseUrls.EU ? undefined : 'preprod');
52
- log(`getAuthInfo, baseUrl = ${baseUrl}, platform = ${platform}, env = ${env}`);
51
+ const environment = !baseUrl || baseUrl === _types.ProdBaseUrls.US || baseUrl === _types.ProdBaseUrls.EU ? this.getConfig('env') : 'preprod';
52
+ log(`getAuthInfo, baseUrl = ${baseUrl}, environment = ${environment}`);
53
53
  const {
54
54
  config,
55
55
  sdk
56
56
  } = (0, _amplifyCliUtils.initSDK)({
57
- clientId: devOpsClientId,
58
- env
59
- }); // TODO: filtering by the clientId will not be needed when https://jira.axway.com/browse/APIGOV-20702 is fixed
60
-
61
- const list = (await sdk.auth.list()).filter(a => a.auth.clientId === devOpsClientId);
62
- log(`getAuthInfo, matching accounts found: ${list.length}`);
63
-
64
- if (list.length > 1) {
65
- // try to find the default one
66
- const defaultAccount = list.find(a => a.name === accountName || a.name === config.get('auth.defaultAccount'));
67
-
68
- if (defaultAccount) {
69
- CoreConfigController.devOpsAccount = await sdk.auth.find(defaultAccount.name);
70
- } else if (!accountName) {
71
- const selectedName = await (0, _basicPrompts.askList)({
72
- msg: 'Multiple authenticated accounts found, please select which one you want to use',
73
- choices: Array.from(new Set(list.map(a => a.name)))
74
- });
75
- console.log((0, _chalk.default)`{grey If you always want to use "${selectedName}" account by default, run: axway config set auth.defaultAccount ${selectedName}}\n`);
76
- CoreConfigController.devOpsAccount = await sdk.auth.find(selectedName);
57
+ env: environment
58
+ });
59
+
60
+ if (clientId) {
61
+ // TODO: client-id is a legacy option used only by proxies promote/create, should be removed
62
+ // https://jira.axway.com/browse/APIGOV-20818
63
+ log(`getAuthInfo, clientId value passed, trying to find a matching account`);
64
+ const list = await sdk.auth.list({
65
+ verify: true
66
+ });
67
+ const matchingAccount = list.find(a => a.auth.clientId === clientId);
68
+ if (matchingAccount) CoreConfigController.devOpsAccount = await sdk.auth.find(matchingAccount.name);
69
+ } else if (account) {
70
+ // ELSE IF: account name passed - ignoring defaultAccount and other accounts
71
+ log(`getAuthInfo, account value passed, trying to find a matching account`);
72
+ CoreConfigController.devOpsAccount = await sdk.auth.find(account);
73
+ } else {
74
+ // ELSE: trying to get any authenticated account
75
+ log(`getAuthInfo, account value not passed, trying to find default/any match`);
76
+ const list = await sdk.auth.list({
77
+ verify: true
78
+ });
79
+ log(`getAuthInfo, authenticated accounts found: ${list.length}`);
80
+
81
+ if (list.length === 1) {
82
+ log(`getAuthInfo, using a single account found with name: ${list[0].name}`);
83
+ CoreConfigController.devOpsAccount = await sdk.auth.find(list[0].name);
84
+ } else if (list.length > 1) {
85
+ // try to find the default account
86
+ const defaultAccount = list.find(a => a.name === config.get('auth.defaultAccount'));
87
+
88
+ if (defaultAccount) {
89
+ log(`getAuthInfo, match found for defaultAccount, refreshing its token`);
90
+ CoreConfigController.devOpsAccount = await sdk.auth.find(defaultAccount.name);
91
+ } else {
92
+ log(`getAuthInfo, no match found for defaultAccount`);
93
+ const selectedName = await (0, _basicPrompts.askList)({
94
+ msg: 'Multiple authenticated accounts found, please select which one you want to use',
95
+ choices: Array.from(new Set(list.map(a => a.name)))
96
+ });
97
+ console.log((0, _chalk.default)`{grey If you always want to use this account by default, run:\naxway config set auth.defaultAccount ${selectedName}}\n`);
98
+ log(`getAuthInfo, refreshing token for selected account: ${selectedName}`);
99
+ CoreConfigController.devOpsAccount = await sdk.auth.find(selectedName);
100
+ }
77
101
  }
78
- } else if (list.length === 1) {
79
- CoreConfigController.devOpsAccount = await sdk.auth.find(accountName || list[0].name);
80
102
  }
81
103
 
82
104
  if (!CoreConfigController.devOpsAccount) {
83
105
  // TODO: piece of old logic here, move throwing out of the method?
84
106
  // temporary commenting out the new functionality and reverting back to the old one, will be fixed with:
85
- // https://jira.axway.com/browse/APIGOV-20818
107
+ // https://jira.axway.com/browse/APIGOV-20520
86
108
  log(`getAuthInfo, no devOpsAccount set after all, throwing 401`); // const title: string = accountName
87
109
  // ? `Account "${accountName}" cannot be found`
88
110
  // : 'No authenticated accounts found.';
@@ -93,14 +115,14 @@ class CoreConfigController {
93
115
  throw {
94
116
  errors: [{
95
117
  status: 401,
96
- title: accountName ? `Account "${accountName}" cannot be found` : 'No authenticated accounts found.'
118
+ title: account ? `Account "${account}" cannot be found` : 'No authenticated accounts found.'
97
119
  }]
98
120
  };
99
121
  }
100
122
  }
101
123
 
102
124
  const token = CoreConfigController.devOpsAccount.auth.tokens.access_token;
103
- const orgId = (devOpsClientId === null || devOpsClientId === void 0 ? void 0 : devOpsClientId.substring(0, 5)) === 'DOSA_' ? undefined : `${CoreConfigController.devOpsAccount.org.id}`;
125
+ const orgId = CoreConfigController.devOpsAccount.isPlatform ? `${CoreConfigController.devOpsAccount.org.id}` : undefined;
104
126
  const orgRegion = (_CoreConfigController = CoreConfigController.devOpsAccount.org) === null || _CoreConfigController === void 0 ? void 0 : _CoreConfigController.region;
105
127
  log(`getAuthInfo, returning account = ${CoreConfigController.devOpsAccount.name}`);
106
128
  log(`getAuthInfo, returning token = ${token.substring(0, 5)}*****${token.substring(token.length - 5)}`);
@@ -113,14 +135,15 @@ class CoreConfigController {
113
135
  };
114
136
  }
115
137
  /**
116
- * Get all config from core cli.
117
- * @returns entire object with core cli config.
138
+ * Get all or specific config value from core cli.
139
+ * @returns entire object config or a specific value if key passed.
118
140
  */
119
141
 
120
142
 
121
- getConfig() {
122
- log(`getConfig`);
123
- return (0, _amplifyCliUtils.loadConfig)().get();
143
+ getConfig(key) {
144
+ log(`getConfig, key = ${key}`); // note: not using loadConfig().get(key) because of config mocks setup for tests.
145
+
146
+ return key ? (0, _amplifyCliUtils.loadConfig)().get()[key] : (0, _amplifyCliUtils.loadConfig)().get();
124
147
  }
125
148
 
126
149
  static getEnv() {
@@ -20,16 +20,20 @@ const {
20
20
  } = (0, _snooplogg.default)('central:class.PlatformClient');
21
21
 
22
22
  class PlatformClient {
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);
30
+ _defineProperty(this, "account", void 0);
27
31
 
28
32
  _defineProperty(this, "region", void 0);
29
33
 
30
- log(`initializing client with params: baseUrl = ${baseUrl}, clientId = ${clientId}, region = ${region}`);
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
 
@@ -44,7 +48,7 @@ class PlatformClient {
44
48
  const service = await (0, _dataService.dataService)({
45
49
  baseUrl: this.baseUrl,
46
50
  basePath: _types.BasePaths.Platform,
47
- clientId: this.clientId
51
+ account: this.account
48
52
  }); // Not using "getWithPagination" method here because /teams API does not support pagination
49
53
 
50
54
  const response = await service.get('/team');
@@ -241,13 +241,16 @@ class Renderer {
241
241
  if ((this.output === _types.OutputTypes.json || this.output === _types.OutputTypes.yaml) && !ignoreOutputParam) {
242
242
  // IF output param has been provided and ignoreOutputParam is not set - render the error in the yaml or json format.
243
243
  // Rendering ApiServer errors as-is, other errors as { name, message } object.
244
- const err = (0, _utils.isApiServerErrorType)(error) || (0, _utils.isApiServerErrorResponseType)(error) ? error : {
244
+ const err = (0, _utils.isApiServerErrorType)(error) || (0, _utils.isApiServerErrorResponseType)(error) ? // note: direct catch of "dataService" methods returns "got" error, which is an instance of Error
245
+ // AND isApiServerErrorResponseType === true with error.name === 'HTTPError'. So trying to get "errors"
246
+ // array or error as-is
247
+ error instanceof Error && error.name === 'HTTPError' && error.errors ? error.errors : error : {
245
248
  name: error.name,
246
249
  message: error.message
247
250
  };
248
251
  (0, _resultsRenderers.renderResponse)(this._console, err, this.output);
249
- } else if (error instanceof Error) {
250
- // ELSE IF some generic error is happening
252
+ } else if (error instanceof Error && error.name !== 'HTTPError') {
253
+ // ELSE IF some generic error is happening (and its not an instance of "got" HTTPError)
251
254
  const message = error.name === 'AbortError' ? `Error: couldn't connect to Amplify Central` : `${error.name}: ${error.message}`;
252
255
  this.error(message);
253
256
  } else {
@@ -264,9 +267,6 @@ class Renderer {
264
267
  this.console((0, _cliKit.chalk)`{cyan axway auth login}`);
265
268
  this.console('Or if using a service account:');
266
269
  this.console((0, _cliKit.chalk)`{cyan axway auth login --client-id <Service Account Client ID> --secret-file <Private Key>}`);
267
- this.console((0, _cliKit.chalk)`{cyan axway central config set --client-id=<Service Account Client ID>}`);
268
- this.console(`Or if no longer using a service account:`);
269
- this.console((0, _cliKit.chalk)`{cyan axway central config unset client-id}`);
270
270
  break;
271
271
 
272
272
  case 400:
@@ -85,7 +85,7 @@ const handleResponse = response => {
85
85
  };
86
86
 
87
87
  const dataService = async ({
88
- accountName,
88
+ account,
89
89
  baseUrl,
90
90
  basePath = _types.BasePaths.ApiServer,
91
91
  clientId,
@@ -98,7 +98,7 @@ const dataService = async ({
98
98
  orgRegion,
99
99
  token
100
100
  } = await new _CoreConfigController.CoreConfigController().getAuthInfo({
101
- accountName,
101
+ account,
102
102
  clientId
103
103
  });
104
104
  const url = await getBaseUrl(baseUrl, basePath, region, orgRegion);