@axway/axway-central-cli 2.17.0-rc.5 → 2.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/dist/cli.js +28 -6
  2. package/dist/commands/apply/index.js +24 -9
  3. package/dist/commands/completion/index.js +9 -3
  4. package/dist/commands/config/common/index.js +11 -2
  5. package/dist/commands/config/index.js +7 -2
  6. package/dist/commands/config/list.js +6 -2
  7. package/dist/commands/config/set.js +31 -4
  8. package/dist/commands/config/unset.js +12 -2
  9. package/dist/commands/create/agentResource.js +32 -12
  10. package/dist/commands/create/environment.js +16 -6
  11. package/dist/commands/create/index.js +26 -9
  12. package/dist/commands/create/serviceAccount.js +6 -2
  13. package/dist/commands/delete/index.js +33 -15
  14. package/dist/commands/edit/environment.js +21 -6
  15. package/dist/commands/edit/index.js +8 -4
  16. package/dist/commands/get/index.js +44 -27
  17. package/dist/commands/install/agents.js +73 -44
  18. package/dist/commands/install/apigeexSaasAgents.js +98 -35
  19. package/dist/commands/install/awsAgents.js +139 -89
  20. package/dist/commands/install/awsSaasAgents.js +142 -50
  21. package/dist/commands/install/azureAgents.js +79 -39
  22. package/dist/commands/install/edgeAgents.js +110 -17
  23. package/dist/commands/install/helpers/creators.js +70 -17
  24. package/dist/commands/install/helpers/deleters.js +11 -2
  25. package/dist/commands/install/helpers/getters.js +30 -4
  26. package/dist/commands/install/helpers/index.js +48 -13
  27. package/dist/commands/install/helpers/inputs.js +98 -26
  28. package/dist/commands/install/helpers/regex.js +34 -29
  29. package/dist/commands/install/helpers/templates/awsTemplates.js +23 -6
  30. package/dist/commands/install/helpers/templates/azureTemplates.js +24 -5
  31. package/dist/commands/install/helpers/templates/edgeTemplates.js +38 -7
  32. package/dist/commands/install/helpers/templates/istioTemplates.js +16 -5
  33. package/dist/commands/install/index.js +10 -4
  34. package/dist/commands/install/istioAgents.js +117 -40
  35. package/dist/commands/install/platform.js +52 -20
  36. package/dist/commands/proxies/create.js +18 -2
  37. package/dist/commands/proxies/index.js +8 -4
  38. package/dist/commands/proxies/promote.js +21 -2
  39. package/dist/common/ApiServerClient.js +173 -64
  40. package/dist/common/CacheController.js +32 -11
  41. package/dist/common/CliConfigManager.js +27 -14
  42. package/dist/common/CompositeError.js +30 -6
  43. package/dist/common/CoreConfigController.js +40 -18
  44. package/dist/common/DefinitionsManager.js +76 -29
  45. package/dist/common/Kubectl.js +25 -2
  46. package/dist/common/PlatformClient.js +63 -19
  47. package/dist/common/Renderer.js +87 -25
  48. package/dist/common/TmpFile.js +28 -11
  49. package/dist/common/bashCommands.js +22 -3
  50. package/dist/common/basicPrompts.js +43 -8
  51. package/dist/common/dataService.js +50 -22
  52. package/dist/common/errorHandler.js +9 -0
  53. package/dist/common/resultsRenderers.js +42 -10
  54. package/dist/common/types.js +341 -116
  55. package/dist/common/utils.js +99 -37
  56. package/dist/main.js +2 -0
  57. package/package.json +2 -2
  58. package/dist/commands/install/gitHubSaasAgents.js +0 -283
@@ -4,22 +4,33 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.CacheController = void 0;
7
+
7
8
  var _dayjs = _interopRequireDefault(require("dayjs"));
9
+
8
10
  var _fsExtra = require("fs-extra");
11
+
9
12
  var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
