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