@axway/axway-central-cli 2.1.0-rc.0 → 2.1.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.
|
@@ -48,9 +48,11 @@ class CliConfigManager {
|
|
|
48
48
|
|
|
49
49
|
getAll() {
|
|
50
50
|
return (0, _fsExtra.existsSync)(CliConfigManager.configFilePath) ? (0, _fsExtra.readJsonSync)(CliConfigManager.configFilePath) : {};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
get(key) {
|
|
54
|
+
return this.getAll()[key];
|
|
51
55
|
} // TODO
|
|
52
|
-
// get(key: CentralConfigKeys) {}
|
|
53
|
-
// TODO
|
|
54
56
|
// set(key: CentralConfigKeys) {}
|
|
55
57
|
|
|
56
58
|
|
|
@@ -7,11 +7,15 @@ exports.CoreConfigController = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _amplifyCliUtils = require("@axway/amplify-cli-utils");
|
|
9
9
|
|
|
10
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
|
11
|
+
|
|
10
12
|
var _snooplogg = _interopRequireDefault(require("snooplogg"));
|
|
11
13
|
|
|
12
|
-
var
|
|
14
|
+
var _basicPrompts = require("./basicPrompts");
|
|
15
|
+
|
|
16
|
+
var _CliConfigManager = require("./CliConfigManager");
|
|
13
17
|
|
|
14
|
-
var
|
|
18
|
+
var _types = require("./types");
|
|
15
19
|
|
|
16
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
21
|
|
|
@@ -32,23 +36,51 @@ class CoreConfigController {
|
|
|
32
36
|
accountName,
|
|
33
37
|
clientId
|
|
34
38
|
} = {}) {
|
|
35
|
-
const
|
|
36
|
-
|
|
39
|
+
const configCtrl = new _CliConfigManager.CliConfigManager();
|
|
40
|
+
const devOpsClientId = clientId ? clientId : configCtrl.get(_CliConfigManager.CliConfigKeys.CLIENT_ID) || _types.defaultClientId;
|
|
41
|
+
log(`getAuthInfo, using clientId = ${devOpsClientId}, accountName = ${accountName}`);
|
|
37
42
|
|
|
38
43
|
if (!CoreConfigController.devOpsAccount || CoreConfigController.devOpsAccount.auth.clientId !== devOpsClientId) {
|
|
39
44
|
log(`getAuthInfo, no cached devOpsAccount found, or clientId does not match`);
|
|
45
|
+
const baseUrl = configCtrl.get(_CliConfigManager.CliConfigKeys.BASE_URL);
|
|
46
|
+
const platform = configCtrl.get(_CliConfigManager.CliConfigKeys.PLATFORM); // environment defined by using central cli "platform" or "base-url" configs if set,
|
|
47
|
+
// otherwise its undefined (equals to prod)
|
|
48
|
+
|
|
49
|
+
const env = platform || (!baseUrl || baseUrl === _types.ProdBaseUrls.EU || baseUrl === _types.ProdBaseUrls.EU ? undefined : 'preprod');
|
|
50
|
+
log(`getAuthInfo, baseUrl = ${baseUrl}, platform = ${platform}, env = ${env}`);
|
|
40
51
|
const {
|
|
41
52
|
config,
|
|
42
53
|
sdk
|
|
43
54
|
} = (0, _amplifyCliUtils.initSDK)({
|
|
44
|
-
clientId: devOpsClientId
|
|
45
|
-
|
|
46
|
-
|
|
55
|
+
clientId: devOpsClientId,
|
|
56
|
+
env
|
|
57
|
+
}); // TODO: filtering by the clientId will not be needed when https://jira.axway.com/browse/APIGOV-20702 is fixed
|
|
58
|
+
|
|
59
|
+
const list = (await sdk.auth.list()).filter(a => a.auth.clientId === devOpsClientId);
|
|
60
|
+
log(`getAuthInfo, matching accounts found: ${list.length}`);
|
|
61
|
+
|
|
62
|
+
if (list.length > 1) {
|
|
63
|
+
// try to find the default one
|
|
64
|
+
const defaultAccount = list.find(a => a.name === accountName || a.name === config.get('auth.defaultAccount'));
|
|
65
|
+
|
|
66
|
+
if (defaultAccount) {
|
|
67
|
+
CoreConfigController.devOpsAccount = await sdk.auth.find(defaultAccount.name);
|
|
68
|
+
} else if (!accountName) {
|
|
69
|
+
const selectedName = await (0, _basicPrompts.askList)({
|
|
70
|
+
msg: 'Multiple authenticated accounts found, please select which one you want to use',
|
|
71
|
+
choices: Array.from(new Set(list.map(a => a.name)))
|
|
72
|
+
});
|
|
73
|
+
console.log((0, _chalk.default)`{grey If you always want to use "${selectedName}" account by default, run: axway config set auth.defaultAccount ${selectedName}}\n`);
|
|
74
|
+
CoreConfigController.devOpsAccount = await sdk.auth.find(selectedName);
|
|
75
|
+
}
|
|
76
|
+
} else if (list.length === 1) {
|
|
77
|
+
CoreConfigController.devOpsAccount = await sdk.auth.find(accountName || list[0].name);
|
|
78
|
+
}
|
|
47
79
|
|
|
48
80
|
if (!CoreConfigController.devOpsAccount) {
|
|
49
81
|
// TODO: piece of old logic here, move throwing out of the method?
|
|
50
82
|
log(`getAuthInfo, no devOpsAccount set after all, throwing 401`);
|
|
51
|
-
const title = accountName ? `Account "${accountName}" cannot be found` : '
|
|
83
|
+
const title = accountName ? `Account "${accountName}" cannot be found` : 'No authenticated accounts found.';
|
|
52
84
|
const err = new Error(title);
|
|
53
85
|
err.errors = [{
|
|
54
86
|
status: 401,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axway/axway-central-cli",
|
|
3
|
-
"version": "2.1.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Manage APIs, services and publish to the Unified Catalog",
|
|
5
5
|
"homepage": "https://platform.axway.com",
|
|
6
6
|
"author": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"name": "central"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@axway/amplify-cli-utils": "
|
|
43
|
+
"@axway/amplify-cli-utils": "5.0.0",
|
|
44
44
|
"chalk": "^4.1.2",
|
|
45
45
|
"cli-kit": "^1.14.1",
|
|
46
46
|
"dayjs": "^1.10.7",
|
|
@@ -118,4 +118,4 @@
|
|
|
118
118
|
"resolutions": {
|
|
119
119
|
"**/lodash": "4.17.21"
|
|
120
120
|
}
|
|
121
|
-
}
|
|
121
|
+
}
|