@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,1109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.ApiServerVersions = exports.ApiServerClient = void 0;
|
|
7
|
-
var _assign = _interopRequireDefault(require("lodash/assign"));
|
|
8
|
-
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
9
|
-
var _pickBy = _interopRequireDefault(require("lodash/pickBy"));
|
|
10
|
-
var _snooplogg = _interopRequireDefault(require("snooplogg"));
|
|
11
|
-
var _CacheController = require("./CacheController");
|
|
12
|
-
var _dataService = require("./dataService");
|
|
13
|
-
var _types = require("./types");
|
|
14
|
-
var _utils = require("./utils");
|
|
15
|
-
var _chalk = _interopRequireDefault(require("chalk"));
|
|
16
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
|
-
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
18
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
19
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
20
|
-
const {
|
|
21
|
-
log
|
|
22
|
-
} = (0, _snooplogg.default)('central:class.ApiServerClient');
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* ApiServer backend types
|
|
26
|
-
*/
|
|
27
|
-
let ApiServerVersions = exports.ApiServerVersions = /*#__PURE__*/function (ApiServerVersions) {
|
|
28
|
-
ApiServerVersions["v1alpha1"] = "v1alpha1";
|
|
29
|
-
return ApiServerVersions;
|
|
30
|
-
}({});
|
|
31
|
-
/**
|
|
32
|
-
* Client's types
|
|
33
|
-
*/
|
|
34
|
-
class ApiServerClient {
|
|
35
|
-
/**
|
|
36
|
-
* Init temporary file if "data" is provided - write data to file (as YAML at the moment)
|
|
37
|
-
* @param {object} data optional data to write while creating file
|
|
38
|
-
*/
|
|
39
|
-
constructor({
|
|
40
|
-
baseUrl,
|
|
41
|
-
region,
|
|
42
|
-
account,
|
|
43
|
-
useCache,
|
|
44
|
-
team,
|
|
45
|
-
forceGetAuthInfo
|
|
46
|
-
} = {}) {
|
|
47
|
-
_defineProperty(this, "baseUrl", void 0);
|
|
48
|
-
_defineProperty(this, "region", void 0);
|
|
49
|
-
_defineProperty(this, "useCache", void 0);
|
|
50
|
-
_defineProperty(this, "account", void 0);
|
|
51
|
-
_defineProperty(this, "team", void 0);
|
|
52
|
-
_defineProperty(this, "forceGetAuthInfo", void 0);
|
|
53
|
-
log(`initializing client with params: baseUrl = ${baseUrl}, region = ${region}, account = ${account}, useCache = ${useCache}, team = ${team}`);
|
|
54
|
-
this.baseUrl = baseUrl;
|
|
55
|
-
this.account = account;
|
|
56
|
-
this.region = region;
|
|
57
|
-
this.useCache = useCache === undefined ? true : useCache; // using cache by default
|
|
58
|
-
this.team = team;
|
|
59
|
-
this.forceGetAuthInfo = forceGetAuthInfo;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Build resource url based on its ResourceDefinition and passed scope def and name.
|
|
64
|
-
* Note that for scope url part both name and def needed.
|
|
65
|
-
* The returned URL path is expected to be appended to the base URL.
|
|
66
|
-
*/
|
|
67
|
-
buildResourceUrlPath({
|
|
68
|
-
resourceDef,
|
|
69
|
-
resourceName,
|
|
70
|
-
scopeDef,
|
|
71
|
-
scopeName,
|
|
72
|
-
version = ApiServerVersions.v1alpha1,
|
|
73
|
-
forceDelete = false,
|
|
74
|
-
expand,
|
|
75
|
-
langDef,
|
|
76
|
-
fieldSet,
|
|
77
|
-
embed
|
|
78
|
-
}) {
|
|
79
|
-
const groupUrl = `/${resourceDef.metadata.scope.name}/${version}`;
|
|
80
|
-
const scopeUrl = scopeName && scopeDef ? `/${scopeDef.spec.plural}/${encodeURIComponent(scopeName)}` : '';
|
|
81
|
-
const resourceUrl = `/${resourceDef.spec.plural}`;
|
|
82
|
-
const nameUrl = resourceName ? `/${encodeURIComponent(resourceName)}` : '';
|
|
83
|
-
const embedSet = new Set(embed === null || embed === void 0 ? void 0 : embed.split(','));
|
|
84
|
-
const expandSet = new Set(expand === null || expand === void 0 ? void 0 : expand.split(','));
|
|
85
|
-
if (langDef) {
|
|
86
|
-
var _fieldSet;
|
|
87
|
-
(_fieldSet = fieldSet) !== null && _fieldSet !== void 0 ? _fieldSet : fieldSet = new Set();
|
|
88
|
-
fieldSet.add('languages').add('group').add('apiVersion').add('name').add('kind').add('metadata');
|
|
89
|
-
expandSet.add('languages');
|
|
90
|
-
let languageTypesArr = [];
|
|
91
|
-
Object.keys(_types.LanguageTypes).forEach(key => languageTypesArr.push((0, _utils.ValueFromKey)(_types.LanguageTypes, key)));
|
|
92
|
-
langDef.split(',').forEach(code => {
|
|
93
|
-
if (languageTypesArr.includes(code)) {
|
|
94
|
-
embedSet.add(`languages-${code.trim()}.resource`);
|
|
95
|
-
expandSet.add(`languages-${code.trim()}`);
|
|
96
|
-
fieldSet.add(`languages-${code.trim()}.values`);
|
|
97
|
-
} else if (code.trim().length > 0) {
|
|
98
|
-
console.log(_chalk.default.yellow(`\n\'${code}\' language code is not supported. Allowed language codes: ${_types.LanguageTypes.French} | ${_types.LanguageTypes.German} | ${_types.LanguageTypes.US} | ${_types.LanguageTypes.Portugese}.'`));
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
let url = `${groupUrl}${scopeUrl}${resourceUrl}${nameUrl}`;
|
|
103
|
-
if (forceDelete || embedSet.size || expandSet.size || fieldSet) {
|
|
104
|
-
const queryParams = [];
|
|
105
|
-
if (forceDelete) {
|
|
106
|
-
queryParams.push('forceDelete=true');
|
|
107
|
-
}
|
|
108
|
-
if (embedSet.size) {
|
|
109
|
-
queryParams.push('embed=' + [...embedSet].join(','));
|
|
110
|
-
}
|
|
111
|
-
if (expandSet.size) {
|
|
112
|
-
queryParams.push('expand=' + [...expandSet].join(','));
|
|
113
|
-
}
|
|
114
|
-
if (fieldSet) {
|
|
115
|
-
// If field set is empty, then return no fields. This is intentional.
|
|
116
|
-
queryParams.push('fields=' + [...fieldSet].join(','));
|
|
117
|
-
}
|
|
118
|
-
url += '?' + queryParams.join('&');
|
|
119
|
-
}
|
|
120
|
-
return url;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Generates an array of PUT requests for sub-resources based on resource input
|
|
125
|
-
*
|
|
126
|
-
* @param {Object} args function expects arguments as an object
|
|
127
|
-
* @param {GenericResource} args.resource resource input (not the APIs response)
|
|
128
|
-
* @param {string} args.resourceName resource name
|
|
129
|
-
* @param {string} args.subResourceName subresource name
|
|
130
|
-
* @param {ResourceDefinition} args.resourceDef resource definition
|
|
131
|
-
* @param {string} [args.scopeName] scope name
|
|
132
|
-
* @param {ResourceDefinition} [args.scopeDef] scope definition
|
|
133
|
-
* @param {string} [args.version] api's version
|
|
134
|
-
* @returns {Promise<Array<() => Promise<any> | null>} returns an array of "request creators" functions
|
|
135
|
-
* that will be used in {@link resolveSubResourcesRequests} to create sub-resources when needed
|
|
136
|
-
*/
|
|
137
|
-
async generateSubResourcesRequests({
|
|
138
|
-
resource,
|
|
139
|
-
resourceName,
|
|
140
|
-
subResourceName,
|
|
141
|
-
resourceDef,
|
|
142
|
-
scopeDef,
|
|
143
|
-
scopeName,
|
|
144
|
-
version,
|
|
145
|
-
createAction,
|
|
146
|
-
language
|
|
147
|
-
}) {
|
|
148
|
-
var _resourceDef$spec$sub, _resourceDef$spec$sub2;
|
|
149
|
-
const service = await (0, _dataService.dataService)({
|
|
150
|
-
baseUrl: this.baseUrl,
|
|
151
|
-
region: this.region,
|
|
152
|
-
account: this.account,
|
|
153
|
-
team: this.team
|
|
154
|
-
});
|
|
155
|
-
const urlPath = this.buildResourceUrlPath({
|
|
156
|
-
resourceDef,
|
|
157
|
-
resourceName,
|
|
158
|
-
scopeDef,
|
|
159
|
-
scopeName,
|
|
160
|
-
version
|
|
161
|
-
});
|
|
162
|
-
const knownSubResourcesNames = (_resourceDef$spec$sub = (_resourceDef$spec$sub2 = resourceDef.spec.subResources) === null || _resourceDef$spec$sub2 === void 0 ? void 0 : _resourceDef$spec$sub2.names) !== null && _resourceDef$spec$sub !== void 0 ? _resourceDef$spec$sub : [];
|
|
163
|
-
const foundSubResources = (0, _pickBy.default)(resource, (_, key) => {
|
|
164
|
-
if (key.startsWith('x-') || knownSubResourcesNames.includes(key)) {
|
|
165
|
-
return !subResourceName || subResourceName === key;
|
|
166
|
-
}
|
|
167
|
-
return false;
|
|
168
|
-
});
|
|
169
|
-
if (language) {
|
|
170
|
-
const langSubResourcesNames = (0, _utils.createLanguageSubresourceNames)(language);
|
|
171
|
-
langSubResourcesNames.forEach(name => {
|
|
172
|
-
if (!Object.keys(foundSubResources).includes(name) && name !== 'languages') {
|
|
173
|
-
console.log(_chalk.default.yellow(`\n\'${name}\' subresource definition not found, hence create/update cannot be performed on \'${name}\' subresource.`));
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
Object.keys(foundSubResources).forEach(subRes => {
|
|
177
|
-
if (!langSubResourcesNames.includes(subRes)) {
|
|
178
|
-
// For create, only delete the language subresources that are not passed in the 'language' argument.
|
|
179
|
-
if (createAction) {
|
|
180
|
-
if (subRes.includes('languages')) {
|
|
181
|
-
delete foundSubResources[subRes];
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
// For update, delete all the subresources except the ones passed in the 'language' argument.
|
|
185
|
-
else {
|
|
186
|
-
delete foundSubResources[subRes];
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
return (0, _isEmpty.default)(foundSubResources) ? null : Object.keys(foundSubResources).map(key => {
|
|
192
|
-
return {
|
|
193
|
-
name: key,
|
|
194
|
-
operation: () => service.put(`${urlPath}/${key}?fields=${key}`, {
|
|
195
|
-
[key]: foundSubResources[key]
|
|
196
|
-
}).catch(err => Promise.reject({
|
|
197
|
-
name: key,
|
|
198
|
-
requestError: err
|
|
199
|
-
}))
|
|
200
|
-
};
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Executes sub-resources requests generated by {@link generateSubResourcesRequests}
|
|
206
|
-
*
|
|
207
|
-
* @param {GenericResource} mainResourceResponse API response of the main resource update/create
|
|
208
|
-
* @param {Array<() => Promise<any>> | null} pendingCalls an array of "request creators" functions for sub-resources
|
|
209
|
-
* @returns {ApiServerClientSingleResult} returns mainResourceResponse merged with successful sub-resources results
|
|
210
|
-
* and error details if encountered
|
|
211
|
-
*/
|
|
212
|
-
async resolveSubResourcesRequests(mainResourceResponse, pendingCalls) {
|
|
213
|
-
var _result$error2, _result$error3;
|
|
214
|
-
if (!pendingCalls) {
|
|
215
|
-
return {
|
|
216
|
-
data: mainResourceResponse,
|
|
217
|
-
error: null
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
log(`resolving sub-resources, pending calls = ${pendingCalls.length}.`);
|
|
221
|
-
// note: errors set to an empty array initially, will reset to null if no errors found
|
|
222
|
-
const result = {
|
|
223
|
-
data: null,
|
|
224
|
-
updatedSubResourceNames: [],
|
|
225
|
-
error: []
|
|
226
|
-
};
|
|
227
|
-
const subResourcesCombined = (await Promise.allSettled(pendingCalls.map(async next => {
|
|
228
|
-
var _result$updatedSubRes;
|
|
229
|
-
const opResult = await next.operation();
|
|
230
|
-
(_result$updatedSubRes = result.updatedSubResourceNames) === null || _result$updatedSubRes === void 0 ? void 0 : _result$updatedSubRes.push(next.name);
|
|
231
|
-
return opResult;
|
|
232
|
-
}))).reduce((a, c) => {
|
|
233
|
-
var _c$reason$requestErro;
|
|
234
|
-
if (c.status === 'fulfilled') {
|
|
235
|
-
return {
|
|
236
|
-
...a,
|
|
237
|
-
...c.value
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
// expecting only a valid ApiServer error response here
|
|
241
|
-
// re-throw if something different, so it should be handled by command's catch block.
|
|
242
|
-
if ((_c$reason$requestErro = c.reason.requestError) !== null && _c$reason$requestErro !== void 0 && _c$reason$requestErro.errors && Array.isArray(c.reason.requestError.errors)) {
|
|
243
|
-
var _result$error;
|
|
244
|
-
// note: if APIs are going to return more details this details override will not be needed, just push as in other methods
|
|
245
|
-
(_result$error = result.error) === null || _result$error === void 0 ? void 0 : _result$error.push(...c.reason.requestError.errors.map(e => ({
|
|
246
|
-
...e,
|
|
247
|
-
detail: `sub-resource "${c.reason.name}" ${e.detail}`
|
|
248
|
-
})));
|
|
249
|
-
return a;
|
|
250
|
-
}
|
|
251
|
-
throw c.reason;
|
|
252
|
-
}, {});
|
|
253
|
-
result.data = (0, _assign.default)(mainResourceResponse, subResourcesCombined);
|
|
254
|
-
if (!((_result$error2 = result.error) !== null && _result$error2 !== void 0 && _result$error2.length)) result.error = null; // reset errors to null if none encountered
|
|
255
|
-
log(`resolving sub-resources is complete, data received = ${!(0, _isEmpty.default)(subResourcesCombined)}, errors = ${(_result$error3 = result.error) === null || _result$error3 === void 0 ? void 0 : _result$error3.length}.`);
|
|
256
|
-
return result;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Check if resources are deleted by making a fetch call for the resources
|
|
261
|
-
*/
|
|
262
|
-
checkForResources(resources, sortedDefsArray) {
|
|
263
|
-
return Promise.all(resources.map(resource => {
|
|
264
|
-
var _resource$metadata2, _resource$metadata3, _resource$metadata3$s;
|
|
265
|
-
const resourceDef = sortedDefsArray.find(def => {
|
|
266
|
-
var _def$spec$scope, _resource$metadata, _resource$metadata$sc;
|
|
267
|
-
return def.spec.kind === resource.kind && ((_def$spec$scope = def.spec.scope) === null || _def$spec$scope === void 0 ? void 0 : _def$spec$scope.kind) === ((_resource$metadata = resource.metadata) === null || _resource$metadata === void 0 ? void 0 : (_resource$metadata$sc = _resource$metadata.scope) === null || _resource$metadata$sc === void 0 ? void 0 : _resource$metadata$sc.kind);
|
|
268
|
-
});
|
|
269
|
-
const scopeDef = !!((_resource$metadata2 = resource.metadata) !== null && _resource$metadata2 !== void 0 && _resource$metadata2.scope) ? sortedDefsArray.find(def => def.spec.kind === resource.metadata.scope.kind && !def.spec.scope) : undefined;
|
|
270
|
-
const scopeName = (_resource$metadata3 = resource.metadata) === null || _resource$metadata3 === void 0 ? void 0 : (_resource$metadata3$s = _resource$metadata3.scope) === null || _resource$metadata3$s === void 0 ? void 0 : _resource$metadata3$s.name;
|
|
271
|
-
if (resourceDef) {
|
|
272
|
-
return this.getResourceByName({
|
|
273
|
-
resourceDef,
|
|
274
|
-
resourceName: resource.name,
|
|
275
|
-
scopeDef,
|
|
276
|
-
scopeName
|
|
277
|
-
});
|
|
278
|
-
} else return null;
|
|
279
|
-
}));
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* SINGLE RESOURCE CALLS
|
|
284
|
-
*/
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Create a single resource.
|
|
288
|
-
* @param resources resource to create
|
|
289
|
-
*/
|
|
290
|
-
async createResource({
|
|
291
|
-
resourceDef,
|
|
292
|
-
resource,
|
|
293
|
-
scopeDef,
|
|
294
|
-
scopeName,
|
|
295
|
-
withSubResources = true,
|
|
296
|
-
language
|
|
297
|
-
}) {
|
|
298
|
-
log(`createResource, spec.kind = ${resourceDef.spec.kind}, name = ${resource.name}`);
|
|
299
|
-
const result = {
|
|
300
|
-
data: null,
|
|
301
|
-
error: null,
|
|
302
|
-
pending: null,
|
|
303
|
-
warning: false
|
|
304
|
-
};
|
|
305
|
-
try {
|
|
306
|
-
const service = await (0, _dataService.dataService)({
|
|
307
|
-
baseUrl: this.baseUrl,
|
|
308
|
-
region: this.region,
|
|
309
|
-
account: this.account,
|
|
310
|
-
team: this.team,
|
|
311
|
-
forceGetAuthInfo: this.forceGetAuthInfo
|
|
312
|
-
});
|
|
313
|
-
const version = resource.apiVersion === undefined ? (0, _utils.getLatestServedAPIVersion)(resourceDef) : resource.apiVersion;
|
|
314
|
-
const urlPath = this.buildResourceUrlPath({
|
|
315
|
-
resourceDef,
|
|
316
|
-
scopeDef,
|
|
317
|
-
scopeName,
|
|
318
|
-
version
|
|
319
|
-
});
|
|
320
|
-
const response = await service.post(urlPath, (0, _utils.sanitizeMetadata)(resource));
|
|
321
|
-
if (!resource.name) {
|
|
322
|
-
log('createResource, resource does not have a logical name');
|
|
323
|
-
result.warning = true;
|
|
324
|
-
}
|
|
325
|
-
const pendingSubResources = await this.generateSubResourcesRequests({
|
|
326
|
-
resource,
|
|
327
|
-
resourceName: response.name,
|
|
328
|
-
resourceDef,
|
|
329
|
-
scopeDef,
|
|
330
|
-
scopeName,
|
|
331
|
-
version,
|
|
332
|
-
createAction: true,
|
|
333
|
-
language
|
|
334
|
-
});
|
|
335
|
-
log(`createResource, pendingSubResources = ${pendingSubResources === null || pendingSubResources === void 0 ? void 0 : pendingSubResources.length}`);
|
|
336
|
-
if (withSubResources) {
|
|
337
|
-
const {
|
|
338
|
-
data: subResData,
|
|
339
|
-
error: subResError
|
|
340
|
-
} = await this.resolveSubResourcesRequests(response, pendingSubResources);
|
|
341
|
-
result.data = subResData;
|
|
342
|
-
result.error = subResError;
|
|
343
|
-
} else {
|
|
344
|
-
result.data = response;
|
|
345
|
-
result.pending = pendingSubResources;
|
|
346
|
-
}
|
|
347
|
-
} catch (e) {
|
|
348
|
-
log('createResource, error: ', e);
|
|
349
|
-
// expecting only a valid ApiServer error response here
|
|
350
|
-
// re-throw if something different, so it should be handled by command's catch block.
|
|
351
|
-
if (e.errors && Array.isArray(e.errors)) {
|
|
352
|
-
result.error = e.errors;
|
|
353
|
-
} else throw e;
|
|
354
|
-
}
|
|
355
|
-
if (!!result.data) {
|
|
356
|
-
result.data = (0, _utils.sanitizeMetadata)(result.data);
|
|
357
|
-
}
|
|
358
|
-
return result;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* Update a single resource.
|
|
363
|
-
* @param resources resource to create
|
|
364
|
-
*/
|
|
365
|
-
async updateResource({
|
|
366
|
-
resourceDef,
|
|
367
|
-
resource,
|
|
368
|
-
scopeDef,
|
|
369
|
-
scopeName,
|
|
370
|
-
subResourceName,
|
|
371
|
-
language
|
|
372
|
-
}) {
|
|
373
|
-
log(`updateResource, spec.kind = ${resourceDef.spec.kind}, name = ${resource.name}`);
|
|
374
|
-
const result = {
|
|
375
|
-
data: null,
|
|
376
|
-
error: null,
|
|
377
|
-
pending: null
|
|
378
|
-
};
|
|
379
|
-
const canUpdateMainResource = !language && !subResourceName;
|
|
380
|
-
const version = resource.apiVersion === undefined ? (0, _utils.getLatestServedAPIVersion)(resourceDef) : resource.apiVersion;
|
|
381
|
-
if (canUpdateMainResource) {
|
|
382
|
-
try {
|
|
383
|
-
const service = await (0, _dataService.dataService)({
|
|
384
|
-
baseUrl: this.baseUrl,
|
|
385
|
-
region: this.region,
|
|
386
|
-
account: this.account,
|
|
387
|
-
team: this.team
|
|
388
|
-
});
|
|
389
|
-
const urlPath = this.buildResourceUrlPath({
|
|
390
|
-
resourceDef,
|
|
391
|
-
resourceName: resource.name,
|
|
392
|
-
scopeDef,
|
|
393
|
-
scopeName,
|
|
394
|
-
version
|
|
395
|
-
});
|
|
396
|
-
result.data = await service.put(urlPath, (0, _utils.sanitizeMetadata)(resource));
|
|
397
|
-
} catch (e) {
|
|
398
|
-
log('updateResource, error', e);
|
|
399
|
-
// expecting only a valid ApiServer error response here
|
|
400
|
-
// re-throw if something different, so it should be handled by command's catch block.
|
|
401
|
-
if (e.errors && Array.isArray(e.errors)) {
|
|
402
|
-
result.error = e.errors;
|
|
403
|
-
} else {
|
|
404
|
-
throw e;
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
result.pending = await this.generateSubResourcesRequests({
|
|
409
|
-
resource,
|
|
410
|
-
resourceName: resource.name,
|
|
411
|
-
subResourceName,
|
|
412
|
-
resourceDef,
|
|
413
|
-
scopeDef,
|
|
414
|
-
scopeName,
|
|
415
|
-
version,
|
|
416
|
-
createAction: false,
|
|
417
|
-
language
|
|
418
|
-
});
|
|
419
|
-
if (!result.data && !result.pending && subResourceName) {
|
|
420
|
-
result.error = [{
|
|
421
|
-
status: 0,
|
|
422
|
-
title: '',
|
|
423
|
-
detail: `sub-resource "${subResourceName}" not found.`,
|
|
424
|
-
meta: {
|
|
425
|
-
instanceId: '',
|
|
426
|
-
tenantId: '',
|
|
427
|
-
authenticatedUserId: '',
|
|
428
|
-
transactionId: ''
|
|
429
|
-
}
|
|
430
|
-
}];
|
|
431
|
-
}
|
|
432
|
-
if (result.data) {
|
|
433
|
-
result.data = (0, _utils.sanitizeMetadata)(result.data);
|
|
434
|
-
}
|
|
435
|
-
return result;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* Update sub resource on the resource.
|
|
440
|
-
* @param resources resource to be updated
|
|
441
|
-
* @param subResourceName sub resource name to be updated
|
|
442
|
-
*/
|
|
443
|
-
async updateSubResource({
|
|
444
|
-
resourceDef,
|
|
445
|
-
resource,
|
|
446
|
-
subResourceName,
|
|
447
|
-
scopeDef,
|
|
448
|
-
scopeName
|
|
449
|
-
}) {
|
|
450
|
-
log(`updateSubResource, spec.kind = ${resourceDef.spec.kind}, name = ${resource.name}`);
|
|
451
|
-
const result = {
|
|
452
|
-
data: null,
|
|
453
|
-
error: null,
|
|
454
|
-
pending: null
|
|
455
|
-
};
|
|
456
|
-
const version = (0, _utils.getLatestServedAPIVersion)(resourceDef);
|
|
457
|
-
try {
|
|
458
|
-
var _resourceDef$spec$sub3, _resourceDef$spec$sub4;
|
|
459
|
-
const service = await (0, _dataService.dataService)({
|
|
460
|
-
baseUrl: this.baseUrl,
|
|
461
|
-
region: this.region,
|
|
462
|
-
account: this.account,
|
|
463
|
-
team: this.team
|
|
464
|
-
});
|
|
465
|
-
const knownSubResourcesNames = (_resourceDef$spec$sub3 = (_resourceDef$spec$sub4 = resourceDef.spec.subResources) === null || _resourceDef$spec$sub4 === void 0 ? void 0 : _resourceDef$spec$sub4.names) !== null && _resourceDef$spec$sub3 !== void 0 ? _resourceDef$spec$sub3 : [];
|
|
466
|
-
const foundSubResources = (0, _pickBy.default)(resource, (_, key) => subResourceName == key && knownSubResourcesNames.includes(key));
|
|
467
|
-
const resourceName = resource.name;
|
|
468
|
-
const urlPath = this.buildResourceUrlPath({
|
|
469
|
-
resourceDef,
|
|
470
|
-
resourceName,
|
|
471
|
-
scopeDef,
|
|
472
|
-
scopeName,
|
|
473
|
-
version
|
|
474
|
-
});
|
|
475
|
-
service.put(`${urlPath}/${subResourceName}?fields=${subResourceName}`, {
|
|
476
|
-
[subResourceName]: foundSubResources[subResourceName]
|
|
477
|
-
});
|
|
478
|
-
} catch (e) {
|
|
479
|
-
log('updateSubResource, error', e);
|
|
480
|
-
// expecting only a valid ApiServer error response here
|
|
481
|
-
// re-throw if something different, so it should be handled by command's catch block.
|
|
482
|
-
if (e.errors && Array.isArray(e.errors)) {
|
|
483
|
-
result.error = e.errors;
|
|
484
|
-
} else throw e;
|
|
485
|
-
}
|
|
486
|
-
if (!!result.data) result.data = (0, _utils.sanitizeMetadata)(result.data);
|
|
487
|
-
return result;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
/**
|
|
491
|
-
* Delete a resources by name.
|
|
492
|
-
* @param opts = {
|
|
493
|
-
* resourceDef - required, resource definition
|
|
494
|
-
* resourceName - required
|
|
495
|
-
* scopeDef - optional scope resource definition, used only if @param opts.scopeName provided too
|
|
496
|
-
* scopeName - optional name of the scope, used only if scoped @param opts.scopeDef provided too
|
|
497
|
-
* version - apis version (using alpha1 by default currently)
|
|
498
|
-
* wait - if provided, a followup GET call will be executed to confirm if the resource removed.
|
|
499
|
-
* }
|
|
500
|
-
*/
|
|
501
|
-
async deleteResourceByName({
|
|
502
|
-
resourceDef,
|
|
503
|
-
resourceName,
|
|
504
|
-
scopeDef,
|
|
505
|
-
scopeName,
|
|
506
|
-
wait,
|
|
507
|
-
forceDelete = false,
|
|
508
|
-
resourceAPIVersion
|
|
509
|
-
}) {
|
|
510
|
-
log(`deleteResourceByName, spec.kind = ${resourceDef.spec.kind}, name = ${resourceName}, scope.kind = ${scopeDef === null || scopeDef === void 0 ? void 0 : scopeDef.spec.kind}, scope.name = ${scopeName}`);
|
|
511
|
-
const result = {
|
|
512
|
-
data: null,
|
|
513
|
-
error: null
|
|
514
|
-
};
|
|
515
|
-
const version = resourceAPIVersion === undefined ? (0, _utils.getLatestServedAPIVersion)(resourceDef) : resourceAPIVersion;
|
|
516
|
-
try {
|
|
517
|
-
const service = await (0, _dataService.dataService)({
|
|
518
|
-
baseUrl: this.baseUrl,
|
|
519
|
-
region: this.region,
|
|
520
|
-
account: this.account,
|
|
521
|
-
team: this.team,
|
|
522
|
-
forceGetAuthInfo: this.forceGetAuthInfo
|
|
523
|
-
});
|
|
524
|
-
const urlPath = this.buildResourceUrlPath({
|
|
525
|
-
resourceDef,
|
|
526
|
-
resourceName,
|
|
527
|
-
scopeDef,
|
|
528
|
-
scopeName,
|
|
529
|
-
version,
|
|
530
|
-
forceDelete
|
|
531
|
-
});
|
|
532
|
-
const response = await service.delete(urlPath);
|
|
533
|
-
// note: delete "response" value from api-server is translated to an empty string currently.
|
|
534
|
-
// If its true, constructing a simple representation from provided data (definition, name, scope name)
|
|
535
|
-
// and manually set it as the "data" key.
|
|
536
|
-
result.data = response === '' ? (0, _utils.buildGenericResource)({
|
|
537
|
-
resourceDef,
|
|
538
|
-
resourceName,
|
|
539
|
-
scopeName
|
|
540
|
-
}) : response;
|
|
541
|
-
if (wait) {
|
|
542
|
-
await new Promise(resolve => setTimeout(async () => {
|
|
543
|
-
const res = await this.getResourceByName({
|
|
544
|
-
resourceDef,
|
|
545
|
-
resourceName,
|
|
546
|
-
scopeDef,
|
|
547
|
-
scopeName
|
|
548
|
-
});
|
|
549
|
-
if (!!res.data) {
|
|
550
|
-
result.data = null;
|
|
551
|
-
result.error = [{
|
|
552
|
-
detail: 'resource has not been deleted yet.',
|
|
553
|
-
status: 0
|
|
554
|
-
}];
|
|
555
|
-
}
|
|
556
|
-
resolve({});
|
|
557
|
-
}, _types.WAIT_TIMEOUT));
|
|
558
|
-
}
|
|
559
|
-
} catch (e) {
|
|
560
|
-
log('deleteResourceByName, error: ', e);
|
|
561
|
-
// expecting only a valid ApiServer error response here
|
|
562
|
-
// re-throw if something different so it should be handled by command's catch block.
|
|
563
|
-
if (e.errors && Array.isArray(e.errors)) {
|
|
564
|
-
result.error = e.errors;
|
|
565
|
-
} else throw e;
|
|
566
|
-
}
|
|
567
|
-
return result;
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
/**
|
|
571
|
-
* Get resources count.
|
|
572
|
-
* @param opts = {
|
|
573
|
-
* resourceDef - required, resource definition
|
|
574
|
-
* resourceName - optional, resource name
|
|
575
|
-
* scopeDef - optional scope resource definition, used only if @param opts.scopeName provided too
|
|
576
|
-
* scopeName - optional name of the scope, used only if scoped @param opts.scopeDef provided too
|
|
577
|
-
* query - Optional RSQL query filter
|
|
578
|
-
* }
|
|
579
|
-
*/
|
|
580
|
-
async getResourceCount({
|
|
581
|
-
resourceDef,
|
|
582
|
-
resourceName,
|
|
583
|
-
scopeDef,
|
|
584
|
-
scopeName,
|
|
585
|
-
query
|
|
586
|
-
}) {
|
|
587
|
-
const version = (0, _utils.getLatestServedAPIVersion)(resourceDef);
|
|
588
|
-
try {
|
|
589
|
-
const service = await (0, _dataService.dataService)({
|
|
590
|
-
baseUrl: this.baseUrl,
|
|
591
|
-
region: this.region,
|
|
592
|
-
account: this.account,
|
|
593
|
-
team: this.team,
|
|
594
|
-
forceGetAuthInfo: this.forceGetAuthInfo
|
|
595
|
-
});
|
|
596
|
-
const urlPath = this.buildResourceUrlPath({
|
|
597
|
-
resourceDef,
|
|
598
|
-
resourceName,
|
|
599
|
-
scopeDef,
|
|
600
|
-
scopeName,
|
|
601
|
-
version
|
|
602
|
-
});
|
|
603
|
-
const response = await service.head(urlPath, query);
|
|
604
|
-
return response;
|
|
605
|
-
} catch (e) {
|
|
606
|
-
log('getResourceCount, error: ', e);
|
|
607
|
-
// re-throw
|
|
608
|
-
throw e;
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
/**
|
|
613
|
-
* Get a resources list.
|
|
614
|
-
* @param opts = {
|
|
615
|
-
* resourceDef - required, resource definition
|
|
616
|
-
* scopeDef - optional scope resource definition, used only if @param opts.scopeName provided too
|
|
617
|
-
* scopeName - optional name of the scope, used only if scoped @param opts.scopeDef provided too
|
|
618
|
-
* version - apis version (using alpha1 by default currently)
|
|
619
|
-
* query - Optional RSQL query filter
|
|
620
|
-
* progressListener - Optional callback invoked multiple times with download progress
|
|
621
|
-
* }
|
|
622
|
-
*/
|
|
623
|
-
async getResourcesList({
|
|
624
|
-
resourceDef,
|
|
625
|
-
scopeDef,
|
|
626
|
-
scopeName,
|
|
627
|
-
query,
|
|
628
|
-
progressListener,
|
|
629
|
-
expand,
|
|
630
|
-
langDef,
|
|
631
|
-
fieldSet
|
|
632
|
-
}) {
|
|
633
|
-
log(`getResourcesList, spec.kind = ${resourceDef.spec.kind}`);
|
|
634
|
-
const version = (0, _utils.getLatestServedAPIVersion)(resourceDef);
|
|
635
|
-
const result = {
|
|
636
|
-
data: null,
|
|
637
|
-
error: null
|
|
638
|
-
};
|
|
639
|
-
try {
|
|
640
|
-
const service = await (0, _dataService.dataService)({
|
|
641
|
-
baseUrl: this.baseUrl,
|
|
642
|
-
region: this.region,
|
|
643
|
-
account: this.account,
|
|
644
|
-
team: this.team,
|
|
645
|
-
forceGetAuthInfo: this.forceGetAuthInfo
|
|
646
|
-
});
|
|
647
|
-
const urlPath = this.buildResourceUrlPath({
|
|
648
|
-
resourceDef,
|
|
649
|
-
scopeDef,
|
|
650
|
-
scopeName,
|
|
651
|
-
version,
|
|
652
|
-
expand,
|
|
653
|
-
langDef,
|
|
654
|
-
fieldSet
|
|
655
|
-
});
|
|
656
|
-
const response = await service.getWithPagination(urlPath, query, 50, {}, progressListener);
|
|
657
|
-
result.data = response;
|
|
658
|
-
} catch (e) {
|
|
659
|
-
log('getResourcesList, error: ', e);
|
|
660
|
-
// expecting only a valid ApiServer error response here
|
|
661
|
-
// re-throw if something different so it should be handled by command's catch block.
|
|
662
|
-
if (e.errors && Array.isArray(e.errors)) {
|
|
663
|
-
result.error = e.errors;
|
|
664
|
-
} else throw e;
|
|
665
|
-
}
|
|
666
|
-
return result;
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
/**
|
|
670
|
-
* Get a resources by name.
|
|
671
|
-
* @param opts = {
|
|
672
|
-
* resourceDef - required, resource definition
|
|
673
|
-
* resourceName - required
|
|
674
|
-
* scopeDef - optional scope resource definition, used only if @param opts.scopeName provided too
|
|
675
|
-
* scopeName - optional name of the scope, used only if scoped @param opts.scopeDef provided too
|
|
676
|
-
* version - apis version (using alpha1 by default currently)
|
|
677
|
-
* }
|
|
678
|
-
*/
|
|
679
|
-
async getResourceByName({
|
|
680
|
-
resourceDef,
|
|
681
|
-
resourceName,
|
|
682
|
-
scopeDef,
|
|
683
|
-
scopeName,
|
|
684
|
-
expand,
|
|
685
|
-
langDef,
|
|
686
|
-
fieldSet,
|
|
687
|
-
resourceVersion,
|
|
688
|
-
embed
|
|
689
|
-
}) {
|
|
690
|
-
log(`getResourceByName, spec.kind = ${resourceDef.spec.kind}, name = ${resourceName}`);
|
|
691
|
-
const version = resourceVersion === undefined ? (0, _utils.getLatestServedAPIVersion)(resourceDef) : resourceVersion;
|
|
692
|
-
const result = {
|
|
693
|
-
data: null,
|
|
694
|
-
error: null
|
|
695
|
-
};
|
|
696
|
-
try {
|
|
697
|
-
const service = await (0, _dataService.dataService)({
|
|
698
|
-
baseUrl: this.baseUrl,
|
|
699
|
-
region: this.region,
|
|
700
|
-
account: this.account,
|
|
701
|
-
team: this.team,
|
|
702
|
-
forceGetAuthInfo: this.forceGetAuthInfo
|
|
703
|
-
});
|
|
704
|
-
const urlPath = this.buildResourceUrlPath({
|
|
705
|
-
resourceDef,
|
|
706
|
-
resourceName,
|
|
707
|
-
scopeDef,
|
|
708
|
-
scopeName,
|
|
709
|
-
version,
|
|
710
|
-
expand,
|
|
711
|
-
langDef,
|
|
712
|
-
fieldSet,
|
|
713
|
-
embed: embed
|
|
714
|
-
});
|
|
715
|
-
const response = await service.get(urlPath);
|
|
716
|
-
result.data = response;
|
|
717
|
-
} catch (e) {
|
|
718
|
-
log('getResourceByName, error: ', e);
|
|
719
|
-
// expecting only a valid ApiServer error response here
|
|
720
|
-
// re-throw if something different so it should be handled by command's catch block.
|
|
721
|
-
if (e.errors && Array.isArray(e.errors)) {
|
|
722
|
-
result.error = e.errors;
|
|
723
|
-
} else throw e;
|
|
724
|
-
}
|
|
725
|
-
return result;
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
/**
|
|
729
|
-
* Fetch definition endpoints to get specs for available resources.
|
|
730
|
-
* Note that only "management" group is used currently.
|
|
731
|
-
* @returns { group1: { resources: Map, cli: Map }, group2: { ... }, groupN: { ... } }
|
|
732
|
-
*/
|
|
733
|
-
async getSpecs(version = ApiServerVersions.v1alpha1) {
|
|
734
|
-
log(`get specs`);
|
|
735
|
-
try {
|
|
736
|
-
const specs = {};
|
|
737
|
-
const service = await (0, _dataService.dataService)({
|
|
738
|
-
baseUrl: this.baseUrl,
|
|
739
|
-
region: this.region,
|
|
740
|
-
account: this.account
|
|
741
|
-
});
|
|
742
|
-
const groups = await service.getWithPagination(`/definitions/${version}/groups`);
|
|
743
|
-
for (const group of groups) {
|
|
744
|
-
let resources = [];
|
|
745
|
-
let cli = [];
|
|
746
|
-
const cachedGroup = _CacheController.CacheController.get(`groups-${group.name}-${version}`);
|
|
747
|
-
let cacheUpdated = false;
|
|
748
|
-
if (this.useCache && cachedGroup && cachedGroup.resourceVersion === group.metadata.resourceVersion) {
|
|
749
|
-
log(`valid ${group.name}/${version} found in cache`);
|
|
750
|
-
resources = cachedGroup.resources;
|
|
751
|
-
cli = cachedGroup.cli;
|
|
752
|
-
} else {
|
|
753
|
-
log(`no valid ${group.name}/${version} found in cache or cache usage is not set`);
|
|
754
|
-
[resources, cli] = await Promise.all([service.getWithPagination(`/definitions/${version}/groups/${group.name}/resources`), service.getWithPagination(`/definitions/${version}/groups/${group.name}/commandlines`)]);
|
|
755
|
-
_CacheController.CacheController.set(`groups-${group.name}-${version}`, {
|
|
756
|
-
resourceVersion: group.metadata.resourceVersion,
|
|
757
|
-
resources,
|
|
758
|
-
cli
|
|
759
|
-
});
|
|
760
|
-
cacheUpdated = true;
|
|
761
|
-
}
|
|
762
|
-
specs[group.name] = {
|
|
763
|
-
resources: new Map(),
|
|
764
|
-
cli: new Map()
|
|
765
|
-
};
|
|
766
|
-
for (const r of resources) {
|
|
767
|
-
specs[group.name].resources.set(r.name, r);
|
|
768
|
-
}
|
|
769
|
-
for (const c of cli) {
|
|
770
|
-
specs[group.name].cli.set(c.name, c);
|
|
771
|
-
}
|
|
772
|
-
if (cacheUpdated) _CacheController.CacheController.writeToFile();
|
|
773
|
-
}
|
|
774
|
-
return specs;
|
|
775
|
-
} catch (e) {
|
|
776
|
-
log('get specs, error: ', e);
|
|
777
|
-
throw e;
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
/**
|
|
782
|
-
* BULK CALLS
|
|
783
|
-
*/
|
|
784
|
-
|
|
785
|
-
/**
|
|
786
|
-
* Bulk creation of resources.
|
|
787
|
-
* There is no endpoint for bulk create so executing them one-by-one. Order of calls calculated by
|
|
788
|
-
* sorting of the array of resources with "compareResourcesByKindAsc".
|
|
789
|
-
* @param resources array of resources to create
|
|
790
|
-
*/
|
|
791
|
-
async bulkCreate(resources, sortedDefsMap, exitOnError = false) {
|
|
792
|
-
log(`bulk create`);
|
|
793
|
-
const sortedDefsArray = Array.from(sortedDefsMap.values());
|
|
794
|
-
const pendingSubResources = [];
|
|
795
|
-
const bulkResult = {
|
|
796
|
-
success: [],
|
|
797
|
-
error: [],
|
|
798
|
-
warning: []
|
|
799
|
-
};
|
|
800
|
-
for (const resource of resources) {
|
|
801
|
-
var _resource$metadata7, _resource$metadata8, _resource$metadata8$s;
|
|
802
|
-
const resourceDef = sortedDefsArray.find(def => {
|
|
803
|
-
var _def$spec$scope2, _resource$metadata4, _resource$metadata4$s;
|
|
804
|
-
return def.spec.kind === resource.kind && ((_def$spec$scope2 = def.spec.scope) === null || _def$spec$scope2 === void 0 ? void 0 : _def$spec$scope2.kind) === ((_resource$metadata4 = resource.metadata) === null || _resource$metadata4 === void 0 ? void 0 : (_resource$metadata4$s = _resource$metadata4.scope) === null || _resource$metadata4$s === void 0 ? void 0 : _resource$metadata4$s.kind);
|
|
805
|
-
});
|
|
806
|
-
if (!resourceDef) {
|
|
807
|
-
var _resource$metadata5, _resource$metadata5$s;
|
|
808
|
-
let errorMessage = `No resource definition found for "kind/${resource.kind}"`;
|
|
809
|
-
if (!!((_resource$metadata5 = resource.metadata) !== null && _resource$metadata5 !== void 0 && (_resource$metadata5$s = _resource$metadata5.scope) !== null && _resource$metadata5$s !== void 0 && _resource$metadata5$s.kind)) {
|
|
810
|
-
var _resource$metadata6, _resource$metadata6$s;
|
|
811
|
-
errorMessage += ` in the scope "${(_resource$metadata6 = resource.metadata) === null || _resource$metadata6 === void 0 ? void 0 : (_resource$metadata6$s = _resource$metadata6.scope) === null || _resource$metadata6$s === void 0 ? void 0 : _resource$metadata6$s.kind}".`;
|
|
812
|
-
} else {
|
|
813
|
-
errorMessage += ' with no scope.';
|
|
814
|
-
}
|
|
815
|
-
bulkResult.error.push({
|
|
816
|
-
name: resource.name || 'Unknown name',
|
|
817
|
-
kind: resource.kind,
|
|
818
|
-
error: new Error(errorMessage)
|
|
819
|
-
});
|
|
820
|
-
continue;
|
|
821
|
-
}
|
|
822
|
-
const scopeDef = !!((_resource$metadata7 = resource.metadata) !== null && _resource$metadata7 !== void 0 && _resource$metadata7.scope) ? sortedDefsArray.find(def => def.spec.kind === resource.metadata.scope.kind && !def.spec.scope) : undefined;
|
|
823
|
-
const scopeName = (_resource$metadata8 = resource.metadata) === null || _resource$metadata8 === void 0 ? void 0 : (_resource$metadata8$s = _resource$metadata8.scope) === null || _resource$metadata8$s === void 0 ? void 0 : _resource$metadata8$s.name;
|
|
824
|
-
const res = await this.createResource({
|
|
825
|
-
resource,
|
|
826
|
-
resourceDef,
|
|
827
|
-
scopeDef,
|
|
828
|
-
scopeName
|
|
829
|
-
});
|
|
830
|
-
if (res.data && !res.error) {
|
|
831
|
-
// note: bulk operation requires creation of sub-resources after all main resources created
|
|
832
|
-
// since a sub-resource might have a reference to another resource.
|
|
833
|
-
if (!!res.pending) {
|
|
834
|
-
var _res$warning;
|
|
835
|
-
pendingSubResources.push({
|
|
836
|
-
mainResult: res.data,
|
|
837
|
-
pendingCalls: res.pending,
|
|
838
|
-
withWarning: (_res$warning = res.warning) !== null && _res$warning !== void 0 ? _res$warning : false
|
|
839
|
-
});
|
|
840
|
-
} else {
|
|
841
|
-
var _bulkResult$warning;
|
|
842
|
-
if (res.warning) (_bulkResult$warning = bulkResult.warning) === null || _bulkResult$warning === void 0 ? void 0 : _bulkResult$warning.push(res.data);else bulkResult.success.push(res.data);
|
|
843
|
-
}
|
|
844
|
-
} else if (res.error) {
|
|
845
|
-
for (const nextError of res.error) {
|
|
846
|
-
bulkResult.error.push({
|
|
847
|
-
name: resource.name || 'Unknown name',
|
|
848
|
-
kind: resource.kind,
|
|
849
|
-
error: nextError
|
|
850
|
-
});
|
|
851
|
-
}
|
|
852
|
-
if (exitOnError) {
|
|
853
|
-
return bulkResult;
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
// creating sub-resources
|
|
859
|
-
for (const p of pendingSubResources) {
|
|
860
|
-
const subResResult = await this.resolveSubResourcesRequests(p.mainResult, p.pendingCalls);
|
|
861
|
-
if (subResResult.data && !subResResult.error) {
|
|
862
|
-
var _bulkResult$warning2;
|
|
863
|
-
if (p.withWarning) (_bulkResult$warning2 = bulkResult.warning) === null || _bulkResult$warning2 === void 0 ? void 0 : _bulkResult$warning2.push(subResResult.data);else bulkResult.success.push(subResResult.data);
|
|
864
|
-
} else if (subResResult.error) {
|
|
865
|
-
for (const nextError of subResResult.error) {
|
|
866
|
-
bulkResult.error.push({
|
|
867
|
-
name: p.mainResult.name,
|
|
868
|
-
kind: p.mainResult.kind,
|
|
869
|
-
error: nextError
|
|
870
|
-
});
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
return bulkResult;
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
/**
|
|
878
|
-
* Bulk creation of resources.
|
|
879
|
-
* There is no endpoint for bulk create so executing them one-by-one. Order of calls calculated by
|
|
880
|
-
* sorting of the array of resources with "compareResourcesByKindAsc".
|
|
881
|
-
* @param resources array of resources to create
|
|
882
|
-
*/
|
|
883
|
-
async bulkCreateOrUpdate(resources, sortedDefsMap, language, subResourceName) {
|
|
884
|
-
log(`bulk create or update`);
|
|
885
|
-
const sortedDefsArray = Array.from(sortedDefsMap.values());
|
|
886
|
-
const applyResults = [];
|
|
887
|
-
for (const resource of resources) {
|
|
888
|
-
var _resource$metadata12, _resource$metadata13, _resource$metadata13$, _resource$name2, _singleResult$error, _applyResult$error3;
|
|
889
|
-
const resourceDef = sortedDefsArray.find(def => {
|
|
890
|
-
var _def$spec$scope3, _resource$metadata9, _resource$metadata9$s;
|
|
891
|
-
return def.spec.kind === resource.kind && ((_def$spec$scope3 = def.spec.scope) === null || _def$spec$scope3 === void 0 ? void 0 : _def$spec$scope3.kind) === ((_resource$metadata9 = resource.metadata) === null || _resource$metadata9 === void 0 ? void 0 : (_resource$metadata9$s = _resource$metadata9.scope) === null || _resource$metadata9$s === void 0 ? void 0 : _resource$metadata9$s.kind);
|
|
892
|
-
});
|
|
893
|
-
// the check below is already happening when loading the specs but checking again just in case.
|
|
894
|
-
if (!resourceDef) {
|
|
895
|
-
var _resource$metadata10, _resource$metadata10$, _resource$name;
|
|
896
|
-
let errorMessage = `No resource definition found for "kind/${resource.kind}"`;
|
|
897
|
-
if (!!((_resource$metadata10 = resource.metadata) !== null && _resource$metadata10 !== void 0 && (_resource$metadata10$ = _resource$metadata10.scope) !== null && _resource$metadata10$ !== void 0 && _resource$metadata10$.kind)) {
|
|
898
|
-
var _resource$metadata11, _resource$metadata11$;
|
|
899
|
-
errorMessage += ` in the scope "${(_resource$metadata11 = resource.metadata) === null || _resource$metadata11 === void 0 ? void 0 : (_resource$metadata11$ = _resource$metadata11.scope) === null || _resource$metadata11$ === void 0 ? void 0 : _resource$metadata11$.kind}".`;
|
|
900
|
-
} else {
|
|
901
|
-
errorMessage += ' with no scope.';
|
|
902
|
-
}
|
|
903
|
-
applyResults.push({
|
|
904
|
-
error: [{
|
|
905
|
-
name: (_resource$name = resource.name) !== null && _resource$name !== void 0 ? _resource$name : 'Unknown name',
|
|
906
|
-
kind: resource.kind,
|
|
907
|
-
error: new Error(errorMessage)
|
|
908
|
-
}]
|
|
909
|
-
});
|
|
910
|
-
continue;
|
|
911
|
-
}
|
|
912
|
-
const scopeDef = !!((_resource$metadata12 = resource.metadata) !== null && _resource$metadata12 !== void 0 && _resource$metadata12.scope) ? sortedDefsArray.find(def => def.spec.kind === resource.metadata.scope.kind && !def.spec.scope) : undefined;
|
|
913
|
-
const scopeName = (_resource$metadata13 = resource.metadata) === null || _resource$metadata13 === void 0 ? void 0 : (_resource$metadata13$ = _resource$metadata13.scope) === null || _resource$metadata13$ === void 0 ? void 0 : _resource$metadata13$.name;
|
|
914
|
-
const resourceName = (_resource$name2 = resource.name) !== null && _resource$name2 !== void 0 ? _resource$name2 : 'Unknown name';
|
|
915
|
-
|
|
916
|
-
// only making getResource call if resource has a name
|
|
917
|
-
let getResult = resource.name ? await this.getResourceByName({
|
|
918
|
-
resourceDef,
|
|
919
|
-
resourceName: resource.name,
|
|
920
|
-
scopeDef,
|
|
921
|
-
scopeName,
|
|
922
|
-
resourceVersion: resource.apiVersion
|
|
923
|
-
}) : null;
|
|
924
|
-
|
|
925
|
-
// Create new resources first
|
|
926
|
-
let singleResult;
|
|
927
|
-
const shouldCreate = !getResult || !!(getResult !== null && getResult !== void 0 && getResult.error) && getResult.error[0].status === 404;
|
|
928
|
-
if (shouldCreate) {
|
|
929
|
-
// Resource not found. Create a new resource.
|
|
930
|
-
singleResult = await this.createResource({
|
|
931
|
-
resource,
|
|
932
|
-
resourceDef,
|
|
933
|
-
scopeDef,
|
|
934
|
-
scopeName,
|
|
935
|
-
language
|
|
936
|
-
});
|
|
937
|
-
} else if (getResult.data) {
|
|
938
|
-
// Resource found. Update the existing resource.
|
|
939
|
-
singleResult = await this.updateResource({
|
|
940
|
-
resource: resource,
|
|
941
|
-
resourceDef,
|
|
942
|
-
scopeDef,
|
|
943
|
-
scopeName,
|
|
944
|
-
language,
|
|
945
|
-
subResourceName
|
|
946
|
-
});
|
|
947
|
-
} else {
|
|
948
|
-
// Something is going wrong - more than one error in api server response, re-throw in the same
|
|
949
|
-
// structure as ApiServerErrorResponse so renderer.anyError can pick this up.
|
|
950
|
-
throw {
|
|
951
|
-
errors: getResult.error
|
|
952
|
-
};
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
// Store the results of the above create/update.
|
|
956
|
-
const applyResult = {
|
|
957
|
-
data: singleResult.data,
|
|
958
|
-
wasCreated: shouldCreate && !!singleResult.data,
|
|
959
|
-
wasAutoNamed: shouldCreate && singleResult.warning,
|
|
960
|
-
wasMainResourceChanged: !!singleResult.data,
|
|
961
|
-
error: []
|
|
962
|
-
};
|
|
963
|
-
(_singleResult$error = singleResult.error) === null || _singleResult$error === void 0 ? void 0 : _singleResult$error.forEach(nextError => {
|
|
964
|
-
var _applyResult$error;
|
|
965
|
-
return (_applyResult$error = applyResult.error) === null || _applyResult$error === void 0 ? void 0 : _applyResult$error.push({
|
|
966
|
-
name: resourceName,
|
|
967
|
-
kind: resource.kind,
|
|
968
|
-
error: nextError
|
|
969
|
-
});
|
|
970
|
-
});
|
|
971
|
-
applyResults.push(applyResult);
|
|
972
|
-
|
|
973
|
-
// Create or update any pending subresources.
|
|
974
|
-
if (singleResult.pending) {
|
|
975
|
-
var _singleResult$data, _subResResult$error;
|
|
976
|
-
const pendingData = (_singleResult$data = singleResult.data) !== null && _singleResult$data !== void 0 ? _singleResult$data : (0, _utils.sanitizeMetadata)((0, _utils.buildGenericResource)({
|
|
977
|
-
resourceName: resourceName,
|
|
978
|
-
resourceDef: resourceDef,
|
|
979
|
-
scopeName: scopeName
|
|
980
|
-
}));
|
|
981
|
-
const subResResult = await this.resolveSubResourcesRequests(pendingData, singleResult.pending);
|
|
982
|
-
if (subResResult.data) {
|
|
983
|
-
applyResult.data = subResResult.data;
|
|
984
|
-
}
|
|
985
|
-
applyResult.updatedSubResourceNames = subResResult.updatedSubResourceNames;
|
|
986
|
-
(_subResResult$error = subResResult.error) === null || _subResResult$error === void 0 ? void 0 : _subResResult$error.forEach(error => {
|
|
987
|
-
var _applyResult$error2;
|
|
988
|
-
return (_applyResult$error2 = applyResult.error) === null || _applyResult$error2 === void 0 ? void 0 : _applyResult$error2.push({
|
|
989
|
-
name: resourceName,
|
|
990
|
-
kind: resource.kind,
|
|
991
|
-
error: error
|
|
992
|
-
});
|
|
993
|
-
});
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
// Delete the result's error array if it is empty.
|
|
997
|
-
if (!((_applyResult$error3 = applyResult.error) !== null && _applyResult$error3 !== void 0 && _applyResult$error3.length)) {
|
|
998
|
-
delete applyResult.error;
|
|
999
|
-
}
|
|
1000
|
-
}
|
|
1001
|
-
return applyResults;
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
/**
|
|
1005
|
-
* Bulk deletion of resources.
|
|
1006
|
-
* Order of calls calculated by sorting of the array of resources with "compareResourcesByKindDesc".
|
|
1007
|
-
* @param resources array of resources to create
|
|
1008
|
-
*/
|
|
1009
|
-
async bulkDelete(resources, sortedDefsMap, wait, forceDelete) {
|
|
1010
|
-
log(`bulk delete`);
|
|
1011
|
-
const sortedDefsArray = Array.from(sortedDefsMap.values());
|
|
1012
|
-
const bulkResult = {
|
|
1013
|
-
success: [],
|
|
1014
|
-
error: []
|
|
1015
|
-
};
|
|
1016
|
-
for (const resource of resources) {
|
|
1017
|
-
try {
|
|
1018
|
-
var _resource$metadata15, _resource$metadata16, _resource$metadata16$;
|
|
1019
|
-
const resourceDef = sortedDefsArray.find(def => {
|
|
1020
|
-
var _def$spec$scope4, _resource$metadata14, _resource$metadata14$;
|
|
1021
|
-
return def.spec.kind === resource.kind && ((_def$spec$scope4 = def.spec.scope) === null || _def$spec$scope4 === void 0 ? void 0 : _def$spec$scope4.kind) === ((_resource$metadata14 = resource.metadata) === null || _resource$metadata14 === void 0 ? void 0 : (_resource$metadata14$ = _resource$metadata14.scope) === null || _resource$metadata14$ === void 0 ? void 0 : _resource$metadata14$.kind);
|
|
1022
|
-
});
|
|
1023
|
-
const scopeDef = !!((_resource$metadata15 = resource.metadata) !== null && _resource$metadata15 !== void 0 && _resource$metadata15.scope) ? sortedDefsArray.find(def => def.spec.kind === resource.metadata.scope.kind && !def.spec.scope) : undefined;
|
|
1024
|
-
const scopeName = (_resource$metadata16 = resource.metadata) === null || _resource$metadata16 === void 0 ? void 0 : (_resource$metadata16$ = _resource$metadata16.scope) === null || _resource$metadata16$ === void 0 ? void 0 : _resource$metadata16$.name;
|
|
1025
|
-
if (!resourceDef) {
|
|
1026
|
-
var _resource$metadata17, _resource$metadata17$;
|
|
1027
|
-
let errorMessage = `No resource definition found for "kind/${resource.kind}"`;
|
|
1028
|
-
if (!!((_resource$metadata17 = resource.metadata) !== null && _resource$metadata17 !== void 0 && (_resource$metadata17$ = _resource$metadata17.scope) !== null && _resource$metadata17$ !== void 0 && _resource$metadata17$.kind)) {
|
|
1029
|
-
var _resource$metadata18, _resource$metadata18$;
|
|
1030
|
-
errorMessage += ` in the scope "${(_resource$metadata18 = resource.metadata) === null || _resource$metadata18 === void 0 ? void 0 : (_resource$metadata18$ = _resource$metadata18.scope) === null || _resource$metadata18$ === void 0 ? void 0 : _resource$metadata18$.kind}".`;
|
|
1031
|
-
} else {
|
|
1032
|
-
errorMessage += ' with no scope.';
|
|
1033
|
-
}
|
|
1034
|
-
bulkResult.error.push({
|
|
1035
|
-
name: resource.name || 'Unknown name',
|
|
1036
|
-
kind: resource.kind,
|
|
1037
|
-
error: new Error(errorMessage)
|
|
1038
|
-
});
|
|
1039
|
-
continue;
|
|
1040
|
-
}
|
|
1041
|
-
const res = await this.deleteResourceByName({
|
|
1042
|
-
resourceName: resource.name,
|
|
1043
|
-
resourceDef,
|
|
1044
|
-
scopeDef,
|
|
1045
|
-
scopeName,
|
|
1046
|
-
forceDelete,
|
|
1047
|
-
resourceAPIVersion: resource.apiVersion
|
|
1048
|
-
});
|
|
1049
|
-
if (res.error) {
|
|
1050
|
-
for (const nextError of res.error) {
|
|
1051
|
-
bulkResult.error.push({
|
|
1052
|
-
name: resource.name,
|
|
1053
|
-
kind: resource.kind,
|
|
1054
|
-
error: nextError
|
|
1055
|
-
});
|
|
1056
|
-
}
|
|
1057
|
-
} else {
|
|
1058
|
-
// deleteResourceByName is constructing a resource representation using buildGenericResource as res.data,
|
|
1059
|
-
// but provided in a file resources might contain more data so using them currently
|
|
1060
|
-
bulkResult.success.push(resource);
|
|
1061
|
-
}
|
|
1062
|
-
} catch (e) {
|
|
1063
|
-
// expecting only a valid ApiServer error response here
|
|
1064
|
-
// re-throw if something different so it should be handled by command's catch block.
|
|
1065
|
-
if (e.errors && Array.isArray(e.errors)) {
|
|
1066
|
-
for (const nextError of e.errors) {
|
|
1067
|
-
bulkResult.error.push({
|
|
1068
|
-
name: resource.name,
|
|
1069
|
-
kind: resource.kind,
|
|
1070
|
-
error: nextError
|
|
1071
|
-
});
|
|
1072
|
-
}
|
|
1073
|
-
} else {
|
|
1074
|
-
throw e;
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
}
|
|
1078
|
-
if (wait) {
|
|
1079
|
-
let pendingResources = [];
|
|
1080
|
-
pendingResources = await this.checkForResources(resources, sortedDefsArray);
|
|
1081
|
-
const pendingDeletingResource = pendingResources.some(res => res === null || res === void 0 ? void 0 : res.data);
|
|
1082
|
-
if (pendingDeletingResource) {
|
|
1083
|
-
setTimeout(async () => {
|
|
1084
|
-
pendingResources = await this.checkForResources(resources, sortedDefsArray);
|
|
1085
|
-
}, _types.WAIT_TIMEOUT);
|
|
1086
|
-
const stillPending = pendingResources.some(res => res === null || res === void 0 ? void 0 : res.data);
|
|
1087
|
-
if (stillPending) {
|
|
1088
|
-
const pendingResNames = pendingResources.map(res => {
|
|
1089
|
-
var _res$data;
|
|
1090
|
-
return res === null || res === void 0 ? void 0 : (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.name;
|
|
1091
|
-
});
|
|
1092
|
-
bulkResult.success.forEach((res, index) => pendingResNames.includes(res.name) && bulkResult.success.splice(index, 1));
|
|
1093
|
-
pendingResources.forEach(res => {
|
|
1094
|
-
if (res !== null && res !== void 0 && res.data) {
|
|
1095
|
-
bulkResult.error.push({
|
|
1096
|
-
...res.data,
|
|
1097
|
-
error: {
|
|
1098
|
-
detail: 'Not deleted yet.'
|
|
1099
|
-
}
|
|
1100
|
-
});
|
|
1101
|
-
}
|
|
1102
|
-
});
|
|
1103
|
-
} else return bulkResult;
|
|
1104
|
-
} else return bulkResult;
|
|
1105
|
-
}
|
|
1106
|
-
return bulkResult;
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
exports.ApiServerClient = ApiServerClient;
|