@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,14 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.verifyApigeeXCredentialFile = exports.validateValueRange = exports.validateValidRegex = exports.validateRegex = exports.validateNonEmptyInput = exports.validateInputIsNew = exports.runValidations = exports.filterEmptyNumberInput = exports.askUsernameAndPassword = exports.askList = exports.askInputValidation = exports.askInput = exports.MAX_FILE_SIZE = void 0;
|
|
7
|
-
|
|
8
7
|
var _inquirer = _interopRequireDefault(require("inquirer"));
|
|
9
|
-
|
|
10
8
|
var _fsExtra = require("fs-extra");
|
|
11
|
-
|
|
12
9
|
var _path = require("path");
|
|
13
|
-
|
|
14
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
//
|
|
12
|
+
// Basic Prompts
|
|
13
|
+
//
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
16
|
* @param validators At least one InputValidation func
|
|
@@ -24,28 +23,20 @@ const runValidations = (...validators) => input => {
|
|
|
24
23
|
const res = validator(input);
|
|
25
24
|
if (typeof res === 'string') return res;
|
|
26
25
|
}
|
|
27
|
-
|
|
28
26
|
return true;
|
|
29
27
|
};
|
|
30
|
-
|
|
31
28
|
exports.runValidations = runValidations;
|
|
32
|
-
|
|
33
29
|
const validateRegex = (regexp, message) => input => {
|
|
34
30
|
return input.toString().match(regexp) ? true : message;
|
|
35
31
|
};
|
|
36
|
-
|
|
37
32
|
exports.validateRegex = validateRegex;
|
|
38
|
-
const MAX_FILE_SIZE = process.env.NODE_ENV === 'test' ? 1e5 : 20 * 1024 * 1024;
|
|
39
|
-
exports.MAX_FILE_SIZE = MAX_FILE_SIZE;
|
|
40
|
-
|
|
33
|
+
const MAX_FILE_SIZE = exports.MAX_FILE_SIZE = process.env.NODE_ENV === 'test' ? 1e5 : 20 * 1024 * 1024;
|
|
41
34
|
const verifyApigeeXCredentialFile = () => input => {
|
|
42
35
|
let stats;
|
|
43
36
|
let fileExtension = '';
|
|
44
|
-
|
|
45
37
|
try {
|
|
46
38
|
stats = (0, _fsExtra.lstatSync)(input);
|
|
47
39
|
fileExtension = (0, _path.extname)(input);
|
|
48
|
-
|
|
49
40
|
if (!stats.isFile()) {
|
|
50
41
|
throw new Error(`Couldn't load the credential file: ${input}`);
|
|
51
42
|
} else if (stats.size >= MAX_FILE_SIZE) {
|
|
@@ -53,43 +44,32 @@ const verifyApigeeXCredentialFile = () => input => {
|
|
|
53
44
|
} else if (fileExtension !== '.json') {
|
|
54
45
|
throw new Error(`File extension is invalid, please provide '.json' file`);
|
|
55
46
|
}
|
|
56
|
-
|
|
57
47
|
return true;
|
|
58
48
|
} catch (e) {
|
|
59
49
|
throw new Error(`Couldn't find the credential file: ${input}`);
|
|
60
50
|
}
|
|
61
51
|
};
|
|
62
|
-
|
|
63
52
|
exports.verifyApigeeXCredentialFile = verifyApigeeXCredentialFile;
|
|
64
|
-
|
|
65
53
|
const validateValidRegex = () => input => {
|
|
66
54
|
try {
|
|
67
55
|
new RegExp(input.toString());
|
|
68
56
|
} catch (error) {
|
|
69
57
|
return 'Please provide a valid regular expression.';
|
|
70
58
|
}
|
|
71
|
-
|
|
72
59
|
return true;
|
|
73
60
|
};
|
|
74
|
-
|
|
75
61
|
exports.validateValidRegex = validateValidRegex;
|
|
76
|
-
|
|
77
62
|
const validateInputIsNew = (options, error) => input => {
|
|
78
63
|
const isFound = options.find(opt => opt === input);
|
|
79
64
|
return isFound ? error : true;
|
|
80
65
|
};
|
|
81
|
-
|
|
82
66
|
exports.validateInputIsNew = validateInputIsNew;
|
|
83
|
-
|
|
84
67
|
const validateValueRange = (lowerLimit, upperLimit) => input => {
|
|
85
68
|
const inputNum = Number(input);
|
|
86
|
-
|
|
87
69
|
if (isNaN(inputNum)) {
|
|
88
70
|
return 'Please provide a number.';
|
|
89
71
|
}
|
|
90
|
-
|
|
91
72
|
let msg = "";
|
|
92
|
-
|
|
93
73
|
if (typeof lowerLimit !== undefined && typeof upperLimit !== undefined) {
|
|
94
74
|
msg = `Please provide a number from ${lowerLimit} to ${upperLimit}`;
|
|
95
75
|
} else if (typeof lowerLimit !== undefined) {
|
|
@@ -97,47 +77,37 @@ const validateValueRange = (lowerLimit, upperLimit) => input => {
|
|
|
97
77
|
} else if (typeof upperLimit !== undefined) {
|
|
98
78
|
msg = `Please provide a maximum number of ${upperLimit}`;
|
|
99
79
|
}
|
|
100
|
-
|
|
101
80
|
if (typeof lowerLimit !== undefined && inputNum < lowerLimit) {
|
|
102
81
|
return msg;
|
|
103
82
|
}
|
|
104
|
-
|
|
105
83
|
if (typeof upperLimit !== undefined && inputNum > upperLimit) {
|
|
106
84
|
return msg;
|
|
107
85
|
}
|
|
108
|
-
|
|
109
86
|
return true;
|
|
110
|
-
};
|
|
111
|
-
|
|
87
|
+
};
|
|
112
88
|
|
|
89
|
+
// exporting for test
|
|
113
90
|
exports.validateValueRange = validateValueRange;
|
|
114
|
-
|
|
115
91
|
const validateNonEmptyInput = input => {
|
|
116
92
|
return String(input).length ? true : 'Please provide a non-empty value.';
|
|
117
|
-
};
|
|
118
|
-
|
|
93
|
+
};
|
|
119
94
|
|
|
95
|
+
// exporting for test
|
|
120
96
|
exports.validateNonEmptyInput = validateNonEmptyInput;
|
|
121
|
-
|
|
122
97
|
const filterEmptyNumberInput = input => {
|
|
123
98
|
// clear the invalid input
|
|
124
99
|
return Number.isNaN(input) ? '' : Number(input);
|
|
125
100
|
};
|
|
126
|
-
|
|
127
101
|
exports.filterEmptyNumberInput = filterEmptyNumberInput;
|
|
128
|
-
|
|
129
102
|
const askInputValidation = (allowEmptyInput, validate) => input => {
|
|
130
103
|
if (allowEmptyInput && !String(input).length) {
|
|
131
104
|
return true;
|
|
132
105
|
}
|
|
133
|
-
|
|
134
106
|
const isEmpty = allowEmptyInput ? true : validateNonEmptyInput(input);
|
|
135
107
|
if (typeof isEmpty === 'string') return isEmpty;
|
|
136
108
|
return validate ? validate(input) : true;
|
|
137
109
|
};
|
|
138
|
-
|
|
139
110
|
exports.askInputValidation = askInputValidation;
|
|
140
|
-
|
|
141
111
|
const askInput = async ({
|
|
142
112
|
msg,
|
|
143
113
|
defaultValue,
|
|
@@ -155,9 +125,7 @@ const askInput = async ({
|
|
|
155
125
|
});
|
|
156
126
|
return answers.value;
|
|
157
127
|
};
|
|
158
|
-
|
|
159
128
|
exports.askInput = askInput;
|
|
160
|
-
|
|
161
129
|
const askList = async opts => {
|
|
162
130
|
const answers = await _inquirer.default.prompt({
|
|
163
131
|
type: 'list',
|
|
@@ -168,9 +136,7 @@ const askList = async opts => {
|
|
|
168
136
|
});
|
|
169
137
|
return answers.value;
|
|
170
138
|
};
|
|
171
|
-
|
|
172
139
|
exports.askList = askList;
|
|
173
|
-
|
|
174
140
|
const askUsernameAndPassword = async (msg, defaultUsername) => {
|
|
175
141
|
const answers = await _inquirer.default.prompt([{
|
|
176
142
|
type: 'input',
|
|
@@ -187,5 +153,4 @@ const askUsernameAndPassword = async (msg, defaultUsername) => {
|
|
|
187
153
|
}]);
|
|
188
154
|
return answers;
|
|
189
155
|
};
|
|
190
|
-
|
|
191
156
|
exports.askUsernameAndPassword = askUsernameAndPassword;
|
|
@@ -4,38 +4,27 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getBaseUrl = exports.dataService = void 0;
|
|
7
|
-
|
|
8
7
|
var _amplifyCliUtils = require("@axway/amplify-cli-utils");
|
|
9
|
-
|
|
10
8
|
var _got = require("got");
|
|
11
|
-
|
|
12
9
|
var _flatten = _interopRequireDefault(require("lodash/flatten"));
|
|
13
|
-
|
|
14
10
|
var _promiseLimit = _interopRequireDefault(require("promise-limit"));
|
|
15
|
-
|
|
16
11
|
var _snooplogg = _interopRequireDefault(require("snooplogg"));
|
|
17
|
-
|
|
18
12
|
var _url = require("url");
|
|
19
|
-
|
|
20
13
|
var _CoreConfigController = require("./CoreConfigController");
|
|
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
17
|
// NOTE: removing update-notifier due to some security issues reported.
|
|
29
18
|
// There is suppression in '.csr-profile.json' that needed to be removed if this library is used in production code.
|
|
30
19
|
// import updateNotifier from 'update-notifier';
|
|
31
20
|
// import semver from 'semver';
|
|
21
|
+
|
|
32
22
|
// dep of @axway/amplify-cli-utils -> @axway/amplify-request
|
|
33
|
-
const thisPackage = require('../../package.json');
|
|
34
23
|
|
|
24
|
+
const thisPackage = require('../../package.json');
|
|
35
25
|
const {
|
|
36
26
|
log
|
|
37
27
|
} = (0, _snooplogg.default)('central: dataService');
|
|
38
|
-
|
|
39
28
|
const getDefaultHeaders = ({
|
|
40
29
|
token,
|
|
41
30
|
orgId
|
|
@@ -47,7 +36,9 @@ const getDefaultHeaders = ({
|
|
|
47
36
|
[_types.cliVersionHeader]: thisPackage.version,
|
|
48
37
|
'User-Agent': 'axway-cli'
|
|
49
38
|
};
|
|
50
|
-
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// TODO: need to refactor this part, data service is used as part of many basic command (create / update, etc.) now.
|
|
51
42
|
// Plus need to revisit this logic since no testing can be done currently (no new prod versions has been released yet)
|
|
52
43
|
// https://jira.axway.com/browse/APIGOV-14969
|
|
53
44
|
// const versionCheckWarning = async () => {
|
|
@@ -64,10 +55,8 @@ const getDefaultHeaders = ({
|
|
|
64
55
|
// }
|
|
65
56
|
// };
|
|
66
57
|
|
|
67
|
-
|
|
68
58
|
const getBaseUrl = async (baseUrl, basePath, region, orgRegion) => {
|
|
69
59
|
const configuredBaseUrl = baseUrl || process.env.AXWAY_CENTRAL_BASE_URL || (await (0, _utils.getConfig)())[_types.ConfigTypes.BASE_URL];
|
|
70
|
-
|
|
71
60
|
if (configuredBaseUrl) {
|
|
72
61
|
return basePath ? configuredBaseUrl + basePath : configuredBaseUrl;
|
|
73
62
|
} else {
|
|
@@ -79,33 +68,27 @@ const getBaseUrl = async (baseUrl, basePath, region, orgRegion) => {
|
|
|
79
68
|
return basePath ? prodBaseurl + basePath : prodBaseurl;
|
|
80
69
|
}
|
|
81
70
|
};
|
|
82
|
-
|
|
83
71
|
exports.getBaseUrl = getBaseUrl;
|
|
84
|
-
|
|
85
72
|
const handleResponse = response => {
|
|
86
73
|
return /application\/json/.test(response.headers['content-type']) ? JSON.parse(response.body) : response.body;
|
|
87
74
|
};
|
|
88
|
-
|
|
89
75
|
const updateRequestError = err => {
|
|
90
76
|
var _err$response;
|
|
91
|
-
|
|
92
77
|
// Do not change given object if it's a timeout error.
|
|
93
78
|
if (err instanceof _got.TimeoutError) {
|
|
94
79
|
return;
|
|
95
|
-
}
|
|
96
|
-
|
|
80
|
+
}
|
|
97
81
|
|
|
82
|
+
// If we have a JSON HTTP body, then turn it into a dictionary.
|
|
98
83
|
let jsonBody = null;
|
|
99
|
-
|
|
100
84
|
if (err instanceof _got.RequestError && (_err$response = err.response) !== null && _err$response !== void 0 && _err$response.body) {
|
|
101
85
|
jsonBody = handleResponse(err.response);
|
|
102
86
|
}
|
|
103
|
-
|
|
104
87
|
if (!jsonBody) {
|
|
105
88
|
return;
|
|
106
|
-
}
|
|
107
|
-
|
|
89
|
+
}
|
|
108
90
|
|
|
91
|
+
// Turn given Error object into an "ApiServerError" or "ApiServerErrorResponse" object.
|
|
109
92
|
if (typeof jsonBody.code === 'number' && typeof jsonBody.description === 'string') {
|
|
110
93
|
// We received a "Platform" server error response.
|
|
111
94
|
err.status = jsonBody.code;
|
|
@@ -115,6 +98,7 @@ const updateRequestError = err => {
|
|
|
115
98
|
Object.assign(err, jsonBody);
|
|
116
99
|
}
|
|
117
100
|
};
|
|
101
|
+
|
|
118
102
|
/**
|
|
119
103
|
* Creates an object with various functions communicating with the API Server.
|
|
120
104
|
* @param {String} clientId Client id to use.
|
|
@@ -122,8 +106,6 @@ const updateRequestError = err => {
|
|
|
122
106
|
* @param {String} [region] The preferred region to use.
|
|
123
107
|
* @returns Object containing data retrieval functions.
|
|
124
108
|
*/
|
|
125
|
-
|
|
126
|
-
|
|
127
109
|
const dataService = async ({
|
|
128
110
|
account,
|
|
129
111
|
baseUrl,
|
|
@@ -150,7 +132,6 @@ const dataService = async ({
|
|
|
150
132
|
token
|
|
151
133
|
});
|
|
152
134
|
const got = (0, _amplifyCliUtils.createRequestClient)();
|
|
153
|
-
|
|
154
135
|
const fetch = async (method, url, params = {}) => {
|
|
155
136
|
try {
|
|
156
137
|
// add the team guid
|
|
@@ -159,31 +140,28 @@ const dataService = async ({
|
|
|
159
140
|
parsed.searchParams.set('query', teamGuid ? `owner.id==${teamGuid},(owner.id==null;metadata.scope.owner.id==${teamGuid})` : 'owner.id==null');
|
|
160
141
|
url = parsed.toString();
|
|
161
142
|
}
|
|
162
|
-
|
|
163
143
|
const response = await got[method](url, {
|
|
164
144
|
followRedirect: false,
|
|
165
145
|
retry: 0,
|
|
166
146
|
timeout: _types.ABORT_TIMEOUT,
|
|
167
147
|
...params
|
|
168
148
|
});
|
|
169
|
-
|
|
170
149
|
if (response.statusCode === 301 || response.statusCode === 302) {
|
|
171
150
|
log(`${method.toUpperCase()}: ${url} ${response.statusCode} redirecting to ${response.headers.location}`);
|
|
172
151
|
return await fetch(method, response.headers.location, params);
|
|
173
152
|
}
|
|
174
|
-
|
|
175
153
|
return response;
|
|
176
154
|
} catch (err) {
|
|
177
155
|
updateRequestError(err);
|
|
178
156
|
throw err;
|
|
179
157
|
}
|
|
180
158
|
};
|
|
181
|
-
|
|
182
159
|
return {
|
|
183
160
|
postFormData: (route, body, headers = {}) => {
|
|
184
161
|
log(`POST (from data): ${url + route}`);
|
|
185
162
|
return fetch('post', url + route, {
|
|
186
|
-
headers: {
|
|
163
|
+
headers: {
|
|
164
|
+
...defaultHeaders,
|
|
187
165
|
...body.getHeaders(),
|
|
188
166
|
...headers
|
|
189
167
|
},
|
|
@@ -194,7 +172,8 @@ const dataService = async ({
|
|
|
194
172
|
log(`POST: ${url + route}`);
|
|
195
173
|
log(data);
|
|
196
174
|
return fetch('post', url + route, {
|
|
197
|
-
headers: {
|
|
175
|
+
headers: {
|
|
176
|
+
...defaultHeaders,
|
|
198
177
|
...headers
|
|
199
178
|
},
|
|
200
179
|
json: data
|
|
@@ -203,14 +182,16 @@ const dataService = async ({
|
|
|
203
182
|
put: (route, data, headers = {}) => {
|
|
204
183
|
log(`PUT: ${url + route}`);
|
|
205
184
|
return fetch('put', url + route, {
|
|
206
|
-
headers: {
|
|
185
|
+
headers: {
|
|
186
|
+
...defaultHeaders,
|
|
207
187
|
...headers
|
|
208
188
|
},
|
|
209
189
|
json: data
|
|
210
190
|
}).then(handleResponse);
|
|
211
191
|
},
|
|
212
192
|
get: (route, headers = {}, skipDefaultHeaders = false) => {
|
|
213
|
-
const h = skipDefaultHeaders ? headers : {
|
|
193
|
+
const h = skipDefaultHeaders ? headers : {
|
|
194
|
+
...defaultHeaders,
|
|
214
195
|
...headers
|
|
215
196
|
};
|
|
216
197
|
log(`GET: ${url + route}`, h);
|
|
@@ -218,7 +199,6 @@ const dataService = async ({
|
|
|
218
199
|
headers: h
|
|
219
200
|
}).then(handleResponse);
|
|
220
201
|
},
|
|
221
|
-
|
|
222
202
|
/**
|
|
223
203
|
* Get the entire list using pagination. Method is trying to define total number of items based on response header
|
|
224
204
|
* and makes additional calls if needed to retrieve additional pages.
|
|
@@ -234,36 +214,30 @@ const dataService = async ({
|
|
|
234
214
|
fullUrl.searchParams.set('pageSize', `${pageSize}`);
|
|
235
215
|
log(`GET (with auto-pagination): ${fullUrl.href}`);
|
|
236
216
|
const response = await fetch('get', fullUrl.toString(), {
|
|
237
|
-
headers: {
|
|
217
|
+
headers: {
|
|
218
|
+
...defaultHeaders,
|
|
238
219
|
...headers
|
|
239
220
|
}
|
|
240
221
|
});
|
|
241
222
|
const totalCountHeader = response.headers['x-axway-total-count'];
|
|
242
|
-
|
|
243
223
|
if (totalCountHeader === null || totalCountHeader === undefined) {
|
|
244
224
|
log(`GET (with auto-pagination), warning: cannot figure out 'total count' header, resolving response as-is`);
|
|
245
225
|
return handleResponse(response);
|
|
246
226
|
}
|
|
247
|
-
|
|
248
227
|
log(`GET (with auto-pagination), 'total count' header found, count = ${totalCountHeader}, will fire additional GET calls if needed`);
|
|
249
228
|
const totalPages = Math.max(Math.ceil(Number(totalCountHeader) / pageSize), 1);
|
|
250
229
|
const allPages = new Array(totalPages);
|
|
251
230
|
allPages[0] = handleResponse(response);
|
|
252
|
-
|
|
253
231
|
if (totalPages > 1) {
|
|
254
232
|
const limit = (0, _promiseLimit.default)(8); // Limits number of concurrrent HTTP requests.
|
|
255
|
-
|
|
256
233
|
const otherPagesCalls = [];
|
|
257
234
|
let pageDownloadCount = 1;
|
|
258
|
-
|
|
259
235
|
const updateProgress = () => {
|
|
260
236
|
if (progressListener && totalPages > 4) {
|
|
261
237
|
progressListener(Math.floor(pageDownloadCount / totalPages * 100));
|
|
262
238
|
}
|
|
263
239
|
};
|
|
264
|
-
|
|
265
240
|
updateProgress();
|
|
266
|
-
|
|
267
241
|
for (let pageIndex = 1; pageIndex < totalPages; pageIndex++) {
|
|
268
242
|
const thisPageIndex = pageIndex;
|
|
269
243
|
fullUrl.searchParams.set('page', `${thisPageIndex + 1}`);
|
|
@@ -274,16 +248,15 @@ const dataService = async ({
|
|
|
274
248
|
updateProgress();
|
|
275
249
|
}));
|
|
276
250
|
}
|
|
277
|
-
|
|
278
251
|
await Promise.all(otherPagesCalls);
|
|
279
252
|
}
|
|
280
|
-
|
|
281
253
|
return (0, _flatten.default)(allPages);
|
|
282
254
|
},
|
|
283
255
|
delete: (route, headers = {}) => {
|
|
284
256
|
log(`DELETE: ${url + route}`);
|
|
285
257
|
return fetch('delete', url + route, {
|
|
286
|
-
headers: {
|
|
258
|
+
headers: {
|
|
259
|
+
...defaultHeaders,
|
|
287
260
|
...headers
|
|
288
261
|
}
|
|
289
262
|
}).then(handleResponse);
|
|
@@ -315,5 +288,4 @@ const dataService = async ({
|
|
|
315
288
|
}
|
|
316
289
|
};
|
|
317
290
|
};
|
|
318
|
-
|
|
319
291
|
exports.dataService = dataService;
|
|
@@ -4,15 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.handleErrors = void 0;
|
|
7
|
-
|
|
8
7
|
var _cliKit = require("cli-kit");
|
|
9
|
-
|
|
10
8
|
// TODO: used by legacy "proxies" command only, will be removed soon
|
|
11
9
|
// https://jira.axway.com/browse/APIGOV-20818
|
|
12
10
|
const handleErrors = (console, e, spinner) => {
|
|
13
11
|
if (e.errors && Array.isArray(e.errors)) {
|
|
14
12
|
const error = e.errors[0];
|
|
15
|
-
|
|
16
13
|
if (spinner) {
|
|
17
14
|
switch (error.status) {
|
|
18
15
|
case 401:
|
|
@@ -22,28 +19,23 @@ const handleErrors = (console, e, spinner) => {
|
|
|
22
19
|
console.info('Or if using a service account:');
|
|
23
20
|
console.info((0, _cliKit.chalk)`{cyan axway auth login --client-id <Service Account Client ID> --secret-file <Private Key>}`);
|
|
24
21
|
break;
|
|
25
|
-
|
|
26
22
|
case 403:
|
|
27
23
|
spinner.fail((0, _cliKit.chalk)`{red ${error.detail}}`);
|
|
28
24
|
break;
|
|
29
|
-
|
|
30
25
|
case 400:
|
|
31
26
|
spinner.fail((0, _cliKit.chalk)`{red Error: ${error.detail || error.title}}`);
|
|
32
27
|
if (error.source) console.log((0, _cliKit.chalk)`{gray Caused by: ${JSON.stringify(error.source)}}`);
|
|
33
28
|
break;
|
|
34
|
-
|
|
35
29
|
case 404:
|
|
36
30
|
case 409:
|
|
37
31
|
spinner.fail((0, _cliKit.chalk)`{red ${error.title}\n{blueBright ${error.detail}}}`);
|
|
38
32
|
break;
|
|
39
|
-
|
|
40
33
|
default:
|
|
41
34
|
spinner.fail((0, _cliKit.chalk)`{red An error occurred}`);
|
|
42
35
|
}
|
|
43
36
|
} else {
|
|
44
37
|
console.error(error);
|
|
45
38
|
}
|
|
46
|
-
|
|
47
39
|
process.exit(1);
|
|
48
40
|
} else if (e instanceof Error) {
|
|
49
41
|
let message = e.name === 'TimeoutError' ? `Couldn't connect to Amplify Central` : e.message;
|
|
@@ -51,5 +43,4 @@ const handleErrors = (console, e, spinner) => {
|
|
|
51
43
|
process.exit(1);
|
|
52
44
|
} else throw e;
|
|
53
45
|
};
|
|
54
|
-
|
|
55
46
|
exports.handleErrors = handleErrors;
|
|
@@ -5,27 +5,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.renderResponse = exports.parseAsYaml = exports.parseAsJson = void 0;
|
|
7
7
|
exports.resolveTeamNames = resolveTeamNames;
|
|
8
|
-
|
|
9
8
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
10
|
-
|
|
11
9
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
12
|
-
|
|
13
10
|
var _easyTable = _interopRequireDefault(require("easy-table"));
|
|
14
|
-
|
|
15
11
|
var _jsYaml = require("js-yaml");
|
|
16
|
-
|
|
17
12
|
var _get = _interopRequireDefault(require("lodash/get"));
|
|
18
|
-
|
|
19
13
|
var _set = _interopRequireDefault(require("lodash/set"));
|
|
20
|
-
|
|
21
14
|
var _CoreConfigController = require("./CoreConfigController");
|
|
22
|
-
|
|
23
15
|
var _amplifyCliUtils = require("@axway/amplify-cli-utils");
|
|
24
|
-
|
|
25
16
|
var _types = require("./types");
|
|
26
|
-
|
|
27
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
28
|
-
|
|
29
18
|
/**
|
|
30
19
|
* HACK: removing "---" delimiter printing from the lib.
|
|
31
20
|
* Currently this is not supported in library itself so have to override prototype methods.
|
|
@@ -33,17 +22,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
33
22
|
_easyTable.default.prototype.pushDelimeter = function () {
|
|
34
23
|
return this;
|
|
35
24
|
};
|
|
25
|
+
|
|
36
26
|
/**
|
|
37
27
|
* Parse JSON object | array of objects as YAML
|
|
38
28
|
* @param response request response payload
|
|
39
29
|
* @param console current console
|
|
40
30
|
* @returns parsed string with YAML objects representation
|
|
41
31
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
32
|
const parseAsYaml = response => {
|
|
45
33
|
let result = '';
|
|
46
|
-
|
|
47
34
|
if (Array.isArray(response)) {
|
|
48
35
|
for (const i of response) {
|
|
49
36
|
result += `\n---\n${(0, _jsYaml.dump)(i)}`;
|
|
@@ -51,9 +38,9 @@ const parseAsYaml = response => {
|
|
|
51
38
|
} else {
|
|
52
39
|
result = (0, _jsYaml.dump)(response);
|
|
53
40
|
}
|
|
54
|
-
|
|
55
41
|
return result;
|
|
56
42
|
};
|
|
43
|
+
|
|
57
44
|
/**
|
|
58
45
|
* Parse JSON object | array of objects as simple text table,
|
|
59
46
|
* NOTE: currently can build table only for "Environment" type.
|
|
@@ -62,19 +49,14 @@ const parseAsYaml = response => {
|
|
|
62
49
|
* @param columns columns config from CommandLineInterface resource definition
|
|
63
50
|
* @returns parsed string with table objects representation
|
|
64
51
|
*/
|
|
65
|
-
|
|
66
|
-
|
|
67
52
|
exports.parseAsYaml = parseAsYaml;
|
|
68
|
-
|
|
69
53
|
const parseAsTable = (response, columns) => {
|
|
70
54
|
const data = Array.isArray(response) ? response : [response];
|
|
71
55
|
const t = new _easyTable.default();
|
|
72
|
-
|
|
73
56
|
for (const i of data) {
|
|
74
57
|
for (const col of columns) {
|
|
75
58
|
// jsonPath starts with '.' so using the substring
|
|
76
59
|
let value = (0, _get.default)(i, col.jsonPath.substring(1));
|
|
77
|
-
|
|
78
60
|
if (col.type === 'date') {
|
|
79
61
|
value = (0, _dayjs.default)(value).fromNow();
|
|
80
62
|
} else if (col.type === 'teamGuid' && !value) {
|
|
@@ -82,52 +64,42 @@ const parseAsTable = (response, columns) => {
|
|
|
82
64
|
} else if (value && value.length > _types.MAX_TABLE_STRING_LENGTH + 3) {
|
|
83
65
|
value = value.substring(0, _types.MAX_TABLE_STRING_LENGTH / 2) + '...' + value.substring(value.length - _types.MAX_TABLE_STRING_LENGTH / 2);
|
|
84
66
|
}
|
|
85
|
-
|
|
86
67
|
t.cell(col.name.toUpperCase(), value);
|
|
87
68
|
}
|
|
88
|
-
|
|
89
69
|
t.newRow();
|
|
90
70
|
}
|
|
91
|
-
|
|
92
71
|
return data.length ? `\n${t.toString()}` : '\nNo resources found.';
|
|
93
72
|
};
|
|
73
|
+
|
|
94
74
|
/**
|
|
95
75
|
* Parse JSON object | array of objects as is but without any replacing like [object Object].
|
|
96
76
|
* @param response request response payload
|
|
97
77
|
* @param console current console
|
|
98
78
|
* @returns parsed string with JSON objects representation
|
|
99
79
|
*/
|
|
100
|
-
|
|
101
|
-
|
|
102
80
|
const parseAsJson = response => JSON.stringify(response, null, 4);
|
|
81
|
+
|
|
103
82
|
/**
|
|
104
83
|
* Util function to render JSON object | array of objects based on output type provided
|
|
105
84
|
* @param response request response payload
|
|
106
85
|
* @param output type of output to render (table (default) / yaml / json)
|
|
107
86
|
* @param console current console
|
|
108
87
|
*/
|
|
109
|
-
|
|
110
|
-
|
|
111
88
|
exports.parseAsJson = parseAsJson;
|
|
112
|
-
|
|
113
89
|
const renderResponse = (console, response, output, columns) => {
|
|
114
90
|
switch (output) {
|
|
115
91
|
case _types.OutputTypes.yaml:
|
|
116
92
|
console.log(parseAsYaml(response));
|
|
117
93
|
break;
|
|
118
|
-
|
|
119
94
|
case _types.OutputTypes.json:
|
|
120
95
|
console.log(parseAsJson(response));
|
|
121
96
|
break;
|
|
122
|
-
|
|
123
97
|
default:
|
|
124
98
|
// @ts-ignore TODO: fix types error once more types are used
|
|
125
99
|
console.log(parseAsTable(response, columns));
|
|
126
100
|
}
|
|
127
101
|
};
|
|
128
|
-
|
|
129
102
|
exports.renderResponse = renderResponse;
|
|
130
|
-
|
|
131
103
|
/**
|
|
132
104
|
* If a team guid column is being rendered, it resolves the team name and injects it into
|
|
133
105
|
* the response payload.
|
|
@@ -140,11 +112,9 @@ async function resolveTeamNames({
|
|
|
140
112
|
}) {
|
|
141
113
|
// check that we even have a team guid column
|
|
142
114
|
const column = columns === null || columns === void 0 ? void 0 : columns.find(col => col.type === 'teamGuid');
|
|
143
|
-
|
|
144
115
|
if (!column || !_CoreConfigController.CoreConfigController.devOpsAccount) {
|
|
145
116
|
return;
|
|
146
117
|
}
|
|
147
|
-
|
|
148
118
|
const jsonPath = column.jsonPath.substring(1);
|
|
149
119
|
const results = Array.isArray(response) ? response : [response];
|
|
150
120
|
const teamNames = {};
|
|
@@ -155,34 +125,32 @@ async function resolveTeamNames({
|
|
|
155
125
|
sdk
|
|
156
126
|
} = (0, _amplifyCliUtils.initSDK)({
|
|
157
127
|
env: devOpsAccount.auth.env
|
|
158
|
-
});
|
|
128
|
+
});
|
|
159
129
|
|
|
130
|
+
// build the team name lookup
|
|
160
131
|
const {
|
|
161
132
|
teams
|
|
162
133
|
} = await sdk.team.list(devOpsAccount);
|
|
163
|
-
|
|
164
134
|
for (const team of teams) {
|
|
165
135
|
teamNames[team.guid] = team.name;
|
|
166
|
-
}
|
|
167
|
-
|
|
136
|
+
}
|
|
168
137
|
|
|
138
|
+
// create the new jsonPath and update the column
|
|
169
139
|
const targetJsonPath = jsonPath.split('.').slice(0, -1).join('.') + '.teamName';
|
|
170
|
-
column.jsonPath = `.${targetJsonPath}`;
|
|
140
|
+
column.jsonPath = `.${targetJsonPath}`;
|
|
171
141
|
|
|
142
|
+
// next loop over data and set the team name
|
|
172
143
|
for (let {
|
|
173
144
|
data
|
|
174
145
|
} of results) {
|
|
175
146
|
if (!data || typeof data !== 'object') {
|
|
176
147
|
continue;
|
|
177
148
|
}
|
|
178
|
-
|
|
179
149
|
if (!Array.isArray(data)) {
|
|
180
150
|
data = [data];
|
|
181
151
|
}
|
|
182
|
-
|
|
183
152
|
for (const obj of data) {
|
|
184
153
|
const value = (0, _get.default)(obj, jsonPath, null);
|
|
185
|
-
|
|
186
154
|
if (value !== null) {
|
|
187
155
|
(0, _set.default)(obj, targetJsonPath, value && teamNames[value] || value || '');
|
|
188
156
|
}
|