13
+
10
14
  var _nodeCache = _interopRequireDefault(require("node-cache"));
15
+
11
16
  var _os = require("os");
17
+
12
18
  var _path = _interopRequireDefault(require("path"));
19
+
13
20
  var _snooplogg = _interopRequireDefault(require("snooplogg"));
21
+
14
22
  var _types = require("./types");
23
+
15
24
  var _utils = require("./utils");
25
+
16
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
18
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
19
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
27
+
28
+ 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; }
29
+
20
30
  const {
21
31
  log
22
32
  } = (0, _snooplogg.default)('central: CacheController');
33
+
23
34
  /**
24
35
  * Note: this file intentionally exporting only a single instance of CacheController,
25
36
  * since its possible to face a race condition when multiple instances will try to read/write file at the same time
@@ -28,22 +39,26 @@ const {
28
39
  class CacheControllerClass {
29
40
  constructor() {
30
41
  _defineProperty(this, "cacheFilePath", _path.default.join((0, _os.homedir)(), '.axway', 'central', 'cache.json'));
42
+
31
43
  _defineProperty(this, "cache", new _nodeCache.default());
44
+
32
45
  // note: init cache fire only once since using only a single instance of the class, remove if this will change
33
46
  this.initCacheFile();
34
47
  this.readFromFile();
35
48
  }
36
-
37
49
  /**
38
50
  * Inits and validate cache file, should run once before using this class in the code (initialized in cli.ts currently)
39
51
  * An empty JSON file will be created if it is not exists of the file size is more than some value.
40
52
  */
