@axway/axway-central-cli 4.5.0 → 4.6.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/.security-profile-branches.json +18 -0
- package/package.json +1 -1
- package/dist/cli.js +0 -71
- package/dist/commands/apply/index.js +0 -112
- package/dist/commands/completion/index.js +0 -100
- package/dist/commands/config/common/index.js +0 -28
- package/dist/commands/config/index.js +0 -20
- package/dist/commands/config/list.js +0 -24
- package/dist/commands/config/set.js +0 -102
- package/dist/commands/config/unset.js +0 -48
- package/dist/commands/create/agentResource.js +0 -108
- package/dist/commands/create/environment.js +0 -62
- package/dist/commands/create/index.js +0 -109
- package/dist/commands/create/serviceAccount.js +0 -15
- package/dist/commands/delete/index.js +0 -196
- package/dist/commands/edit/environment.js +0 -101
- package/dist/commands/edit/index.js +0 -28
- package/dist/commands/get/index.js +0 -272
- package/dist/commands/install/agents.js +0 -290
- package/dist/commands/install/apigeexAgents.js +0 -223
- package/dist/commands/install/apigeexSaasAgents.js +0 -300
- package/dist/commands/install/awsAgents.js +0 -525
- package/dist/commands/install/awsSaasAgents.js +0 -508
- package/dist/commands/install/azureAgents.js +0 -242
- package/dist/commands/install/azureSaasAgents.js +0 -519
- package/dist/commands/install/backstageAgents.js +0 -167
- package/dist/commands/install/edgeAgents.js +0 -409
- package/dist/commands/install/gitHubSaasAgents.js +0 -294
- package/dist/commands/install/gitLabAgents.js +0 -178
- package/dist/commands/install/graylogAgent.js +0 -147
- package/dist/commands/install/helpers/creators.js +0 -359
- package/dist/commands/install/helpers/deleters.js +0 -36
- package/dist/commands/install/helpers/getters.js +0 -95
- package/dist/commands/install/helpers/index.js +0 -267
- package/dist/commands/install/helpers/inputs.js +0 -593
- package/dist/commands/install/helpers/regex.js +0 -67
- package/dist/commands/install/helpers/templates/apigeexTemplates.js +0 -109
- package/dist/commands/install/helpers/templates/awsTemplates.js +0 -129
- package/dist/commands/install/helpers/templates/azureTemplates.js +0 -125
- package/dist/commands/install/helpers/templates/backstageTemplates.js +0 -95
- package/dist/commands/install/helpers/templates/edgeTemplates.js +0 -360
- package/dist/commands/install/helpers/templates/gitLabTemplates.js +0 -66
- package/dist/commands/install/helpers/templates/graylogTemplates.js +0 -75
- package/dist/commands/install/helpers/templates/ibmAPIConnectTemplates.js +0 -116
- package/dist/commands/install/helpers/templates/istioTemplates.js +0 -214
- package/dist/commands/install/helpers/templates/kafkaTemplates.js +0 -194
- package/dist/commands/install/helpers/templates/sapApiPortalTemplates.js +0 -114
- package/dist/commands/install/helpers/templates/softwareAGWebMethodsTemplates.js +0 -93
- package/dist/commands/install/helpers/templates/traceableTemplates.js +0 -135
- package/dist/commands/install/helpers/templates/wso2Templates.js +0 -85
- package/dist/commands/install/helpers/util.js +0 -26
- package/dist/commands/install/ibmAPIConnectAgents.js +0 -213
- package/dist/commands/install/index.js +0 -36
- package/dist/commands/install/istioAgents.js +0 -346
- package/dist/commands/install/kafkaAgents.js +0 -303
- package/dist/commands/install/platform.js +0 -175
- package/dist/commands/install/sapApiPortalAgents.js +0 -198
- package/dist/commands/install/softwareAGWebMethodsAgents.js +0 -161
- package/dist/commands/install/swaggerHubSaasAgents.js +0 -272
- package/dist/commands/install/traceableAgents.js +0 -257
- package/dist/commands/install/traceableSaasAgents.js +0 -275
- package/dist/commands/install/wso2Agents.js +0 -163
- package/dist/commands/productize/helpers/productizationHelper.js +0 -408
- package/dist/commands/productize/index.js +0 -99
- package/dist/common/ApiServerClient.js +0 -1109
- package/dist/common/CacheController.js +0 -146
- package/dist/common/CliConfigManager.js +0 -76
- package/dist/common/CompositeError.js +0 -95
- package/dist/common/CoreConfigController.js +0 -174
- package/dist/common/DefinitionsManager.js +0 -298
- package/dist/common/Kubectl.js +0 -68
- package/dist/common/PlatformClient.js +0 -128
- package/dist/common/Renderer.js +0 -409
- package/dist/common/TmpFile.js +0 -96
- package/dist/common/bashCommands.js +0 -97
- package/dist/common/basicPrompts.js +0 -160
- package/dist/common/dataService.js +0 -312
- package/dist/common/errorHandler.js +0 -46
- package/dist/common/modules.d.js +0 -1
- package/dist/common/resultsRenderers.js +0 -164
- package/dist/common/types.js +0 -746
- package/dist/common/utils.js +0 -476
- package/dist/main.js +0 -8
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.verifyApigeeXCredentialFile = exports.validateValueRange = exports.validateValidRegex = exports.validateRegex = exports.validateNonEmptyInput = exports.validateInputLength = exports.validateInputIsNew = exports.runValidations = exports.filterEmptyNumberInput = exports.askUsernameAndPassword = exports.askList = exports.askInputValidation = exports.askInput = exports.MAX_FILE_SIZE = void 0;
|
|
7
|
-
var _inquirer = _interopRequireDefault(require("inquirer"));
|
|
8
|
-
var _fsExtra = require("fs-extra");
|
|
9
|
-
var _path = require("path");
|
|
10
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
-
//
|
|
12
|
-
// Basic Prompts
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @param validators At least one InputValidation func
|
|
17
|
-
* @description Executes the provided InputValidation funcs until all are successful, or one returns an error.
|
|
18
|
-
* Pass to the askInput for validation when input validation becomes complex. Provides an easy way
|
|
19
|
-
* to break down input validation into their own small functions.
|
|
20
|
-
*/
|
|
21
|
-
const runValidations = (...validators) => input => {
|
|
22
|
-
for (const validator of validators) {
|
|
23
|
-
const res = validator(input);
|
|
24
|
-
if (typeof res === 'string') return res;
|
|
25
|
-
}
|
|
26
|
-
return true;
|
|
27
|
-
};
|
|
28
|
-
exports.runValidations = runValidations;
|
|
29
|
-
const validateRegex = (regexp, message) => input => {
|
|
30
|
-
return input.toString().match(regexp) ? true : message;
|
|
31
|
-
};
|
|
32
|
-
exports.validateRegex = validateRegex;
|
|
33
|
-
const validateInputLength = (length, message) => input => {
|
|
34
|
-
return input.toString().length <= length ? true : message;
|
|
35
|
-
};
|
|
36
|
-
exports.validateInputLength = validateInputLength;
|
|
37
|
-
const MAX_FILE_SIZE = exports.MAX_FILE_SIZE = process.env.NODE_ENV === 'test' ? 1e5 : 20 * 1024 * 1024;
|
|
38
|
-
const verifyApigeeXCredentialFile = () => input => {
|
|
39
|
-
let stats;
|
|
40
|
-
let fileExtension = '';
|
|
41
|
-
try {
|
|
42
|
-
stats = (0, _fsExtra.lstatSync)(input);
|
|
43
|
-
fileExtension = (0, _path.extname)(input);
|
|
44
|
-
if (!stats.isFile()) {
|
|
45
|
-
throw new Error(`Couldn't load the credential file: ${input}`);
|
|
46
|
-
} else if (stats.size >= MAX_FILE_SIZE) {
|
|
47
|
-
throw new Error(`File size too large`);
|
|
48
|
-
} else if (fileExtension !== '.json') {
|
|
49
|
-
throw new Error(`File extension is invalid, please provide '.json' file`);
|
|
50
|
-
}
|
|
51
|
-
return true;
|
|
52
|
-
} catch (e) {
|
|
53
|
-
throw new Error(`Couldn't find the credential file: ${input}`);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
exports.verifyApigeeXCredentialFile = verifyApigeeXCredentialFile;
|
|
57
|
-
const validateValidRegex = () => input => {
|
|
58
|
-
try {
|
|
59
|
-
new RegExp(input.toString());
|
|
60
|
-
} catch (error) {
|
|
61
|
-
return 'Please provide a valid regular expression.';
|
|
62
|
-
}
|
|
63
|
-
return true;
|
|
64
|
-
};
|
|
65
|
-
exports.validateValidRegex = validateValidRegex;
|
|
66
|
-
const validateInputIsNew = (options, error) => input => {
|
|
67
|
-
const isFound = options.find(opt => opt === input);
|
|
68
|
-
return isFound ? error : true;
|
|
69
|
-
};
|
|
70
|
-
exports.validateInputIsNew = validateInputIsNew;
|
|
71
|
-
const validateValueRange = (lowerLimit, upperLimit) => input => {
|
|
72
|
-
const inputNum = Number(input);
|
|
73
|
-
if (isNaN(inputNum)) {
|
|
74
|
-
return 'Please provide a number.';
|
|
75
|
-
}
|
|
76
|
-
let msg = '';
|
|
77
|
-
if (typeof lowerLimit !== undefined && typeof upperLimit !== undefined) {
|
|
78
|
-
msg = `Please provide a number from ${lowerLimit} to ${upperLimit}`;
|
|
79
|
-
} else if (typeof lowerLimit !== undefined) {
|
|
80
|
-
msg = `Please provide a minimum number of ${lowerLimit}`;
|
|
81
|
-
} else if (typeof upperLimit !== undefined) {
|
|
82
|
-
msg = `Please provide a maximum number of ${upperLimit}`;
|
|
83
|
-
}
|
|
84
|
-
if (typeof lowerLimit !== undefined && inputNum < lowerLimit) {
|
|
85
|
-
return msg;
|
|
86
|
-
}
|
|
87
|
-
if (typeof upperLimit !== undefined && inputNum > upperLimit) {
|
|
88
|
-
return msg;
|
|
89
|
-
}
|
|
90
|
-
return true;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
// exporting for test
|
|
94
|
-
exports.validateValueRange = validateValueRange;
|
|
95
|
-
const validateNonEmptyInput = input => {
|
|
96
|
-
return String(input).length ? true : 'Please provide a non-empty value.';
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
// exporting for test
|
|
100
|
-
exports.validateNonEmptyInput = validateNonEmptyInput;
|
|
101
|
-
const filterEmptyNumberInput = input => {
|
|
102
|
-
// clear the invalid input
|
|
103
|
-
return Number.isNaN(input) ? '' : Number(input);
|
|
104
|
-
};
|
|
105
|
-
exports.filterEmptyNumberInput = filterEmptyNumberInput;
|
|
106
|
-
const askInputValidation = (allowEmptyInput, validate) => input => {
|
|
107
|
-
if (allowEmptyInput && !String(input).length) {
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
110
|
-
const isEmpty = allowEmptyInput ? true : validateNonEmptyInput(input);
|
|
111
|
-
if (typeof isEmpty === 'string') return isEmpty;
|
|
112
|
-
return validate ? validate(input) : true;
|
|
113
|
-
};
|
|
114
|
-
exports.askInputValidation = askInputValidation;
|
|
115
|
-
const askInput = async ({
|
|
116
|
-
msg,
|
|
117
|
-
defaultValue,
|
|
118
|
-
type = 'string',
|
|
119
|
-
validate,
|
|
120
|
-
allowEmptyInput = false
|
|
121
|
-
}) => {
|
|
122
|
-
const answers = await _inquirer.default.prompt({
|
|
123
|
-
type: type === 'string' ? 'input' : 'number',
|
|
124
|
-
name: 'value',
|
|
125
|
-
message: `${msg}: `,
|
|
126
|
-
default: defaultValue,
|
|
127
|
-
validate: askInputValidation(allowEmptyInput, validate),
|
|
128
|
-
filter: type === 'number' ? filterEmptyNumberInput : undefined
|
|
129
|
-
});
|
|
130
|
-
return answers.value;
|
|
131
|
-
};
|
|
132
|
-
exports.askInput = askInput;
|
|
133
|
-
const askList = async opts => {
|
|
134
|
-
const answers = await _inquirer.default.prompt({
|
|
135
|
-
type: 'list',
|
|
136
|
-
name: 'value',
|
|
137
|
-
message: `${opts.msg}: `,
|
|
138
|
-
choices: opts.choices,
|
|
139
|
-
default: opts.default
|
|
140
|
-
});
|
|
141
|
-
return answers.value;
|
|
142
|
-
};
|
|
143
|
-
exports.askList = askList;
|
|
144
|
-
const askUsernameAndPassword = async (msg, defaultUsername) => {
|
|
145
|
-
const answers = await _inquirer.default.prompt([{
|
|
146
|
-
type: 'input',
|
|
147
|
-
name: 'username',
|
|
148
|
-
message: `Enter ${msg} username: `,
|
|
149
|
-
default: defaultUsername,
|
|
150
|
-
validate: validateNonEmptyInput
|
|
151
|
-
}, {
|
|
152
|
-
type: 'password',
|
|
153
|
-
name: 'password',
|
|
154
|
-
mask: '*',
|
|
155
|
-
message: `Enter ${msg} password: `,
|
|
156
|
-
validate: validateNonEmptyInput
|
|
157
|
-
}]);
|
|
158
|
-
return answers;
|
|
159
|
-
};
|
|
160
|
-
exports.askUsernameAndPassword = askUsernameAndPassword;
|
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getBaseUrl = exports.dataService = void 0;
|
|
7
|
-
var _amplifyCliUtils = require("@axway/amplify-cli-utils");
|
|
8
|
-
var _got = require("got");
|
|
9
|
-
var _flatten = _interopRequireDefault(require("lodash/flatten"));
|
|
10
|
-
var _promiseLimit = _interopRequireDefault(require("promise-limit"));
|
|
11
|
-
var _snooplogg = _interopRequireDefault(require("snooplogg"));
|
|
12
|
-
var _url = require("url");
|
|
13
|
-
var _CoreConfigController = require("./CoreConfigController");
|
|
14
|
-
var _types = require("./types");
|
|
15
|
-
var _utils = require("./utils");
|
|
16
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
|
-
// NOTE: removing update-notifier due to some security issues reported.
|
|
18
|
-
// There is suppression in '.csr-profile.json' that needed to be removed if this library is used in production code.
|
|
19
|
-
// import updateNotifier from 'update-notifier';
|
|
20
|
-
// import semver from 'semver';
|
|
21
|
-
|
|
22
|
-
// dep of @axway/amplify-cli-utils -> @axway/amplify-request
|
|
23
|
-
|
|
24
|
-
const thisPackage = require('../../package.json');
|
|
25
|
-
const {
|
|
26
|
-
log
|
|
27
|
-
} = (0, _snooplogg.default)('central: dataService');
|
|
28
|
-
const getDefaultHeaders = ({
|
|
29
|
-
token,
|
|
30
|
-
orgId
|
|
31
|
-
}) => {
|
|
32
|
-
return {
|
|
33
|
-
accept: 'application/json',
|
|
34
|
-
authorization: `Bearer ${token}`,
|
|
35
|
-
'X-Axway-Tenant-Id': orgId || '',
|
|
36
|
-
[_types.cliVersionHeader]: thisPackage.version,
|
|
37
|
-
'User-Agent': 'axway-cli'
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// TODO: need to refactor this part, data service is used as part of many basic command (create / update, etc.) now.
|
|
42
|
-
// Plus need to revisit this logic since no testing can be done currently (no new prod versions has been released yet)
|
|
43
|
-
// https://jira.axway.com/browse/APIGOV-14969
|
|
44
|
-
// const versionCheckWarning = async () => {
|
|
45
|
-
// const notifier = updateNotifier({ pkg: thisPackage, updateCheckInterval: 1000 * 300 });
|
|
46
|
-
// const latestCliVersion = notifier.update && notifier.update.latest;
|
|
47
|
-
// const currentCliVersion = thisPackage.version;
|
|
48
|
-
// if (latestCliVersion)
|
|
49
|
-
// if (semver.lt(currentCliVersion, latestCliVersion)) {
|
|
50
|
-
// console.log(
|
|
51
|
-
// chalk.red.bgWhite(`\n\n WARNING:`),
|
|
52
|
-
// chalk.white(`Update available ${currentCliVersion} → ${latestCliVersion}`)
|
|
53
|
-
// );
|
|
54
|
-
// console.log(`Run "amplify pm update central" to update.`);
|
|
55
|
-
// }
|
|
56
|
-
// };
|
|
57
|
-
|
|
58
|
-
const getBaseUrl = async (baseUrl, basePath, region, orgRegion) => {
|
|
59
|
-
const configuredBaseUrl = baseUrl || process.env.AXWAY_CENTRAL_BASE_URL || (await (0, _utils.getConfig)())[_types.ConfigTypes.BASE_URL];
|
|
60
|
-
if (configuredBaseUrl) {
|
|
61
|
-
return basePath ? configuredBaseUrl + basePath : configuredBaseUrl;
|
|
62
|
-
} else {
|
|
63
|
-
const configRegion = (await (0, _utils.getConfig)())[_types.ConfigTypes.REGION];
|
|
64
|
-
const configuredRegion = String(region || configRegion || orgRegion || _types.Regions.US).toUpperCase();
|
|
65
|
-
log(`Using region "${configuredRegion}" from ${region ? '--region' : configRegion ? 'config' : orgRegion ? 'org' : 'default'}`);
|
|
66
|
-
const prodBaseurl = _types.ProdBaseUrls[configuredRegion];
|
|
67
|
-
if (!prodBaseurl) throw Error('Unknown region provided, check your region config, should be one of: ' + Object.keys(_types.ProdBaseUrls).join(', '));
|
|
68
|
-
return basePath ? prodBaseurl + basePath : prodBaseurl;
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
exports.getBaseUrl = getBaseUrl;
|
|
72
|
-
const handleResponse = response => {
|
|
73
|
-
return /application\/json/.test(response.headers['content-type']) ? JSON.parse(response.body) : response.body;
|
|
74
|
-
};
|
|
75
|
-
const updateRequestError = err => {
|
|
76
|
-
var _err$response;
|
|
77
|
-
// Do not change given object if it's a timeout error.
|
|
78
|
-
if (err instanceof _got.TimeoutError) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// If we have a JSON HTTP body, then turn it into a dictionary.
|
|
83
|
-
let jsonBody = null;
|
|
84
|
-
if (err instanceof _got.RequestError && (_err$response = err.response) !== null && _err$response !== void 0 && _err$response.body) {
|
|
85
|
-
jsonBody = handleResponse(err.response);
|
|
86
|
-
}
|
|
87
|
-
if (!jsonBody) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Turn given Error object into an "ApiServerError" or "ApiServerErrorResponse" object.
|
|
92
|
-
if (typeof jsonBody.code === 'number' && typeof jsonBody.description === 'string') {
|
|
93
|
-
// We received a "Platform" server error response.
|
|
94
|
-
err.status = jsonBody.code;
|
|
95
|
-
err.detail = jsonBody.description;
|
|
96
|
-
} else {
|
|
97
|
-
// Assume we received a "Central" server error response which should already conform to "ApiServerError".
|
|
98
|
-
Object.assign(err, jsonBody);
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Creates an object with various functions communicating with the API Server.
|
|
104
|
-
* @param {String} clientId Client id to use.
|
|
105
|
-
* @param {String} [team] The preferred team to use. This value overrides the default from the Axway CLI config.
|
|
106
|
-
* @param {String} [region] The preferred region to use.
|
|
107
|
-
* @returns Object containing data retrieval functions.
|
|
108
|
-
*/
|
|
109
|
-
const dataService = async ({
|
|
110
|
-
account,
|
|
111
|
-
baseUrl,
|
|
112
|
-
basePath = _types.BasePaths.ApiServer,
|
|
113
|
-
clientId,
|
|
114
|
-
region,
|
|
115
|
-
team,
|
|
116
|
-
forceGetAuthInfo
|
|
117
|
-
}) => {
|
|
118
|
-
// see above
|
|
119
|
-
// await versionCheckWarning();
|
|
120
|
-
const {
|
|
121
|
-
orgId,
|
|
122
|
-
orgRegion,
|
|
123
|
-
teamGuid,
|
|
124
|
-
token
|
|
125
|
-
} = await new _CoreConfigController.CoreConfigController().getAuthInfo({
|
|
126
|
-
account,
|
|
127
|
-
clientId,
|
|
128
|
-
team,
|
|
129
|
-
forceGetAuthInfo
|
|
130
|
-
});
|
|
131
|
-
baseUrl = await getBaseUrl(baseUrl, basePath, region, orgRegion);
|
|
132
|
-
const defaultHeaders = getDefaultHeaders({
|
|
133
|
-
orgId,
|
|
134
|
-
token
|
|
135
|
-
});
|
|
136
|
-
const got = (0, _amplifyCliUtils.createRequestClient)();
|
|
137
|
-
const fetch = async (method, url, params = {}) => {
|
|
138
|
-
try {
|
|
139
|
-
// add the team guid
|
|
140
|
-
if (teamGuid !== undefined) {
|
|
141
|
-
const parsed = new _url.URL(url);
|
|
142
|
-
parsed.searchParams.set('query', teamGuid ? `owner.id==${teamGuid},(owner.id==null;metadata.scope.owner.id==${teamGuid})` : 'owner.id==null');
|
|
143
|
-
url = parsed.toString();
|
|
144
|
-
}
|
|
145
|
-
const response = await got[method](url, {
|
|
146
|
-
followRedirect: false,
|
|
147
|
-
retry: 0,
|
|
148
|
-
timeout: _types.ABORT_TIMEOUT,
|
|
149
|
-
...params
|
|
150
|
-
});
|
|
151
|
-
if (response.statusCode === 301 || response.statusCode === 302) {
|
|
152
|
-
log(`${method.toUpperCase()}: ${url} ${response.statusCode} redirecting to ${response.headers.location}`);
|
|
153
|
-
return await fetch(method, response.headers.location, params);
|
|
154
|
-
}
|
|
155
|
-
return response;
|
|
156
|
-
} catch (err) {
|
|
157
|
-
updateRequestError(err);
|
|
158
|
-
throw err;
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
return {
|
|
162
|
-
postFormData: (route, body, headers = {}) => {
|
|
163
|
-
log(`POST (from data): ${baseUrl + route}`);
|
|
164
|
-
return fetch('post', baseUrl + route, {
|
|
165
|
-
headers: {
|
|
166
|
-
...defaultHeaders,
|
|
167
|
-
...body.getHeaders(),
|
|
168
|
-
...headers
|
|
169
|
-
},
|
|
170
|
-
body
|
|
171
|
-
}).then(handleResponse);
|
|
172
|
-
},
|
|
173
|
-
post: (route, data, headers = {}) => {
|
|
174
|
-
log(`POST: ${baseUrl + route}`);
|
|
175
|
-
log(data);
|
|
176
|
-
return fetch('post', baseUrl + route, {
|
|
177
|
-
headers: {
|
|
178
|
-
...defaultHeaders,
|
|
179
|
-
...headers
|
|
180
|
-
},
|
|
181
|
-
json: data
|
|
182
|
-
}).then(handleResponse);
|
|
183
|
-
},
|
|
184
|
-
put: (route, data, headers = {}) => {
|
|
185
|
-
log(`PUT: ${baseUrl + route}`);
|
|
186
|
-
return fetch('put', baseUrl + route, {
|
|
187
|
-
headers: {
|
|
188
|
-
...defaultHeaders,
|
|
189
|
-
...headers
|
|
190
|
-
},
|
|
191
|
-
json: data
|
|
192
|
-
}).then(handleResponse);
|
|
193
|
-
},
|
|
194
|
-
get: (route, headers = {}, skipDefaultHeaders = false) => {
|
|
195
|
-
const h = skipDefaultHeaders ? headers : {
|
|
196
|
-
...defaultHeaders,
|
|
197
|
-
...headers
|
|
198
|
-
};
|
|
199
|
-
log(`GET: ${baseUrl + route}`, h);
|
|
200
|
-
return fetch('get', baseUrl + route, {
|
|
201
|
-
headers: h
|
|
202
|
-
}).then(handleResponse);
|
|
203
|
-
},
|
|
204
|
-
head: (route, queryParams, headers = {}, skipDefaultHeaders = false) => {
|
|
205
|
-
const h = skipDefaultHeaders ? headers : {
|
|
206
|
-
...defaultHeaders,
|
|
207
|
-
...headers
|
|
208
|
-
};
|
|
209
|
-
log(`HEAD: ${baseUrl + route}`, h);
|
|
210
|
-
const fullUrl = new _url.URL(baseUrl + route);
|
|
211
|
-
if (queryParams) {
|
|
212
|
-
fullUrl.searchParams.set('query', queryParams);
|
|
213
|
-
}
|
|
214
|
-
return fetch('head', fullUrl.toString(), {
|
|
215
|
-
headers: h
|
|
216
|
-
}).then(response => {
|
|
217
|
-
return response.headers['x-axway-total-count'];
|
|
218
|
-
});
|
|
219
|
-
},
|
|
220
|
-
/**
|
|
221
|
-
* Get the entire list using pagination. Method is trying to define total number of items based on response header
|
|
222
|
-
* and makes additional calls if needed to retrieve additional pages.
|
|
223
|
-
* Note: currently this only present correct results if response is an array (see the "allPages" var spread logic)
|
|
224
|
-
* @param route route to hit
|
|
225
|
-
* @param queryParams specific query params
|
|
226
|
-
* @param pageSize page size to use, by default = 50
|
|
227
|
-
* @param headers headers to add
|
|
228
|
-
* @param progressListener invoked multiple times where argument is assigned progress value 0-100
|
|
229
|
-
*/
|
|
230
|
-
getWithPagination: async function (route, queryParams = '', pageSize = 50, headers = {}, progressListener) {
|
|
231
|
-
const fullUrl = new _url.URL(baseUrl + route);
|
|
232
|
-
if (queryParams) {
|
|
233
|
-
fullUrl.searchParams.set('query', queryParams);
|
|
234
|
-
}
|
|
235
|
-
fullUrl.searchParams.set('pageSize', `${pageSize}`);
|
|
236
|
-
log(`GET (with auto-pagination): ${fullUrl.href}`);
|
|
237
|
-
const response = await fetch('get', fullUrl.toString(), {
|
|
238
|
-
headers: {
|
|
239
|
-
...defaultHeaders,
|
|
240
|
-
...headers
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
const totalCountHeader = response.headers['x-axway-total-count'];
|
|
244
|
-
if (totalCountHeader === null || totalCountHeader === undefined) {
|
|
245
|
-
log(`GET (with auto-pagination), warning: cannot figure out 'total count' header, resolving response as-is`);
|
|
246
|
-
return handleResponse(response);
|
|
247
|
-
}
|
|
248
|
-
log(`GET (with auto-pagination), 'total count' header found, count = ${totalCountHeader}, will fire additional GET calls if needed`);
|
|
249
|
-
const totalPages = Math.max(Math.ceil(Number(totalCountHeader) / pageSize), 1);
|
|
250
|
-
const allPages = new Array(totalPages);
|
|
251
|
-
allPages[0] = handleResponse(response);
|
|
252
|
-
if (totalPages > 1) {
|
|
253
|
-
const limit = (0, _promiseLimit.default)(8); // Limits number of concurrrent HTTP requests.
|
|
254
|
-
const otherPagesCalls = [];
|
|
255
|
-
let pageDownloadCount = 1;
|
|
256
|
-
const updateProgress = () => {
|
|
257
|
-
if (progressListener && totalPages > 4) {
|
|
258
|
-
progressListener(Math.floor(pageDownloadCount / totalPages * 100));
|
|
259
|
-
}
|
|
260
|
-
};
|
|
261
|
-
updateProgress();
|
|
262
|
-
for (let pageIndex = 1; pageIndex < totalPages; pageIndex++) {
|
|
263
|
-
const thisPageIndex = pageIndex;
|
|
264
|
-
fullUrl.searchParams.set('page', `${thisPageIndex + 1}`);
|
|
265
|
-
const nextRoute = fullUrl.href.substring(baseUrl.length);
|
|
266
|
-
otherPagesCalls.push(limit(async () => {
|
|
267
|
-
allPages[thisPageIndex] = await this.get(nextRoute, headers);
|
|
268
|
-
pageDownloadCount++;
|
|
269
|
-
updateProgress();
|
|
270
|
-
}));
|
|
271
|
-
}
|
|
272
|
-
await Promise.all(otherPagesCalls);
|
|
273
|
-
}
|
|
274
|
-
return (0, _flatten.default)(allPages);
|
|
275
|
-
},
|
|
276
|
-
delete: (route, headers = {}) => {
|
|
277
|
-
log(`DELETE: ${baseUrl + route}`);
|
|
278
|
-
return fetch('delete', baseUrl + route, {
|
|
279
|
-
headers: {
|
|
280
|
-
...defaultHeaders,
|
|
281
|
-
...headers
|
|
282
|
-
}
|
|
283
|
-
}).then(handleResponse);
|
|
284
|
-
},
|
|
285
|
-
download: async route => {
|
|
286
|
-
try {
|
|
287
|
-
return await new Promise((resolve, reject) => {
|
|
288
|
-
log(`DOWNLOAD: ${baseUrl + route}`);
|
|
289
|
-
const stream = got.stream(baseUrl + route, {
|
|
290
|
-
retry: 0,
|
|
291
|
-
timeout: _types.ABORT_TIMEOUT
|
|
292
|
-
});
|
|
293
|
-
stream.on('response', response => {
|
|
294
|
-
if (response.statusCode < 300) {
|
|
295
|
-
resolve({
|
|
296
|
-
response,
|
|
297
|
-
stream
|
|
298
|
-
});
|
|
299
|
-
} else {
|
|
300
|
-
reject(new Error());
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
stream.on('error', reject);
|
|
304
|
-
});
|
|
305
|
-
} catch (err) {
|
|
306
|
-
updateRequestError(err);
|
|
307
|
-
throw err;
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
};
|
|
311
|
-
};
|
|
312
|
-
exports.dataService = dataService;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.handleErrors = void 0;
|
|
7
|
-
var _cliKit = require("cli-kit");
|
|
8
|
-
// TODO: used by legacy "proxies" command only, will be removed soon
|
|
9
|
-
// https://jira.axway.com/browse/APIGOV-20818
|
|
10
|
-
const handleErrors = (console, e, spinner) => {
|
|
11
|
-
if (e.errors && Array.isArray(e.errors)) {
|
|
12
|
-
const error = e.errors[0];
|
|
13
|
-
if (spinner) {
|
|
14
|
-
switch (error.status) {
|
|
15
|
-
case 401:
|
|
16
|
-
spinner.fail((0, _cliKit.chalk)`{red Error: ${error.title || `Looks like you're not authenticated!`}}`);
|
|
17
|
-
console.info('\nTry running:');
|
|
18
|
-
console.info((0, _cliKit.chalk)`{cyan axway auth login}`);
|
|
19
|
-
console.info('Or if using a service account:');
|
|
20
|
-
console.info((0, _cliKit.chalk)`{cyan axway auth login --client-id <Service Account Client ID> --secret-file <Private Key>}`);
|
|
21
|
-
break;
|
|
22
|
-
case 403:
|
|
23
|
-
spinner.fail((0, _cliKit.chalk)`{red ${error.detail}}`);
|
|
24
|
-
break;
|
|
25
|
-
case 400:
|
|
26
|
-
spinner.fail((0, _cliKit.chalk)`{red Error: ${error.detail || error.title}}`);
|
|
27
|
-
if (error.source) console.log((0, _cliKit.chalk)`{gray Caused by: ${JSON.stringify(error.source)}}`);
|
|
28
|
-
break;
|
|
29
|
-
case 404:
|
|
30
|
-
case 409:
|
|
31
|
-
spinner.fail((0, _cliKit.chalk)`{red ${error.title}\n{blueBright ${error.detail}}}`);
|
|
32
|
-
break;
|
|
33
|
-
default:
|
|
34
|
-
spinner.fail((0, _cliKit.chalk)`{red An error occurred}`);
|
|
35
|
-
}
|
|
36
|
-
} else {
|
|
37
|
-
console.error(error);
|
|
38
|
-
}
|
|
39
|
-
process.exit(1);
|
|
40
|
-
} else if (e instanceof Error) {
|
|
41
|
-
let message = e.name === 'TimeoutError' ? `Couldn't connect to Amplify Central` : e.message;
|
|
42
|
-
spinner ? spinner.fail((0, _cliKit.chalk)`{red ${message}}`) : console.error(message);
|
|
43
|
-
process.exit(1);
|
|
44
|
-
} else throw e;
|
|
45
|
-
};
|
|
46
|
-
exports.handleErrors = handleErrors;
|
package/dist/common/modules.d.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.renderResponse = exports.parseAsYaml = exports.parseAsJson = void 0;
|
|
7
|
-
exports.resolveTeamNames = resolveTeamNames;
|
|
8
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
9
|
-
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
10
|
-
var _easyTable = _interopRequireDefault(require("easy-table"));
|
|
11
|
-
var _jsYaml = require("js-yaml");
|
|
12
|
-
var _get = _interopRequireDefault(require("lodash/get"));
|
|
13
|
-
var _set = _interopRequireDefault(require("lodash/set"));
|
|
14
|
-
var _CoreConfigController = require("./CoreConfigController");
|
|
15
|
-
var _amplifyCliUtils = require("@axway/amplify-cli-utils");
|
|
16
|
-
var _types = require("./types");
|
|
17
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
-
/**
|
|
19
|
-
* HACK: removing "---" delimiter printing from the lib.
|
|
20
|
-
* Currently this is not supported in library itself so have to override prototype methods.
|
|
21
|
-
*/
|
|
22
|
-
_easyTable.default.prototype.pushDelimeter = function () {
|
|
23
|
-
return this;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Parse JSON object | array of objects as YAML
|
|
28
|
-
* @param response request response payload
|
|
29
|
-
* @param console current console
|
|
30
|
-
* @returns parsed string with YAML objects representation
|
|
31
|
-
*/
|
|
32
|
-
const parseAsYaml = response => {
|
|
33
|
-
let result = '';
|
|
34
|
-
if (Array.isArray(response)) {
|
|
35
|
-
for (const i of response) {
|
|
36
|
-
result += `\n---\n${(0, _jsYaml.dump)(i)}`;
|
|
37
|
-
}
|
|
38
|
-
} else {
|
|
39
|
-
result = (0, _jsYaml.dump)(response);
|
|
40
|
-
}
|
|
41
|
-
return result;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Parse JSON object | array of objects as simple text table,
|
|
46
|
-
* NOTE: currently can build table only for "Environment" type.
|
|
47
|
-
* @param response request response payload
|
|
48
|
-
* @param console current console
|
|
49
|
-
* @param columns columns config from CommandLineInterface resource definition
|
|
50
|
-
* @returns parsed string with table objects representation
|
|
51
|
-
*/
|
|
52
|
-
exports.parseAsYaml = parseAsYaml;
|
|
53
|
-
const parseAsTable = (response, columns) => {
|
|
54
|
-
const data = Array.isArray(response) ? response : [response];
|
|
55
|
-
const t = new _easyTable.default();
|
|
56
|
-
for (const i of data) {
|
|
57
|
-
for (const col of columns) {
|
|
58
|
-
// jsonPath starts with '.' so using the substring
|
|
59
|
-
let value = (0, _get.default)(i, col.jsonPath.substring(1));
|
|
60
|
-
let deletingState = (0, _get.default)(i, "metadata.state");
|
|
61
|
-
if (col.type === 'date') {
|
|
62
|
-
value = (0, _dayjs.default)(value).fromNow();
|
|
63
|
-
} else if (col.type === 'teamGuid' && !value) {
|
|
64
|
-
value = _chalk.default.gray('---');
|
|
65
|
-
} else if (value && value.length > _types.MAX_TABLE_STRING_LENGTH + 3) {
|
|
66
|
-
value = value.substring(0, _types.MAX_TABLE_STRING_LENGTH / 2) + '...' + value.substring(value.length - _types.MAX_TABLE_STRING_LENGTH / 2);
|
|
67
|
-
}
|
|
68
|
-
if (deletingState) {
|
|
69
|
-
t.cell(col.name.toUpperCase(), _chalk.default.yellow(value));
|
|
70
|
-
} else {
|
|
71
|
-
t.cell(col.name.toUpperCase(), value);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
t.newRow();
|
|
75
|
-
}
|
|
76
|
-
return data.length ? `\n${t.toString()}` : '\nNo resources found.';
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Parse JSON object | array of objects as is but without any replacing like [object Object].
|
|
81
|
-
* @param response request response payload
|
|
82
|
-
* @param console current console
|
|
83
|
-
* @returns parsed string with JSON objects representation
|
|
84
|
-
*/
|
|
85
|
-
const parseAsJson = response => JSON.stringify(response, null, 4);
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Util function to render JSON object | array of objects based on output type provided
|
|
89
|
-
* @param response request response payload
|
|
90
|
-
* @param output type of output to render (table (default) / yaml / json)
|
|
91
|
-
* @param console current console
|
|
92
|
-
*/
|
|
93
|
-
exports.parseAsJson = parseAsJson;
|
|
94
|
-
const renderResponse = (console, response, output, columns) => {
|
|
95
|
-
switch (output) {
|
|
96
|
-
case _types.OutputTypes.yaml:
|
|
97
|
-
console.log(parseAsYaml(response));
|
|
98
|
-
break;
|
|
99
|
-
case _types.OutputTypes.json:
|
|
100
|
-
console.log(parseAsJson(response));
|
|
101
|
-
break;
|
|
102
|
-
default:
|
|
103
|
-
// @ts-ignore TODO: fix types error once more types are used
|
|
104
|
-
console.log(parseAsTable(response, columns));
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
exports.renderResponse = renderResponse;
|
|
108
|
-
/**
|
|
109
|
-
* If a team guid column is being rendered, it resolves the team name and injects it into
|
|
110
|
-
* the response payload.
|
|
111
|
-
* @param columns an array of columns being rendered
|
|
112
|
-
* @param response request response payload
|
|
113
|
-
*/
|
|
114
|
-
async function resolveTeamNames({
|
|
115
|
-
columns,
|
|
116
|
-
response
|
|
117
|
-
}) {
|
|
118
|
-
// check that we even have a team guid column
|
|
119
|
-
const column = columns === null || columns === void 0 ? void 0 : columns.find(col => col.type === 'teamGuid');
|
|
120
|
-
if (!column || !_CoreConfigController.CoreConfigController.devOpsAccount) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
const jsonPath = column.jsonPath.substring(1);
|
|
124
|
-
const results = Array.isArray(response) ? response : [response];
|
|
125
|
-
const teamNames = {};
|
|
126
|
-
const {
|
|
127
|
-
devOpsAccount
|
|
128
|
-
} = _CoreConfigController.CoreConfigController;
|
|
129
|
-
const {
|
|
130
|
-
sdk
|
|
131
|
-
} = (0, _amplifyCliUtils.initSDK)({
|
|
132
|
-
env: devOpsAccount.auth.env
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
// build the team name lookup
|
|
136
|
-
const {
|
|
137
|
-
teams
|
|
138
|
-
} = await sdk.team.list(devOpsAccount);
|
|
139
|
-
for (const team of teams) {
|
|
140
|
-
teamNames[team.guid] = team.name;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// create the new jsonPath and update the column
|
|
144
|
-
const targetJsonPath = jsonPath.split('.').slice(0, -1).join('.') + '.teamName';
|
|
145
|
-
column.jsonPath = `.${targetJsonPath}`;
|
|
146
|
-
|
|
147
|
-
// next loop over data and set the team name
|
|
148
|
-
for (let {
|
|
149
|
-
data
|
|
150
|
-
} of results) {
|
|
151
|
-
if (!data || typeof data !== 'object') {
|
|
152
|
-
continue;
|
|
153
|
-
}
|
|
154
|
-
if (!Array.isArray(data)) {
|
|
155
|
-
data = [data];
|
|
156
|
-
}
|
|
157
|
-
for (const obj of data) {
|
|
158
|
-
const value = (0, _get.default)(obj, jsonPath, null);
|
|
159
|
-
if (value !== null) {
|
|
160
|
-
(0, _set.default)(obj, targetJsonPath, value && teamNames[value] || value || '');
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|