@axway/axway-central-cli 2.8.0-rc.3 → 2.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/config/set.js +2 -2
- package/dist/commands/edit/environment.js +6 -2
- package/dist/commands/get/index.js +21 -6
- package/dist/commands/install/agents.js +21 -1
- package/dist/commands/install/helpers/getters.js +8 -8
- package/dist/commands/install/istioAgents.js +4 -4
- package/dist/commands/install/platform.js +2 -2
- package/dist/common/ApiServerClient.js +157 -58
- package/dist/common/CompositeError.js +124 -0
- package/dist/common/CoreConfigController.js +30 -5
- package/dist/common/Renderer.js +112 -19
- package/dist/common/dataService.js +35 -17
- package/dist/common/resultsRenderers.js +68 -5
- package/dist/common/types.js +8 -8
- package/dist/common/utils.js +36 -50
- package/package.json +2 -1
|
@@ -71,7 +71,7 @@ const action = async ({
|
|
|
71
71
|
const parsedValue = String(argv.platform).toLowerCase();
|
|
72
72
|
|
|
73
73
|
if (!(parsedValue in _types.Platforms)) {
|
|
74
|
-
throw Error('"--platform" value is not correct, please provide one of: prod,
|
|
74
|
+
throw Error('"--platform" value is not correct, please provide one of: prod, staging. For example: "axway central config set --platform=staging"');
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
log(`Writing ${_types.ConfigTypes.PLATFORM}`);
|
|
@@ -82,7 +82,7 @@ const action = async ({
|
|
|
82
82
|
log(`Writing ${_types.ConfigTypes.APIC_DEPLOYMENT}`);
|
|
83
83
|
|
|
84
84
|
if (!Object.values(_types.APICDeployments).includes(argv.apicDeployment)) {
|
|
85
|
-
throw Error('"--apic-deployment" value is not correct, please provide one of: prod,
|
|
85
|
+
throw Error('"--apic-deployment" value is not correct, please provide one of: prod, staging, prod-eu, staging-eu, qa, or teams. For example: "axway central config set --apic-deployment=staging"');
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
config[_types.ConfigTypes.APIC_DEPLOYMENT] = argv.apicDeployment;
|
|
@@ -17,6 +17,8 @@ var _resultsRenderers = require("../../common/resultsRenderers");
|
|
|
17
17
|
|
|
18
18
|
var _TmpFile = _interopRequireDefault(require("../../common/TmpFile"));
|
|
19
19
|
|
|
20
|
+
var _types = require("../../common/types");
|
|
21
|
+
|
|
20
22
|
var _utils = require("../../common/utils");
|
|
21
23
|
|
|
22
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -57,8 +59,10 @@ const action = async ({
|
|
|
57
59
|
|
|
58
60
|
if (isUpdated) {
|
|
59
61
|
// intentionally taking just first doc even if user will provide more in the same file while editing.
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
+
const {
|
|
63
|
+
docs
|
|
64
|
+
} = await (0, _utils.loadAndVerifySpecs)(file.path, new Set([_types.Kind.Environment]));
|
|
65
|
+
response = await service.put(`/management/v1alpha1/environments/${name}`, docs[0]);
|
|
62
66
|
render.success((0, _cliKit.chalk)`{greenBright "environment/${name}" has successfully been edited.}`); // render result if output flag has been provided
|
|
63
67
|
|
|
64
68
|
output && (0, _resultsRenderers.renderResponse)(console, response, output);
|
|
@@ -15,6 +15,8 @@ var _DefinitionsManager = require("../../common/DefinitionsManager");
|
|
|
15
15
|
|
|
16
16
|
var _Renderer = _interopRequireDefault(require("../../common/Renderer"));
|
|
17
17
|
|
|
18
|
+
var _resultsRenderers = require("../../common/resultsRenderers");
|
|
19
|
+
|
|
18
20
|
var _types = require("../../common/types");
|
|
19
21
|
|
|
20
22
|
var _utils = require("../../common/utils");
|
|
@@ -25,7 +27,7 @@ const {
|
|
|
25
27
|
log
|
|
26
28
|
} = (0, _snooplogg.default)('central: get');
|
|
27
29
|
|
|
28
|
-
const getListOrByName = async (resourceDef, client, scopeName, resourceName, scopeDef, query) => {
|
|
30
|
+
const getListOrByName = async (resourceDef, client, scopeName, resourceName, scopeDef, query, progressListener) => {
|
|
29
31
|
return resourceName ? await client.getResourceByName({
|
|
30
32
|
resourceDef,
|
|
31
33
|
resourceName,
|
|
@@ -35,7 +37,8 @@ const getListOrByName = async (resourceDef, client, scopeName, resourceName, sco
|
|
|
35
37
|
resourceDef,
|
|
36
38
|
scopeDef,
|
|
37
39
|
scopeName,
|
|
38
|
-
query
|
|
40
|
+
query,
|
|
41
|
+
progressListener
|
|
39
42
|
});
|
|
40
43
|
};
|
|
41
44
|
|
|
@@ -104,9 +107,16 @@ The server supports the following resources:
|
|
|
104
107
|
|
|
105
108
|
${defsManager.getDefsTableForHelpMsg()}`);
|
|
106
109
|
process.exit(1);
|
|
107
|
-
}
|
|
110
|
+
} // Start showing download progress.
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
const downloadMessage = 'Retrieving resource(s)';
|
|
114
|
+
renderer.startSpin(downloadMessage);
|
|
115
|
+
|
|
116
|
+
const progressListener = percent => {
|
|
117
|
+
renderer.updateSpinText(`${downloadMessage} - ${percent}%`);
|
|
118
|
+
}; // parse passed resources types (if passed comma-separated)
|
|
108
119
|
|
|
109
|
-
renderer.startSpin('Retrieving resource(s)'); // parse passed resources types (if passed comma-separated)
|
|
110
120
|
|
|
111
121
|
for (const typedResource of args[0].split(',')) {
|
|
112
122
|
const defs = defsManager.findDefsByWord(typedResource); // is typed resource known?
|
|
@@ -129,7 +139,7 @@ ${defsManager.getDefsTableForHelpMsg()}`);
|
|
|
129
139
|
|
|
130
140
|
if (scope) {
|
|
131
141
|
const results = await Promise.all(defs.filter(defs => !scope.kind || !defs.scope || defs.scope.spec.kind === scope.kind).map(async defs => ({
|
|
132
|
-
response: await getListOrByName(defs.resource, client, scope.name, resourceName, defs.scope, query),
|
|
142
|
+
response: await getListOrByName(defs.resource, client, scope.name, resourceName, defs.scope, query, progressListener),
|
|
133
143
|
cli: defs.cli
|
|
134
144
|
})));
|
|
135
145
|
results.forEach(({
|
|
@@ -142,12 +152,17 @@ ${defsManager.getDefsTableForHelpMsg()}`);
|
|
|
142
152
|
});
|
|
143
153
|
});
|
|
144
154
|
} else {
|
|
145
|
-
let response = await getListOrByName(defs[0].resource, client, undefined, resourceName, undefined, query);
|
|
155
|
+
let response = await getListOrByName(defs[0].resource, client, undefined, resourceName, undefined, query, progressListener);
|
|
146
156
|
getResults.push({
|
|
147
157
|
columns: defs[0].cli.spec.columns,
|
|
148
158
|
response
|
|
149
159
|
});
|
|
150
160
|
}
|
|
161
|
+
} // resolve team guids
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
for (const obj of getResults) {
|
|
165
|
+
await (0, _resultsRenderers.resolveTeamNames)(obj);
|
|
151
166
|
} // considering the command successful if at least 1 response found
|
|
152
167
|
|
|
153
168
|
|
|
@@ -13,6 +13,8 @@ var _ApiServerClient = require("../../common/ApiServerClient");
|
|
|
13
13
|
|
|
14
14
|
var _basicPrompts = require("../../common/basicPrompts");
|
|
15
15
|
|
|
16
|
+
var _CoreConfigController = require("../../common/CoreConfigController");
|
|
17
|
+
|
|
16
18
|
var _DefinitionsManager = require("../../common/DefinitionsManager");
|
|
17
19
|
|
|
18
20
|
var _PlatformClient = require("../../common/PlatformClient");
|
|
@@ -82,6 +84,8 @@ const agents = {
|
|
|
82
84
|
const render = new _Renderer.default(console);
|
|
83
85
|
|
|
84
86
|
try {
|
|
87
|
+
var _accountInfo$roles, _accountInfo$roles2;
|
|
88
|
+
|
|
85
89
|
// initialize clients
|
|
86
90
|
const apiServerClient = new _ApiServerClient.ApiServerClient({
|
|
87
91
|
baseUrl,
|
|
@@ -94,7 +98,23 @@ const agents = {
|
|
|
94
98
|
account,
|
|
95
99
|
region
|
|
96
100
|
});
|
|
97
|
-
const defsManager = await new _DefinitionsManager.DefinitionsManager(apiServerClient).init(); //
|
|
101
|
+
const defsManager = await new _DefinitionsManager.DefinitionsManager(apiServerClient).init(); // Verify account has permission to create an environment and service account.
|
|
102
|
+
|
|
103
|
+
const accountInfo = await platformClient.getAccountInfo();
|
|
104
|
+
const isCentralAdmin = accountInfo === null || accountInfo === void 0 ? void 0 : (_accountInfo$roles = accountInfo.roles) === null || _accountInfo$roles === void 0 ? void 0 : _accountInfo$roles.includes(_CoreConfigController.AccountRole.ApiCentralAdmin);
|
|
105
|
+
const isPlatformAdmin = accountInfo === null || accountInfo === void 0 ? void 0 : (_accountInfo$roles2 = accountInfo.roles) === null || _accountInfo$roles2 === void 0 ? void 0 : _accountInfo$roles2.includes(_CoreConfigController.AccountRole.PlatformAdmin);
|
|
106
|
+
|
|
107
|
+
if (!isCentralAdmin || !isPlatformAdmin) {
|
|
108
|
+
if (!accountInfo || accountInfo.isPlatform) {
|
|
109
|
+
render.error('Error: Not authorized. Account must be assigned the roles: Platform Admin, Central Admin');
|
|
110
|
+
} else {
|
|
111
|
+
render.error('Error: Not authorized. "Service Account" must be authorized with a user account with "Tooling Credentials" assigned the roles: Platform Admin, Central Admin');
|
|
112
|
+
render.error('See: https://docs.axway.com/bundle/axwaycli-open-docs/page/docs/authentication/index.html#service-account-with-username-password');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
process.exit(1);
|
|
116
|
+
} // helper text
|
|
117
|
+
|
|
98
118
|
|
|
99
119
|
console.log(_chalk.default.gray(`This command configures and installs the agents so that you can manage your gateway environment within the Amplify Platform.\n`));
|
|
100
120
|
let installConfig = new _types.AgentInstallConfig();
|
|
@@ -73,8 +73,8 @@ const getIngestionHost = (region, env, apicDeployment, protocol = _types.Ingesti
|
|
|
73
73
|
[_types.Platforms.prod]: {
|
|
74
74
|
[_types.APICDeployments.US]: _types.IngestionHosts.US
|
|
75
75
|
},
|
|
76
|
-
[_types.Platforms.
|
|
77
|
-
[_types.APICDeployments.
|
|
76
|
+
[_types.Platforms.staging]: {
|
|
77
|
+
[_types.APICDeployments.USStaging]: _types.IngestionHosts.USStaging,
|
|
78
78
|
[_types.APICDeployments.QA]: _types.IngestionHosts.QA,
|
|
79
79
|
[_types.APICDeployments.TEAMS]: _types.IngestionHosts.QA
|
|
80
80
|
}
|
|
@@ -83,8 +83,8 @@ const getIngestionHost = (region, env, apicDeployment, protocol = _types.Ingesti
|
|
|
83
83
|
[_types.Platforms.prod]: {
|
|
84
84
|
[_types.APICDeployments.EU]: _types.IngestionHosts.EU
|
|
85
85
|
},
|
|
86
|
-
[_types.Platforms.
|
|
87
|
-
[_types.APICDeployments.
|
|
86
|
+
[_types.Platforms.staging]: {
|
|
87
|
+
[_types.APICDeployments.EUStaging]: _types.IngestionHosts.EUStaging
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
},
|
|
@@ -93,16 +93,16 @@ const getIngestionHost = (region, env, apicDeployment, protocol = _types.Ingesti
|
|
|
93
93
|
[_types.Platforms.prod]: {
|
|
94
94
|
[_types.APICDeployments.US]: _types.IngestionHTTPHosts.US
|
|
95
95
|
},
|
|
96
|
-
[_types.Platforms.
|
|
97
|
-
[_types.APICDeployments.US]: _types.IngestionHTTPHosts.
|
|
96
|
+
[_types.Platforms.staging]: {
|
|
97
|
+
[_types.APICDeployments.US]: _types.IngestionHTTPHosts.USStaging
|
|
98
98
|
}
|
|
99
99
|
},
|
|
100
100
|
[_types.Regions.EU]: {
|
|
101
101
|
[_types.Platforms.prod]: {
|
|
102
102
|
[_types.APICDeployments.EU]: _types.IngestionHTTPHosts.EU
|
|
103
103
|
},
|
|
104
|
-
[_types.Platforms.
|
|
105
|
-
[_types.APICDeployments.EU]: _types.IngestionHTTPHosts.
|
|
104
|
+
[_types.Platforms.staging]: {
|
|
105
|
+
[_types.APICDeployments.EU]: _types.IngestionHTTPHosts.EUStaging
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
}
|
|
@@ -299,8 +299,8 @@ const getCondorHost = (region, env, apicDeployment) => {
|
|
|
299
299
|
[_types.Platforms.prod]: {
|
|
300
300
|
[_types.APICDeployments.US]: _types.IngestionHosts.US
|
|
301
301
|
},
|
|
302
|
-
[_types.Platforms.
|
|
303
|
-
[_types.APICDeployments.
|
|
302
|
+
[_types.Platforms.staging]: {
|
|
303
|
+
[_types.APICDeployments.USStaging]: _types.IngestionHosts.USStaging,
|
|
304
304
|
[_types.APICDeployments.QA]: _types.IngestionHosts.QA,
|
|
305
305
|
[_types.APICDeployments.TEAMS]: _types.IngestionHosts.QA
|
|
306
306
|
}
|
|
@@ -309,8 +309,8 @@ const getCondorHost = (region, env, apicDeployment) => {
|
|
|
309
309
|
[_types.Platforms.prod]: {
|
|
310
310
|
[_types.APICDeployments.EU]: _types.IngestionHosts.EU
|
|
311
311
|
},
|
|
312
|
-
[_types.Platforms.
|
|
313
|
-
[_types.APICDeployments.
|
|
312
|
+
[_types.Platforms.staging]: {
|
|
313
|
+
[_types.APICDeployments.EUStaging]: _types.IngestionHosts.EUStaging
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
316
|
};
|
|
@@ -179,11 +179,11 @@ const getApicDeployment = (region, env) => {
|
|
|
179
179
|
const deployments = {
|
|
180
180
|
[_types.Regions.US]: {
|
|
181
181
|
[_types.Platforms.prod]: _types.APICDeployments.US,
|
|
182
|
-
[_types.Platforms.
|
|
182
|
+
[_types.Platforms.staging]: _types.APICDeployments.TEAMS
|
|
183
183
|
},
|
|
184
184
|
[_types.Regions.EU]: {
|
|
185
185
|
[_types.Platforms.prod]: _types.APICDeployments.EU,
|
|
186
|
-
[_types.Platforms.
|
|
186
|
+
[_types.Platforms.staging]: _types.APICDeployments.EUStaging
|
|
187
187
|
}
|
|
188
188
|
};
|
|
189
189
|
const savedDeployment = new _CliConfigManager.CliConfigManager().getAll()['apic-deployment'];
|
|
@@ -451,6 +451,8 @@ class ApiServerClient {
|
|
|
451
451
|
* scopeDef - optional scope resource definition, used only if @param opts.scopeName provided too
|
|
452
452
|
* scopeName - optional name of the scope, used only if scoped @param opts.scopeDef provided too
|
|
453
453
|
* version - apis version (using alpha1 by default currently)
|
|
454
|
+
* query - Optional RSQL query filter
|
|
455
|
+
* progressListener - Optional callback invoked multiple times with download progress
|
|
454
456
|
* }
|
|
455
457
|
*/
|
|
456
458
|
|
|
@@ -460,7 +462,8 @@ class ApiServerClient {
|
|
|
460
462
|
scopeDef,
|
|
461
463
|
scopeName,
|
|
462
464
|
version = ApiServerVersions.v1alpha1,
|
|
463
|
-
query
|
|
465
|
+
query,
|
|
466
|
+
progressListener
|
|
464
467
|
}) {
|
|
465
468
|
log(`getResourcesList, spec.kind = ${resourceDef.spec.kind}`);
|
|
466
469
|
const result = {
|
|
@@ -481,7 +484,7 @@ class ApiServerClient {
|
|
|
481
484
|
scopeName,
|
|
482
485
|
version
|
|
483
486
|
});
|
|
484
|
-
const response = await service.getWithPagination(url, query);
|
|
487
|
+
const response = await service.getWithPagination(url, query, 50, {}, progressListener);
|
|
485
488
|
result.data = response;
|
|
486
489
|
} catch (e) {
|
|
487
490
|
log('getResourcesList, error: ', e); // expecting only a valid ApiServer error response here
|
|
@@ -603,7 +606,7 @@ class ApiServerClient {
|
|
|
603
606
|
specs[group.name].cli.set(c.name, c);
|
|
604
607
|
}
|
|
605
608
|
|
|
606
|
-
if (
|
|
609
|
+
if (cacheUpdated) _CacheController.CacheController.writeToFile();
|
|
607
610
|
}
|
|
608
611
|
|
|
609
612
|
return specs;
|
|
@@ -637,14 +640,35 @@ class ApiServerClient {
|
|
|
637
640
|
};
|
|
638
641
|
|
|
639
642
|
for (const resource of sortedResources) {
|
|
640
|
-
var _resource$
|
|
643
|
+
var _resource$metadata7, _resource$metadata8, _resource$metadata8$s;
|
|
641
644
|
|
|
642
645
|
const resourceDef = sortedDefsArray.find(def => {
|
|
643
646
|
var _def$spec$scope2, _resource$metadata4, _resource$metadata4$s;
|
|
644
647
|
|
|
645
648
|
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);
|
|
646
649
|
});
|
|
647
|
-
|
|
650
|
+
|
|
651
|
+
if (!resourceDef) {
|
|
652
|
+
var _resource$metadata5, _resource$metadata5$s;
|
|
653
|
+
|
|
654
|
+
let errorMessage = `No resource definition found for "kind/${resource.kind}"`;
|
|
655
|
+
|
|
656
|
+
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)) {
|
|
657
|
+
var _resource$metadata6, _resource$metadata6$s;
|
|
658
|
+
|
|
659
|
+
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}".`;
|
|
660
|
+
} else {
|
|
661
|
+
errorMessage += ' with no scope.';
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
bulkResult.error.push({
|
|
665
|
+
name: resource.name || 'Unknown name',
|
|
666
|
+
kind: resource.kind,
|
|
667
|
+
error: new Error(errorMessage)
|
|
668
|
+
});
|
|
669
|
+
continue;
|
|
670
|
+
}
|
|
671
|
+
|
|
648
672
|
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;
|
|
649
673
|
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;
|
|
650
674
|
const res = await this.createResource({
|
|
@@ -672,12 +696,15 @@ class ApiServerClient {
|
|
|
672
696
|
|
|
673
697
|
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);
|
|
674
698
|
}
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
699
|
+
} else if (res.error) {
|
|
700
|
+
for (const nextError of res.error) {
|
|
701
|
+
bulkResult.error.push({
|
|
702
|
+
name: resource.name || 'Unknown name',
|
|
703
|
+
kind: resource.kind,
|
|
704
|
+
error: nextError
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
}
|
|
681
708
|
} // creating sub-resources
|
|
682
709
|
|
|
683
710
|
|
|
@@ -688,12 +715,15 @@ class ApiServerClient {
|
|
|
688
715
|
var _bulkResult$warning2;
|
|
689
716
|
|
|
690
717
|
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);
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
718
|
+
} else if (subResResult.error) {
|
|
719
|
+
for (const nextError of subResResult.error) {
|
|
720
|
+
bulkResult.error.push({
|
|
721
|
+
name: p.mainResult.name,
|
|
722
|
+
kind: p.mainResult.kind,
|
|
723
|
+
error: nextError
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
}
|
|
697
727
|
}
|
|
698
728
|
|
|
699
729
|
return bulkResult;
|
|
@@ -728,7 +758,7 @@ class ApiServerClient {
|
|
|
728
758
|
};
|
|
729
759
|
|
|
730
760
|
for (const resource of sortedResources) {
|
|
731
|
-
var _resource$
|
|
761
|
+
var _resource$metadata12, _resource$metadata13, _resource$metadata13$;
|
|
732
762
|
|
|
733
763
|
const resourceDef = sortedDefsArray.find(def => {
|
|
734
764
|
var _def$spec$scope3, _resource$metadata9, _resource$metadata9$s;
|
|
@@ -736,7 +766,27 @@ class ApiServerClient {
|
|
|
736
766
|
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);
|
|
737
767
|
}); // the check below is already happening when loading the specs but checking again just in case.
|
|
738
768
|
|
|
739
|
-
if (!resourceDef)
|
|
769
|
+
if (!resourceDef) {
|
|
770
|
+
var _resource$metadata10, _resource$metadata10$;
|
|
771
|
+
|
|
772
|
+
let errorMessage = `No resource definition found for "kind/${resource.kind}"`;
|
|
773
|
+
|
|
774
|
+
if (!!((_resource$metadata10 = resource.metadata) !== null && _resource$metadata10 !== void 0 && (_resource$metadata10$ = _resource$metadata10.scope) !== null && _resource$metadata10$ !== void 0 && _resource$metadata10$.kind)) {
|
|
775
|
+
var _resource$metadata11, _resource$metadata11$;
|
|
776
|
+
|
|
777
|
+
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}".`;
|
|
778
|
+
} else {
|
|
779
|
+
errorMessage += ' with no scope.';
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
bulkResult.created.error.push({
|
|
783
|
+
name: resource.name || 'Unknown name',
|
|
784
|
+
kind: resource.kind,
|
|
785
|
+
error: new Error(errorMessage)
|
|
786
|
+
});
|
|
787
|
+
continue;
|
|
788
|
+
}
|
|
789
|
+
|
|
740
790
|
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;
|
|
741
791
|
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; // only making getResource call if resource has a name
|
|
742
792
|
|
|
@@ -774,12 +824,15 @@ class ApiServerClient {
|
|
|
774
824
|
|
|
775
825
|
if (res.warning) (_bulkResult$created$w = bulkResult.created.warning) === null || _bulkResult$created$w === void 0 ? void 0 : _bulkResult$created$w.push(res.data);else bulkResult.created.success.push(res.data);
|
|
776
826
|
}
|
|
777
|
-
} else if (res.error)
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
827
|
+
} else if (res.error) {
|
|
828
|
+
for (const nextError of res.error) {
|
|
829
|
+
bulkResult.created.error.push({
|
|
830
|
+
name: resource.name || 'Unknown name',
|
|
831
|
+
kind: resource.kind,
|
|
832
|
+
error: nextError
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
}
|
|
783
836
|
} else if (getResult.data) {
|
|
784
837
|
// Resource found, do the update
|
|
785
838
|
const res = await this.updateResource({
|
|
@@ -804,12 +857,15 @@ class ApiServerClient {
|
|
|
804
857
|
} else {
|
|
805
858
|
bulkResult.updated.success.push(res.data);
|
|
806
859
|
}
|
|
807
|
-
} else if (res.error)
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
860
|
+
} else if (res.error) {
|
|
861
|
+
for (const nextError of res.error) {
|
|
862
|
+
bulkResult.updated.error.push({
|
|
863
|
+
name: resource.name,
|
|
864
|
+
kind: resource.kind,
|
|
865
|
+
error: nextError
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
}
|
|
813
869
|
} else {
|
|
814
870
|
// Something is going wrong - more than one error in api server response, re-throw in the same
|
|
815
871
|
// structure as ApiServerErrorResponse so renderer.anyError can pick this up.
|
|
@@ -827,23 +883,32 @@ class ApiServerClient {
|
|
|
827
883
|
var _bulkResult$created$w2;
|
|
828
884
|
|
|
829
885
|
if (p.withWarning) (_bulkResult$created$w2 = bulkResult.created.warning) === null || _bulkResult$created$w2 === void 0 ? void 0 : _bulkResult$created$w2.push(subResResult.data);else bulkResult.created.success.push(subResResult.data);
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
886
|
+
} else if (subResResult.error) {
|
|
887
|
+
for (const nextError of subResResult.error) {
|
|
888
|
+
bulkResult.created.error.push({
|
|
889
|
+
name: p.mainResult.name,
|
|
890
|
+
kind: p.mainResult.kind,
|
|
891
|
+
error: nextError
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
}
|
|
836
895
|
} // creating sub-resources
|
|
837
896
|
|
|
838
897
|
|
|
839
898
|
for (const p of pendingSubResources.updated) {
|
|
840
899
|
const subResResult = await this.resolveSubResourcesRequests(p.mainResult, p.pendingCalls);
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
900
|
+
|
|
901
|
+
if (subResResult.data && !subResResult.error) {
|
|
902
|
+
bulkResult.updated.success.push(subResResult.data);
|
|
903
|
+
} else if (subResResult.error) {
|
|
904
|
+
for (const nextError of subResResult.error) {
|
|
905
|
+
bulkResult.created.error.push({
|
|
906
|
+
name: p.mainResult.name,
|
|
907
|
+
kind: p.mainResult.kind,
|
|
908
|
+
error: nextError
|
|
909
|
+
});
|
|
910
|
+
}
|
|
911
|
+
}
|
|
847
912
|
}
|
|
848
913
|
|
|
849
914
|
return bulkResult;
|
|
@@ -867,7 +932,7 @@ class ApiServerClient {
|
|
|
867
932
|
|
|
868
933
|
for (const resource of sortedResources) {
|
|
869
934
|
try {
|
|
870
|
-
var _resource$metadata15, _resource$metadata16, _resource$metadata16
|
|
935
|
+
var _resource$metadata15, _resource$metadata16, _resource$metadata16$;
|
|
871
936
|
|
|
872
937
|
const resourceDef = sortedDefsArray.find(def => {
|
|
873
938
|
var _def$spec$scope4, _resource$metadata14, _resource$metadata14$;
|
|
@@ -876,7 +941,28 @@ class ApiServerClient {
|
|
|
876
941
|
});
|
|
877
942
|
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;
|
|
878
943
|
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;
|
|
879
|
-
|
|
944
|
+
|
|
945
|
+
if (!resourceDef) {
|
|
946
|
+
var _resource$metadata17, _resource$metadata17$;
|
|
947
|
+
|
|
948
|
+
let errorMessage = `No resource definition found for "kind/${resource.kind}"`;
|
|
949
|
+
|
|
950
|
+
if (!!((_resource$metadata17 = resource.metadata) !== null && _resource$metadata17 !== void 0 && (_resource$metadata17$ = _resource$metadata17.scope) !== null && _resource$metadata17$ !== void 0 && _resource$metadata17$.kind)) {
|
|
951
|
+
var _resource$metadata18, _resource$metadata18$;
|
|
952
|
+
|
|
953
|
+
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}".`;
|
|
954
|
+
} else {
|
|
955
|
+
errorMessage += ' with no scope.';
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
bulkResult.error.push({
|
|
959
|
+
name: resource.name || 'Unknown name',
|
|
960
|
+
kind: resource.kind,
|
|
961
|
+
error: new Error(errorMessage)
|
|
962
|
+
});
|
|
963
|
+
continue;
|
|
964
|
+
}
|
|
965
|
+
|
|
880
966
|
const res = await this.deleteResourceByName({
|
|
881
967
|
resourceName: resource.name,
|
|
882
968
|
resourceDef,
|
|
@@ -884,23 +970,36 @@ class ApiServerClient {
|
|
|
884
970
|
scopeName,
|
|
885
971
|
version
|
|
886
972
|
});
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
973
|
+
|
|
974
|
+
if (res.error) {
|
|
975
|
+
for (const nextError of res.error) {
|
|
976
|
+
bulkResult.error.push({
|
|
977
|
+
name: resource.name,
|
|
978
|
+
kind: resource.kind,
|
|
979
|
+
error: nextError
|
|
980
|
+
});
|
|
981
|
+
}
|
|
982
|
+
} else {
|
|
983
|
+
// deleteResourceByName is constructing a resource representation using buildGenericResource as res.data,
|
|
984
|
+
// but provided in a file resources might contain more data so using them currently
|
|
985
|
+
bulkResult.success.push(resource);
|
|
986
|
+
}
|
|
894
987
|
} catch (e) {
|
|
895
988
|
// expecting only a valid ApiServer error response here
|
|
896
989
|
// re-throw if something different so it should be handled by command's catch block.
|
|
897
990
|
if (e.errors && Array.isArray(e.errors)) {
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
991
|
+
for (const nextError of e.errors) {
|
|
992
|
+
bulkResult.error.push({
|
|
993
|
+
name: resource.name,
|
|
994
|
+
kind: resource.kind,
|
|
995
|
+
error: nextError
|
|
996
|
+
});
|
|
997
|
+
}
|
|
998
|
+
} else {
|
|
999
|
+
throw e;
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
;
|
|
904
1003
|
}
|
|
905
1004
|
}
|
|
906
1005
|
|