53
+
54
+
41
55
  initCacheFile() {
42
56
  try {
43
57
  if ((0, _fsExtra.pathExistsSync)(this.cacheFilePath)) {
44
58
  log(`init, cache file found at ${this.cacheFilePath}`);
45
59
  const stats = (0, _fsExtra.lstatSync)(this.cacheFilePath);
46
60
  log(`init, cache file size: ${Math.round(stats.size / 1000)} kb`);
61
+
47
62
  if (stats.size >= _types.MAX_CACHE_FILE_SIZE) {
48
63
  // validating the size
49
64
  log(`init, cache size is exceeding the max allowed size of ${Math.round(_types.MAX_CACHE_FILE_SIZE / 1000)} kb, resetting the file`);
@@ -61,40 +76,42 @@ class CacheControllerClass {
61
76
  log(`cannot initialize cache file`, e);
62
77
  }
63
78
  }
64
-
65
79
  /**
66
80
  * Set the key in memory cache.
67
81
  * @param key cache key to set
68
82
  * @param value value to set, note that setting "undefined" value will result in "null" value stored
69
83
  * @returns CacheController instance
70
84
  */
85
+
86
+
71
87
  set(key, value) {
72
88
  this.cache.set(key, value);
73
89
  return this;
74
90
  }
75
-
76
91
  /**
77
92
  * Returns the key value from the memory cache.
78
93
  * @param key key to get
79
94
  * @returns key value
80
95
  */
96
+
97
+
81
98
  get(key) {
82
99
  return this.cache.get(key);
83
100
  }
84
-
85
101
  /**
86
102
  * Load stored cache from the file into memory and checks its timestamp.
87
103
  * If the timestamp is more than X days old it will reset the file without any changes to cache.
88
104
  * Note: using this method before writeToFile() will override keys in memory cache with the same name.
89
105
  * @returns CacheController instance
90
106
  */
107
+
108
+
91
109
  readFromFile() {
92
110
  try {
93
111
  log('reading cache from the file');
94
112
  const jsonData = (0, _fsExtra.readFileSync)(this.cacheFilePath, 'utf8');
95
- const storedCache = JSON.parse(jsonData);
113
+ const storedCache = JSON.parse(jsonData); // validate values stored in the cache, reset the content of the file if its not empty already.
96
114
 
97
- // validate values stored in the cache, reset the content of the file if its not empty already.
98
115
  if (storedCache.data && storedCache.metadata && storedCache.metadata.modifyTimestamp && (0, _dayjs.default)().diff(storedCache.metadata.modifyTimestamp, 'milliseconds') < _types.CACHE_FILE_TTL_MILLISECONDS) {
99
116
  for (const [key, val] of Object.entries(storedCache.data)) {
100
117
  if (storedCache.data.hasOwnProperty(key)) {
@@ -111,7 +128,6 @@ class CacheControllerClass {
111
128
  return this;
112
129
  }
113
130
  }
114
-
115
131
  /**
116
132
  * Writes current set of keys to the json file with following structure:
117
133
  * {
@@ -123,6 +139,8 @@ class CacheControllerClass {
123
139
  * }
124
140
  * @returns CacheController instance
125
141
  */
142
+
143
+
126
144
  writeToFile() {
127
145
  try {
128
146
  log('writing cache to the file');
@@ -142,5 +160,8 @@ class CacheControllerClass {
142
160
  return this;
143
161
  }
144
162
  }
163
+
145
164
  }
146
- const CacheController = exports.CacheController = new CacheControllerClass();
165
+
166
+ const CacheController = new CacheControllerClass();
167
+ exports.CacheController = CacheController;
@@ -4,15 +4,23 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.CliConfigManager = exports.CliConfigKeys = void 0;
7
+
7
8
  var _fsExtra = require("fs-extra");
9
+
8
10
  var _unset2 = _interopRequireDefault(require("lodash/unset"));
11
+
9
12
  var _os = require("os");
13
+
10
14
  var _path = require("path");
15
+
11
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
14
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
15
- let CliConfigKeys = exports.CliConfigKeys = /*#__PURE__*/function (CliConfigKeys) {
17
+
18
+ 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; }
19
+
20
+ let CliConfigKeys;
21
+ exports.CliConfigKeys = CliConfigKeys;
22
+
23
+ (function (CliConfigKeys) {
16
24
  CliConfigKeys["APIC_DEPLOYMENT"] = "apic-deployment";
17
25
  CliConfigKeys["BASE_URL"] = "base-url";
18
26
  CliConfigKeys["ACCOUNT"] = "account";
@@ -20,34 +28,35 @@ let CliConfigKeys = exports.CliConfigKeys = /*#__PURE__*/function (CliConfigKeys
20
28
  CliConfigKeys["PLATFORM"] = "platform";
21
29
  CliConfigKeys["EXTENSIONS"] = "extensions";
22
30
  CliConfigKeys["CLIENT_ID"] = "client-id";
23
- return CliConfigKeys;
24
- }({});
31
+ })(CliConfigKeys || (exports.CliConfigKeys = CliConfigKeys = {}));
32
+
25
33
  class CliConfigManager {
26
34
  saveToFile(values) {
27
35
  (0, _fsExtra.outputJsonSync)(CliConfigManager.configFilePath, values, {
28
36
  spaces: '\t'
29
37
  });
30
38
  }
31
-
32
39
  /**
33
40
  * Temporary validator for config file content. Needed only to cleanup some values from config files for a couple of
34
41
  * versions, remove it after some time.
35
42
  */
43
+
44
+
36
45
  validateSavedConfigKeys() {
37
- const deprecatedKeys = [
38
- // TODO: a few other configs might be getting deprecated: https://jira.axway.com/browse/APIGOV-19737
46
+ const deprecatedKeys = [// TODO: a few other configs might be getting deprecated: https://jira.axway.com/browse/APIGOV-19737
39
47
  // CliConfigKeys.PLATFORM,
40
48
  CliConfigKeys.CLIENT_ID];
41
49
  const keysToRemove = Object.keys(this.getAll()).filter(key => deprecatedKeys.includes(key));
50
+
42
51
  if (keysToRemove.length) {
43
52
  throw Error(`Following Axway Central CLI config keys has been deprecated and no longer needed: ${keysToRemove.join(', ')}
44
53
  Please unset by running:
45
54
  ${keysToRemove.map(key => `axway central config unset ${key}`).join('\n')}
46
55
  `);
47
56
  }
48
- }
57
+ } // Note: current validation is good for "unset" but for "set" its needed to validate the value for "extensions" (should be non-empty)
58
+
49
59
 
50
- // Note: current validation is good for "unset" but for "set" its needed to validate the value for "extensions" (should be non-empty)
51
60
  validate(key) {
52
61
  // validate 'extensions' keys - should alway have dot in the mid: extensions.abc
53
62
  if (key.startsWith(`${CliConfigKeys.EXTENSIONS}`)) {
@@ -56,21 +65,25 @@ ${keysToRemove.map(key => `axway central config unset ${key}`).join('\n')}
56
65
  throw Error(`central configuration doesn't support the "${key}" key.`);
57
66
  }
58
67
  }
68
+
59
69
  getAll() {
60
70
  return (0, _fsExtra.existsSync)(CliConfigManager.configFilePath) ? (0, _fsExtra.readJsonSync)(CliConfigManager.configFilePath) : {};
61
71
  }
72
+
62
73
  get(key) {
63
74
  return this.getAll()[key];
64
- }
65
-
66
- // TODO
75
+ } // TODO
67
76
  // set(key: CentralConfigKeys) {}
68
77
 
78
+
69
79
  unset(key) {
70
80
  const config = this.getAll();
71
81
  (0, _unset2.default)(config, key);
72
82
  this.saveToFile(config);
73
83
  }
84
+
74
85
  }
86
+
75
87
  exports.CliConfigManager = CliConfigManager;
88
+
76
89
  _defineProperty(CliConfigManager, "configFilePath", (0, _path.join)((0, _os.homedir)(), '.axway', 'central.json'));
@@ -4,18 +4,29 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.CompositeError = void 0;
7
+
7
8
  function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
9
+
8
10
  function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
11
+
9
12
  function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
13
+
10
14
  function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
15
+
11
16
  function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
17
+
12
18
  function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
19
+
13
20
  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; } }
21
+
14
22
  var _nestedErrors = /*#__PURE__*/new WeakMap();
23
+
15
24
  /** This type is returnd by the CompositeError.toDictionary() method. Intended to be outputted to JSON or YAML. */
16
25
 
17
26
  /** Error object which can provide nested errors to indicated if multiple errors have occurred. */
18
27
  class CompositeError extends Error {
28
+ /** Array of errors wrapped by this error object. */
29
+
19
30
  /**
20
31
  * Creates a new error wrapping the given array of errors.
21
32
  * @param errors Array of errors to be owned by this composite error. Can contain CompositeError instances.
@@ -23,35 +34,40 @@ class CompositeError extends Error {
23
34
  */
24
35
  constructor(errors, message) {
25
36
  super(message);
26
- /** Array of errors wrapped by this error object. */
37
+
27
38
  _classPrivateFieldInitSpec(this, _nestedErrors, {
28
39
  writable: true,
29
40
  value: void 0
30
41
  });
42
+
31
43
  _classPrivateFieldSet(this, _nestedErrors, errors);
32
44
  }
33
-
34
45
  /** Gets the name of this error type. */
46
+
47
+
35
48
  get name() {
36
49
  return 'CompositeError';
37
50
  }
38
-
39
51
  /** Gets an array of error objects owned by this composite error. */
52
+
53
+
40
54
  get nestedErrors() {
41
55
  return _classPrivateFieldGet(this, _nestedErrors);
42
56
  }
43
-
44
57
  /**
45
58
  * Creates a dictionary providing the name, message, and array of all errors nested under this error object.
46
59
  * Intended to be outputted to JSON or YAML.
47
60
  * @returns Returns a dictionary of this error object and all nested error objects.
48
61
  */
62
+
63
+
49
64
  toDictionary() {
50
65
  const dictionary = {
51
66
  name: this.name,
52
67
  message: this.message,
53
68
  nestedErrors: []
54
69
  };
70
+
55
71
  for (const nextError of _classPrivateFieldGet(this, _nestedErrors)) {
56
72
  if (nextError instanceof CompositeError) {
57
73
  dictionary.nestedErrors.push(nextError.toDictionary());
@@ -62,19 +78,23 @@ class CompositeError extends Error {
62
78
  });
63
79
  }
64
80
  }
81
+
65
82
  return dictionary;
66
83
  }
67
-
68
84
  /**
69
85
  * Creates an array of strings providing this object's error message and all of its nested error messages.
70
86
  * Each error object's message is added to its own array entry and will be indented according to nested position.
71
87
  * @returns Returns an array of all error messages that are indented according to their nested position.
72
88
  */
89
+
90
+
73
91
  toNestedMessageArray() {
74
92
  const messageLines = [];
93
+
75
94
  if (this.message) {
76
95
  messageLines.push(this.message);
77
96
  }
97
+
78
98
  for (const nextError of _classPrivateFieldGet(this, _nestedErrors)) {
79
99
  if (nextError instanceof CompositeError) {
80
100
  for (const nextLine of nextError.toNestedMessageArray()) {
@@ -85,16 +105,20 @@ class CompositeError extends Error {
85
105
  messageLines.push(`- ${nextError.message || 'Unknown error'}`);
86
106
  }
87
107
  }
108
+
88
109
  return messageLines;
89
110
  }
90
-
91
111
  /**
92
112
  * Creates an error message containing this object's message and all nested error messages separated by newlines
93
113
  * and indented according to their nested position.
94
114
  * @returns Returns a single string containing all nested error messages separated by newlines.
95
115
  */
116
+
117
+
96
118
  toNestedMessageString() {
97
119
  return this.toNestedMessageArray().join('\n');
98
120
  }
121
+
99
122
  }
123
+
100
124
  exports.CompositeError = CompositeError;
@@ -4,23 +4,30 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.CoreConfigController = exports.AccountRole = void 0;
7
+
7
8
  var _amplifyCliUtils = require("@axway/amplify-cli-utils");
9
+
8
10
  var _snooplogg = _interopRequireDefault(require("snooplogg"));
11
+
9
12
  var _CliConfigManager = require("./CliConfigManager");
13
+
10
14
  var _types = require("./types");
15
+
11
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
14
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
17
+
18
+ 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; }
19
+
15
20
  const {
16
21
  log
17
- } = (0, _snooplogg.default)('central: CoreConfigController');
18
-
19
- // TODO: https://jira.axway.com/browse/APIGOV-20520
22
+ } = (0, _snooplogg.default)('central: CoreConfigController'); // TODO: https://jira.axway.com/browse/APIGOV-20520
20
23
  // interface AuthenticationError extends Error {
21
24
  // errors?: Array<object>;
22
25
  // }
23
- let AccountRole = exports.AccountRole = /*#__PURE__*/function (AccountRole) {
26
+
27
+ let AccountRole;
28
+ exports.AccountRole = AccountRole;
29
+
30
+ (function (AccountRole) {
24
31
  AccountRole["AnalyticsSpecialist"] = "analytics_specialist";
25
32
  AccountRole["ApiCentralAdmin"] = "api_central_admin";
26
33
  AccountRole["FileTransferServicesAdmin"] = "fts_admin";
@@ -40,8 +47,8 @@ let AccountRole = exports.AccountRole = /*#__PURE__*/function (AccountRole) {
40
47
  AccountRole["PlatformDeveloper"] = "developer";
41
48
  AccountRole["PlatformReadOnly"] = "read_only";
42
49
  AccountRole["RuntimeServicesAdmin"] = "ars_admin";
43
- return AccountRole;
44
- }({});
50
+ })(AccountRole || (exports.AccountRole = AccountRole = {}));
51
+
45
52
  class CoreConfigController {
46
53
  /**
47
54
  * Get authentication info
@@ -57,16 +64,15 @@ class CoreConfigController {
57
64
  team
58
65
  } = {}) {
59
66
  var _devOpsAccount, _devOpsAccount$org, _devOpsAccount$org$id, _devOpsAccount$org2;
67
+
60
68
  const configCtrl = new _CliConfigManager.CliConfigManager();
61
- const config = (0, _amplifyCliUtils.loadConfig)();
69
+ const config = (0, _amplifyCliUtils.loadConfig)(); // note: remove this validator after couple of versions
62
70
 
63
- // note: remove this validator after couple of versions
64
71
  configCtrl.validateSavedConfigKeys();
65
72
  log(`getAuthInfo, received clientId = ${clientId}, account = ${account}, team = ${team}`);
66
- const baseUrl = process.env.AXWAY_CENTRAL_BASE_URL || configCtrl.get(_CliConfigManager.CliConfigKeys.BASE_URL);
67
-
68
- // environment defined by using central cli "base-url" or axway "env" configs if set,
73
+ const baseUrl = process.env.AXWAY_CENTRAL_BASE_URL || configCtrl.get(_CliConfigManager.CliConfigKeys.BASE_URL); // environment defined by using central cli "base-url" or axway "env" configs if set,
69
74
  // otherwise its undefined (equals to prod)
75
+
70
76
  const environment = !baseUrl || baseUrl === _types.ProdBaseUrls.US || baseUrl === _types.ProdBaseUrls.EU || baseUrl === _types.ProdBaseUrls.AP ? config.get('env') : 'staging';
71
77
  log(`getAuthInfo, baseUrl = ${baseUrl}, environment = ${environment}`);
72
78
  const {
@@ -77,8 +83,10 @@ class CoreConfigController {
77
83
  let {
78
84
  devOpsAccount
79
85
  } = CoreConfigController;
86
+
80
87
  if (!devOpsAccount || account && devOpsAccount.name !== account) {
81
88
  log(`getAuthInfo, no cached devOpsAccount found, or account name does not match`);
89
+
82
90
  if (clientId) {
83
91
  // TODO: client-id is a legacy option used only by proxies promote/create, should be removed
84
92
  // https://jira.axway.com/browse/APIGOV-20818
@@ -87,6 +95,7 @@ class CoreConfigController {
87
95
  validate: true
88
96
  });
89
97
  const matchingAccount = list.find(a => a.auth.clientId === clientId);
98
+
90
99
  if (matchingAccount) {
91
100
  devOpsAccount = await sdk.auth.find(matchingAccount.name);
92
101
  }
@@ -101,6 +110,7 @@ class CoreConfigController {
101
110
  validate: true
102
111
  });
103
112
  log(`getAuthInfo, authenticated accounts found: ${list.length}`);
113
+
104
114
  if (list.length === 1) {
105
115
  log(`getAuthInfo, using a single account found with name: ${list[0].name}`);
106
116
  devOpsAccount = list[0];
@@ -109,17 +119,18 @@ class CoreConfigController {
109
119
  devOpsAccount = list.find(a => a.name === config.get('auth.defaultAccount')) || list.find(a => a.default) || list[0];
110
120
  }
111
121
  }
122
+
112
123
  if (!devOpsAccount) {
113
124
  // TODO: piece of old logic here, move throwing out of the method?
114
125
  // temporary commenting out the new functionality and reverting back to the old one, will be fixed with:
115
126
  // https://jira.axway.com/browse/APIGOV-20520
116
- log(`getAuthInfo, no devOpsAccount set after all, throwing 401`);
117
- // const title: string = accountName
127
+ log(`getAuthInfo, no devOpsAccount set after all, throwing 401`); // const title: string = accountName
118
128
  // ? `Account "${accountName}" cannot be found`
119
129
  // : 'No authenticated accounts found.';
120
130
  // const err: AuthenticationError = new Error(title);
121
131
  // err.errors = [{ status: 401, title }];
122
132
  // throw err;
133
+
123
134
  throw {
124
135
  errors: [{
125
136
  status: 401,
@@ -127,15 +138,16 @@ class CoreConfigController {
127
138
  }]
128
139
  };
129
140
  }
141
+
130
142
  CoreConfigController.devOpsAccount = devOpsAccount;
131
143
  }
144
+
132
145
  const result = {
133
146
  orgId: (_devOpsAccount = devOpsAccount) === null || _devOpsAccount === void 0 ? void 0 : (_devOpsAccount$org = _devOpsAccount.org) === null || _devOpsAccount$org === void 0 ? void 0 : (_devOpsAccount$org$id = _devOpsAccount$org.id) === null || _devOpsAccount$org$id === void 0 ? void 0 : _devOpsAccount$org$id.toString(),
134
147
  orgRegion: (_devOpsAccount$org2 = devOpsAccount.org) === null || _devOpsAccount$org2 === void 0 ? void 0 : _devOpsAccount$org2.region,
135
148
  token: process.env.AXWAY_CENTRAL_AUTH_TOKEN || config.get('central.authToken', devOpsAccount.auth.tokens.access_token)
136
- };
149
+ }; // now that we have resolved the account, we can validate the team
137
150
 
138
- // now that we have resolved the account, we can validate the team
139
151
  if (team) {
140
152
  const {
141
153
  teams
@@ -143,13 +155,16 @@ class CoreConfigController {
143
155
  const teamObj = teams.find(t => {
144
156
  return t.guid.toLowerCase() === team.toLowerCase() || t.name.toLowerCase() === team.toLowerCase();
145
157
  });
158
+
146
159
  if (!teamObj) {
147
160
  throw new Error(`Unable to find team "${team}" in the "${devOpsAccount.org.name}" organization`);
148
161
  }
162
+
149
163
  result.teamGuid = teamObj.guid;
150
164
  } else if (team === null) {
151
165
  result.teamGuid = null;
152
166
  }
167
+
153
168
  log(`getAuthInfo, returning account = ${devOpsAccount.name}`);
154
169
  log(`getAuthInfo, returning token = ${result.token.substring(0, 5)}*****${result.token.substring(result.token.length - 5)}`);
155
170
  log(`getAuthInfo, returning orgId = ${result.orgId}`);
@@ -157,14 +172,21 @@ class CoreConfigController {
157
172
  log(`getAuthInfo, returning teamGuid = ${result.teamGuid}`);
158
173
  return result;
159
174
  }
175
+
160
176
  static getEnv() {
161
177
  var _CoreConfigController, _CoreConfigController2;
178
+
162
179
  return ((_CoreConfigController = CoreConfigController.devOpsAccount) === null || _CoreConfigController === void 0 ? void 0 : (_CoreConfigController2 = _CoreConfigController.auth) === null || _CoreConfigController2 === void 0 ? void 0 : _CoreConfigController2.env) || _types.Platforms.prod;
163
180
  }
181
+
164
182
  static getAuthUrl() {
165
183
  var _CoreConfigController3, _CoreConfigController4;
184
+
166
185
  return ((_CoreConfigController3 = CoreConfigController.devOpsAccount) === null || _CoreConfigController3 === void 0 ? void 0 : (_CoreConfigController4 = _CoreConfigController3.auth) === null || _CoreConfigController4 === void 0 ? void 0 : _CoreConfigController4.baseUrl) || _types.AuthUrls.Prod;
167
186
  }
187
+
168
188
  }
189
+
169
190
  exports.CoreConfigController = CoreConfigController;
191
+
170
192
  _defineProperty(CoreConfigController, "devOpsAccount", null);