@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,298 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.DefinitionsManager = void 0;
|
|
7
|
-
var _snooplogg = _interopRequireDefault(require("snooplogg"));
|
|
8
|
-
var _easyTable = _interopRequireDefault(require("easy-table"));
|
|
9
|
-
var _findIndex = _interopRequireDefault(require("lodash/findIndex"));
|
|
10
|
-
var _findLastIndex = _interopRequireDefault(require("lodash/findLastIndex"));
|
|
11
|
-
var _omit = _interopRequireDefault(require("lodash/omit"));
|
|
12
|
-
var _max2 = _interopRequireDefault(require("lodash/max"));
|
|
13
|
-
var _min2 = _interopRequireDefault(require("lodash/min"));
|
|
14
|
-
var _chalk = require("chalk");
|
|
15
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
-
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; }
|
|
17
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
18
|
-
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); }
|
|
19
|
-
const {
|
|
20
|
-
log
|
|
21
|
-
} = (0, _snooplogg.default)('central:class.DefinitionsManager');
|
|
22
|
-
/**
|
|
23
|
-
* Get / fetch / set specs.
|
|
24
|
-
*/
|
|
25
|
-
class DefinitionsManager {
|
|
26
|
-
constructor(apiServerClient) {
|
|
27
|
-
_defineProperty(this, "apiServerClient", void 0);
|
|
28
|
-
_defineProperty(this, "specs", void 0);
|
|
29
|
-
_defineProperty(this, "cli", new Map());
|
|
30
|
-
_defineProperty(this, "resources", new Map());
|
|
31
|
-
this.apiServerClient = apiServerClient;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Private
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* A reducer for sorting ResourceDefinition by references in the sortByReferences's "fromTo" list.
|
|
39
|
-
* Function utilize current "fromTo" list which is expected to be passed in { sorted, unsorted } form
|
|
40
|
-
* and "from" list which is used to find references for entities in the "fromTo" list.
|
|
41
|
-
* IF resource's "to" references still in "unsorted" list - put it back to unsorted also
|
|
42
|
-
* (its too early for the resource to be sorted).
|
|
43
|
-
* ELSE resource's "to" links are in the "from" list or/and current "sorted" list - find max index
|
|
44
|
-
* and append to "right-most" position of the "sorted" list
|
|
45
|
-
* @param curr
|
|
46
|
-
* @param defsFrom
|
|
47
|
-
*/
|
|
48
|
-
reduceByReferenceLinks(curr, defsFrom) {
|
|
49
|
-
return curr.unsorted.reduce((a, c, _, arr) => {
|
|
50
|
-
// IF any unsorted reference found, push current definition to unsorted too and skip
|
|
51
|
-
const unsortedRefs = c.spec.references.toResources.find(ref => {
|
|
52
|
-
return (0, _findLastIndex.default)(arr, def => {
|
|
53
|
-
var _def$spec$scope;
|
|
54
|
-
return def.spec.kind === ref.kind && ((_def$spec$scope = def.spec.scope) === null || _def$spec$scope === void 0 ? void 0 : _def$spec$scope.kind) === ref.scopeKind;
|
|
55
|
-
}) !== -1;
|
|
56
|
-
});
|
|
57
|
-
if (!!unsortedRefs) {
|
|
58
|
-
a.unsorted.push(c);
|
|
59
|
-
} else {
|
|
60
|
-
var _max, _min;
|
|
61
|
-
// ELSE all refs are in pre populated or in sorted lists, calculate
|
|
62
|
-
const startIndex = (_max = (0, _max2.default)(c.spec.references.toResources.map(ref => {
|
|
63
|
-
// find index in current sorted array
|
|
64
|
-
const sortedListIndex = (0, _findLastIndex.default)(a.sorted, def => {
|
|
65
|
-
var _def$spec$scope2;
|
|
66
|
-
return def.spec.kind === ref.kind && ((_def$spec$scope2 = def.spec.scope) === null || _def$spec$scope2 === void 0 ? void 0 : _def$spec$scope2.kind) === ref.scopeKind;
|
|
67
|
-
});
|
|
68
|
-
// find index in "from-only" array
|
|
69
|
-
const fromListIndex = (0, _findLastIndex.default)(defsFrom, def => {
|
|
70
|
-
var _def$spec$scope3;
|
|
71
|
-
return def.spec.kind === ref.kind && ((_def$spec$scope3 = def.spec.scope) === null || _def$spec$scope3 === void 0 ? void 0 : _def$spec$scope3.kind) === ref.scopeKind;
|
|
72
|
-
});
|
|
73
|
-
// this should never happen only if the api-server is missing some corresponding
|
|
74
|
-
// references so nothing found
|
|
75
|
-
if (sortedListIndex === -1 && fromListIndex === -1) {
|
|
76
|
-
var _c$spec$scope;
|
|
77
|
-
log('reduceByReferenceLinks, startIndex error, def: ', JSON.stringify(c, null, 2), '\nref: ', ref);
|
|
78
|
-
throw Error(`References calculation error, startIndex for kind: ${c.spec.kind} in scope: ${(_c$spec$scope = c.spec.scope) === null || _c$spec$scope === void 0 ? void 0 : _c$spec$scope.kind}`);
|
|
79
|
-
}
|
|
80
|
-
// if nothing found in sorted and pre return null so it will put it back to unsorted
|
|
81
|
-
else return sortedListIndex === -1 ? 0 : sortedListIndex;
|
|
82
|
-
}))) !== null && _max !== void 0 ? _max : null;
|
|
83
|
-
const stopIndex = (_min = (0, _min2.default)(c.spec.references.fromResources.map(ref => {
|
|
84
|
-
const i = (0, _findIndex.default)(a.sorted, def => {
|
|
85
|
-
var _def$spec$scope4;
|
|
86
|
-
return def.spec.kind === ref.kind && ((_def$spec$scope4 = def.spec.scope) === null || _def$spec$scope4 === void 0 ? void 0 : _def$spec$scope4.kind) === ref.scopeKind;
|
|
87
|
-
});
|
|
88
|
-
return i === -1 ? null : i;
|
|
89
|
-
}))) !== null && _min !== void 0 ? _min : null;
|
|
90
|
-
if (startIndex && stopIndex && startIndex >= stopIndex || startIndex === null) {
|
|
91
|
-
var _c$spec$scope2;
|
|
92
|
-
log('reduceByReferenceLinks, indexes error, definition: ', JSON.stringify(c, null, 2));
|
|
93
|
-
throw Error(`References calculation error, indexes for kind: ${c.spec.kind} in scope: ${(_c$spec$scope2 = c.spec.scope) === null || _c$spec$scope2 === void 0 ? void 0 : _c$spec$scope2.kind}`);
|
|
94
|
-
} else {
|
|
95
|
-
a.sorted.splice(startIndex + 1, 0, c);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return a;
|
|
99
|
-
}, {
|
|
100
|
-
sorted: curr.sorted,
|
|
101
|
-
unsorted: []
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Utility for sorting ResourceDefinition by refs. Its grouping resources into 4 arrays and
|
|
107
|
-
* iterates over the "fromTo" list with "reduceByReferenceLinks" reducer until its completely sorted.
|
|
108
|
-
* @param defs list of resources to sort
|
|
109
|
-
*/
|
|
110
|
-
sortByReferences(defs) {
|
|
111
|
-
// 1. Sort by references into 4 arrays
|
|
112
|
-
const groupedDefs = defs.reduce((a, c) => {
|
|
113
|
-
const fromRefsNum = c.spec.references.fromResources.length;
|
|
114
|
-
const toRefsNum = c.spec.references.toResources.length;
|
|
115
|
-
if (fromRefsNum && toRefsNum) a.fromTo.push(c);else if (!fromRefsNum && !toRefsNum) a.noRefs.push(c);else if (!toRefsNum) a.from.push(c);else if (!fromRefsNum) a.to.push(c);
|
|
116
|
-
return a;
|
|
117
|
-
}, {
|
|
118
|
-
noRefs: [],
|
|
119
|
-
from: [],
|
|
120
|
-
fromTo: [],
|
|
121
|
-
to: []
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
// 2. Iterate over "fromTo" defs until its completely sorted
|
|
125
|
-
let result = this.reduceByReferenceLinks({
|
|
126
|
-
sorted: [],
|
|
127
|
-
unsorted: groupedDefs.fromTo
|
|
128
|
-
}, groupedDefs.from);
|
|
129
|
-
let loopCount = 0; // just in case, circuit breaker;
|
|
130
|
-
while (result.unsorted.length > 0 && loopCount <= 1000) {
|
|
131
|
-
result = this.reduceByReferenceLinks(result, groupedDefs.from);
|
|
132
|
-
loopCount += 1;
|
|
133
|
-
}
|
|
134
|
-
// On average function should not take more than 5 loops currently.
|
|
135
|
-
// Lets signal that something is wrong here.
|
|
136
|
-
if (loopCount === 1000) throw Error('Definition references calculation error, max loop count reached');
|
|
137
|
-
return [...groupedDefs.noRefs, ...groupedDefs.from, ...result.sorted, ...groupedDefs.to];
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Public
|
|
142
|
-
* Constructs two maps per resource group(e.g. management, catalog)
|
|
143
|
-
* First map is for the nested 'cli' object and the other is for the nested 'resource' object
|
|
144
|
-
* Created by stripping the 'definitions' group from the specs object, leaving only the 'management' and 'catalog' groups as of 6/7(this will dynamically update in case new groups are added on api-server)
|
|
145
|
-
* Then iterating over that specs object and pushing the cli and resource objects for each group into arrays, which are used to initialize the final maps
|
|
146
|
-
*/
|
|
147
|
-
async init() {
|
|
148
|
-
log('init');
|
|
149
|
-
this.specs = await this.apiServerClient.getSpecs();
|
|
150
|
-
const filteredSpecs = (0, _omit.default)(this.specs, 'definitions');
|
|
151
|
-
const cliArray = [];
|
|
152
|
-
const resourcesArray = [];
|
|
153
|
-
for (const [key] of Object.entries(filteredSpecs)) {
|
|
154
|
-
resourcesArray.push(...filteredSpecs[key].resources);
|
|
155
|
-
cliArray.push(...filteredSpecs[key].cli);
|
|
156
|
-
}
|
|
157
|
-
this.cli = new Map(cliArray);
|
|
158
|
-
this.resources = new Map(resourcesArray);
|
|
159
|
-
return this;
|
|
160
|
-
}
|
|
161
|
-
getAllWordsList() {
|
|
162
|
-
if (!this.specs) return [];
|
|
163
|
-
const result = [];
|
|
164
|
-
this.cli.forEach(v => {
|
|
165
|
-
result.push(v.spec.names.plural, v.spec.names.singular, ...v.spec.names.shortNames);
|
|
166
|
-
});
|
|
167
|
-
return result;
|
|
168
|
-
}
|
|
169
|
-
getAllKindsList() {
|
|
170
|
-
if (!this.specs) throw Error('DefinitionManager.specs is not initialized.');
|
|
171
|
-
const result = new Set([]);
|
|
172
|
-
this.resources.forEach(v => {
|
|
173
|
-
result.add(v.spec.kind);
|
|
174
|
-
});
|
|
175
|
-
return result;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Get the map with resources definitions sorted by references.
|
|
180
|
-
* Used to identify the correct order in which resources should be created / removed.
|
|
181
|
-
* @returns {Map<string,ResourceDefinition>} map where key is ResourceDefinition.name, value is ResourceDefinition
|
|
182
|
-
*/
|
|
183
|
-
getSortedKindsMap() {
|
|
184
|
-
if (!this.specs) throw Error('DefinitionManager.specs is not initialized.');
|
|
185
|
-
// For each spec modify the references:
|
|
186
|
-
// 1. since cli do not support creating or updating sub-resources we are ignoring references and removing them atm.
|
|
187
|
-
// 2. if it is a scoped resource, add a manual "to" reference to the scope resource and a corresponding "from"
|
|
188
|
-
// reference in the scope resource
|
|
189
|
-
this.resources.forEach(definition => {
|
|
190
|
-
// 1. remove the references from the sub-resources and circular references (to self)
|
|
191
|
-
// TODO: circular references support: https://jira.axway.com/browse/APIGOV-20808
|
|
192
|
-
definition.spec.references.toResources = definition.spec.references.toResources.filter(ref => {
|
|
193
|
-
var _definition$spec$scop;
|
|
194
|
-
return !ref.from && !(ref.kind === definition.spec.kind && ref.scopeKind === ((_definition$spec$scop = definition.spec.scope) === null || _definition$spec$scop === void 0 ? void 0 : _definition$spec$scop.kind));
|
|
195
|
-
});
|
|
196
|
-
definition.spec.references.fromResources = definition.spec.references.fromResources.filter(ref => {
|
|
197
|
-
var _definition$spec$scop2;
|
|
198
|
-
return !ref.from && !(ref.kind === definition.spec.kind && ref.scopeKind === ((_definition$spec$scop2 = definition.spec.scope) === null || _definition$spec$scop2 === void 0 ? void 0 : _definition$spec$scop2.kind));
|
|
199
|
-
});
|
|
200
|
-
// 2. add references between scope and scoped resources
|
|
201
|
-
if (!!definition.spec.scope) {
|
|
202
|
-
const scopeDef = [...this.resources.values()].find(res => res.spec.kind === definition.spec.scope.kind); // mind the non-null assertion here
|
|
203
|
-
// modify current definition by adding "toResources" link to scopeDef
|
|
204
|
-
if (!definition.spec.references.toResources.find(ref => ref.kind === scopeDef.spec.kind)) {
|
|
205
|
-
definition.spec.references.toResources.push({
|
|
206
|
-
kind: scopeDef.spec.kind,
|
|
207
|
-
// @ts-ignore
|
|
208
|
-
// NOTE: not used value, adding just to indicate it's manual nature.
|
|
209
|
-
types: ['CALCULATED']
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
// modify related "scope" definition by adding "fromResources" link to current definition
|
|
213
|
-
if (!scopeDef.spec.references.fromResources.find(ref => ref.kind === definition.spec.kind)) {
|
|
214
|
-
scopeDef.spec.references.fromResources.push({
|
|
215
|
-
kind: definition.spec.kind,
|
|
216
|
-
// @ts-ignore
|
|
217
|
-
// NOTE: not used value, adding just to indicate it's manual nature.
|
|
218
|
-
types: ['CALCULATED'],
|
|
219
|
-
scopeKind: definition.spec.scope.kind
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
// execute the sorting, note that the returning map is using the "name" field as keys.
|
|
225
|
-
const res = this.sortByReferences([...this.resources.values()]);
|
|
226
|
-
return new Map(res.map(v => [v.name, v]));
|
|
227
|
-
}
|
|
228
|
-
getDefsTableForHelpMsg() {
|
|
229
|
-
if (!this.specs) return 'No resources found.';
|
|
230
|
-
const t = new _easyTable.default();
|
|
231
|
-
|
|
232
|
-
// create the 'axway central get' table
|
|
233
|
-
this.cli.forEach(v => {
|
|
234
|
-
var _this$resources$get, _this$resources$get2, _this$resources, _this$resources$get3, _this$resources$get3$;
|
|
235
|
-
// grab the resource group
|
|
236
|
-
const group = v.metadata.scope.name;
|
|
237
|
-
t.cell('RESOURCE', `${v.spec.names.plural}`, () => (0, _chalk.cyan)(v.spec.names.plural));
|
|
238
|
-
t.cell('SHORT NAMES', [...(v.spec.names.shortNamesAlias || v.spec.names.shortNames)].join(','));
|
|
239
|
-
t.cell('RESOURCE KIND', (_this$resources$get = this.resources.get(v.spec.resourceDefinition)) === null || _this$resources$get === void 0 ? void 0 : _this$resources$get.spec.kind);
|
|
240
|
-
t.cell('SCOPED', (_this$resources$get2 = this.resources.get(v.spec.resourceDefinition)) !== null && _this$resources$get2 !== void 0 && _this$resources$get2.spec.scope ? 'true' : 'false');
|
|
241
|
-
t.cell('SCOPE KIND', (_this$resources = this.resources) === null || _this$resources === void 0 ? void 0 : (_this$resources$get3 = _this$resources.get(v.spec.resourceDefinition)) === null || _this$resources$get3 === void 0 ? void 0 : (_this$resources$get3$ = _this$resources$get3.spec.scope) === null || _this$resources$get3$ === void 0 ? void 0 : _this$resources$get3$.kind);
|
|
242
|
-
t.cell('RESOURCE GROUP', group);
|
|
243
|
-
t.newRow();
|
|
244
|
-
});
|
|
245
|
-
return t.sort(['RESOURCE']).toString();
|
|
246
|
-
}
|
|
247
|
-
findDefsByKind(kind) {
|
|
248
|
-
log('findDefsByKind: ', kind);
|
|
249
|
-
const res = [...this.resources].reduce((a, [_, def]) => {
|
|
250
|
-
if (def.spec.kind === kind) {
|
|
251
|
-
a.push({
|
|
252
|
-
resource: def,
|
|
253
|
-
cli: [...this.cli].find(([_, cliDef]) => cliDef.spec.resourceDefinition === def.name)[1],
|
|
254
|
-
scope: def.spec.scope ? [...this.resources].find(([_, resDef]) => resDef.spec.kind === def.spec.scope.kind)[1] : undefined
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
return a;
|
|
258
|
-
}, []);
|
|
259
|
-
return res.length ? res : null;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Returns set of related definitions if word is known.
|
|
264
|
-
* @param word word to search for
|
|
265
|
-
* @returns {object | null} {
|
|
266
|
-
* resource: definition of the resource
|
|
267
|
-
* cli: cli definition of the resource
|
|
268
|
-
* scope: scope resource definition, can support multiple scopes (only for scoped resources, otherwise it is undefined)
|
|
269
|
-
* } or null if no definitions found for this word.
|
|
270
|
-
*/
|
|
271
|
-
findDefsByWord(word) {
|
|
272
|
-
log('findDefsByWord: ', word);
|
|
273
|
-
if (!this.specs) return null;
|
|
274
|
-
const cliKv = [...this.cli].filter(([_, v]) => {
|
|
275
|
-
var _v$spec$names$shortNa;
|
|
276
|
-
return v.spec.names.plural === word || v.spec.names.singular === word || v.spec.names.shortNames.includes(word) || ((_v$spec$names$shortNa = v.spec.names.shortNamesAlias) === null || _v$spec$names$shortNa === void 0 ? void 0 : _v$spec$names$shortNa.includes(word));
|
|
277
|
-
});
|
|
278
|
-
// no match found returning null
|
|
279
|
-
if (!cliKv.length) return null;
|
|
280
|
-
const result = [...this.cli].reduce((a, [_, cliDef]) => {
|
|
281
|
-
var _cliDef$spec$names$sh;
|
|
282
|
-
if (cliDef.spec.names.plural === word || cliDef.spec.names.singular === word || cliDef.spec.names.shortNames.includes(word) || (_cliDef$spec$names$sh = cliDef.spec.names.shortNamesAlias) !== null && _cliDef$spec$names$sh !== void 0 && _cliDef$spec$names$sh.includes(word)) {
|
|
283
|
-
var _this$findDefsByKind;
|
|
284
|
-
// note: mind non-null assertion
|
|
285
|
-
const resource = this.resources.get(cliDef.spec.resourceDefinition);
|
|
286
|
-
const scope = resource.spec.scope ? (_this$findDefsByKind = this.findDefsByKind(resource.spec.scope.kind)) === null || _this$findDefsByKind === void 0 ? void 0 : _this$findDefsByKind[0].resource : null;
|
|
287
|
-
a.push({
|
|
288
|
-
resource,
|
|
289
|
-
cli: cliDef,
|
|
290
|
-
scope: !!scope ? scope : undefined
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
return a;
|
|
294
|
-
}, []);
|
|
295
|
-
return result;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
exports.DefinitionsManager = DefinitionsManager;
|
package/dist/common/Kubectl.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.kubectl = exports.exec = void 0;
|
|
7
|
-
var _child_process = require("child_process");
|
|
8
|
-
var _cliKit = require("cli-kit");
|
|
9
|
-
var _util = _interopRequireDefault(require("util"));
|
|
10
|
-
var _utils = require("./utils");
|
|
11
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
-
const quotes = _utils.isWindows ? '"' : "'";
|
|
13
|
-
const {
|
|
14
|
-
log
|
|
15
|
-
} = (0, _cliKit.snooplogg)('central: kubectl');
|
|
16
|
-
const exec = exports.exec = _util.default.promisify(_child_process.exec);
|
|
17
|
-
class Kubectl {
|
|
18
|
-
async get(resource, args) {
|
|
19
|
-
return await this.invoke('get', resource, args);
|
|
20
|
-
}
|
|
21
|
-
async create(resource, args) {
|
|
22
|
-
return await this.invoke('create', resource, args);
|
|
23
|
-
}
|
|
24
|
-
async delete(resource, args) {
|
|
25
|
-
return await this.invoke('delete', resource, args);
|
|
26
|
-
}
|
|
27
|
-
async isInstalled() {
|
|
28
|
-
return await this.execKubectl('version', 'version');
|
|
29
|
-
}
|
|
30
|
-
async invoke(action, resource, args) {
|
|
31
|
-
const obj = {
|
|
32
|
-
error: null,
|
|
33
|
-
data: []
|
|
34
|
-
};
|
|
35
|
-
let logMsg = `kubectl ${action} ${resource}`;
|
|
36
|
-
logMsg = args ? logMsg += ` ${args}` : logMsg;
|
|
37
|
-
log(logMsg);
|
|
38
|
-
const res = await this.execKubectl(`${action} ${resource} ${args || ''}`, resource);
|
|
39
|
-
if (res.error) {
|
|
40
|
-
obj.error = res.error;
|
|
41
|
-
log(`command failed: ${res.error}`);
|
|
42
|
-
return obj;
|
|
43
|
-
}
|
|
44
|
-
obj.data = this.cleanResponse(res.data);
|
|
45
|
-
log('command success');
|
|
46
|
-
return obj;
|
|
47
|
-
}
|
|
48
|
-
async execKubectl(action, resource) {
|
|
49
|
-
let {
|
|
50
|
-
stdout,
|
|
51
|
-
stderr
|
|
52
|
-
} = await exec(`kubectl ${action} | awk ${quotes}{print $1}${quotes}`);
|
|
53
|
-
if (stderr.includes('WARNING')) {
|
|
54
|
-
stderr = '';
|
|
55
|
-
}
|
|
56
|
-
return stderr ? {
|
|
57
|
-
data: null,
|
|
58
|
-
error: `K8S ${resource}: ${stderr}`
|
|
59
|
-
} : {
|
|
60
|
-
data: stdout,
|
|
61
|
-
error: null
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
cleanResponse(res) {
|
|
65
|
-
return res.split('\n').filter(str => str !== 'NAME' && str != '').sort();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
const kubectl = exports.kubectl = new Kubectl();
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.PlatformTeamMemberRole = exports.PlatformServiceAccountRole = exports.PlatformClient = exports.PlatformAuthMethod = void 0;
|
|
7
|
-
var _snooplogg = _interopRequireDefault(require("snooplogg"));
|
|
8
|
-
var _amplifyCliUtils = require("@axway/amplify-cli-utils");
|
|
9
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
-
function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|
11
|
-
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
12
|
-
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
13
|
-
function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|
14
|
-
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
15
|
-
const {
|
|
16
|
-
log
|
|
17
|
-
} = (0, _snooplogg.default)('central:class.PlatformClient');
|
|
18
|
-
let PlatformAuthMethod = exports.PlatformAuthMethod = /*#__PURE__*/function (PlatformAuthMethod) {
|
|
19
|
-
PlatformAuthMethod["Certificate"] = "certificate";
|
|
20
|
-
PlatformAuthMethod["Secret"] = "secret";
|
|
21
|
-
return PlatformAuthMethod;
|
|
22
|
-
}({});
|
|
23
|
-
let PlatformServiceAccountRole = exports.PlatformServiceAccountRole = /*#__PURE__*/function (PlatformServiceAccountRole) {
|
|
24
|
-
PlatformServiceAccountRole["ApiCentralAdmin"] = "api_central_admin";
|
|
25
|
-
PlatformServiceAccountRole["FlowCentralAccessManager"] = "fc_access_manager";
|
|
26
|
-
PlatformServiceAccountRole["FlowCentralIntegration"] = "fc_integration";
|
|
27
|
-
PlatformServiceAccountRole["FlowCentralITAdmin"] = "fc_it_admin";
|
|
28
|
-
PlatformServiceAccountRole["FlowCentralProductsAdmin"] = "fc_products_admin";
|
|
29
|
-
PlatformServiceAccountRole["FlowCentralSpecOps"] = "fc_spec_ops";
|
|
30
|
-
PlatformServiceAccountRole["FlowCentralSubscriptionApprover"] = "fc_subscriptionapprover";
|
|
31
|
-
PlatformServiceAccountRole["FlowCentralSubscriptionSpecialist"] = "fc_subscriptionspecialist";
|
|
32
|
-
PlatformServiceAccountRole["FlowCentralTemplatePublisher"] = "fc_templatepublisher";
|
|
33
|
-
PlatformServiceAccountRole["FlowCentralCftAdmin"] = "fc_cft_admin";
|
|
34
|
-
return PlatformServiceAccountRole;
|
|
35
|
-
}({});
|
|
36
|
-
let PlatformTeamMemberRole = exports.PlatformTeamMemberRole = /*#__PURE__*/function (PlatformTeamMemberRole) {
|
|
37
|
-
PlatformTeamMemberRole["Admin"] = "administrator";
|
|
38
|
-
PlatformTeamMemberRole["Developer"] = "developer";
|
|
39
|
-
PlatformTeamMemberRole["Consumer"] = "consumer";
|
|
40
|
-
PlatformTeamMemberRole["CatalogManager"] = "catalog_manager";
|
|
41
|
-
return PlatformTeamMemberRole;
|
|
42
|
-
}({});
|
|
43
|
-
/** Options used to create a service account via the PlatformClient.createServiceAccount() method. */
|
|
44
|
-
/** Provides information for a platform service account. */
|
|
45
|
-
var _baseUrl = /*#__PURE__*/new WeakMap();
|
|
46
|
-
var _accountName = /*#__PURE__*/new WeakMap();
|
|
47
|
-
var _amplifyConfig = /*#__PURE__*/new WeakMap();
|
|
48
|
-
var _amplifySdk = /*#__PURE__*/new WeakMap();
|
|
49
|
-
class PlatformClient {
|
|
50
|
-
constructor({
|
|
51
|
-
baseUrl,
|
|
52
|
-
region,
|
|
53
|
-
account
|
|
54
|
-
} = {}) {
|
|
55
|
-
_classPrivateFieldInitSpec(this, _baseUrl, void 0);
|
|
56
|
-
_classPrivateFieldInitSpec(this, _accountName, void 0);
|
|
57
|
-
_classPrivateFieldInitSpec(this, _amplifyConfig, void 0);
|
|
58
|
-
_classPrivateFieldInitSpec(this, _amplifySdk, void 0);
|
|
59
|
-
log(`initializing client with params: baseUrl = ${baseUrl}, region = ${region}, account = ${account}`);
|
|
60
|
-
_classPrivateFieldSet(_baseUrl, this, baseUrl);
|
|
61
|
-
_classPrivateFieldSet(_accountName, this, account);
|
|
62
|
-
const initResult = (0, _amplifyCliUtils.initSDK)({
|
|
63
|
-
baseUrl: _classPrivateFieldGet(_baseUrl, this),
|
|
64
|
-
username: _classPrivateFieldGet(_accountName, this)
|
|
65
|
-
});
|
|
66
|
-
_classPrivateFieldSet(_amplifyConfig, this, initResult.config);
|
|
67
|
-
_classPrivateFieldSet(_amplifySdk, this, initResult.sdk);
|
|
68
|
-
}
|
|
69
|
-
async getAccountInfo() {
|
|
70
|
-
var _classPrivateFieldGet2;
|
|
71
|
-
// Get default teams from config.
|
|
72
|
-
const defaultTeams = _classPrivateFieldGet(_amplifyConfig, this).get(`${(0, _amplifyCliUtils.getAuthConfigEnvSpecifier)((_classPrivateFieldGet2 = _classPrivateFieldGet(_amplifySdk, this).env) === null || _classPrivateFieldGet2 === void 0 ? void 0 : _classPrivateFieldGet2.name)}.defaultTeam`);
|
|
73
|
-
|
|
74
|
-
// Fetch specified account or default account currently logged in.
|
|
75
|
-
let accountInfo;
|
|
76
|
-
if (_classPrivateFieldGet(_accountName, this)) {
|
|
77
|
-
accountInfo = await _classPrivateFieldGet(_amplifySdk, this).auth.find(_classPrivateFieldGet(_accountName, this), defaultTeams);
|
|
78
|
-
if (!accountInfo) {
|
|
79
|
-
throw new Error(`Account "${_classPrivateFieldGet(_accountName, this)}" not found`);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
if (!accountInfo) {
|
|
83
|
-
const accountArray = await _classPrivateFieldGet(_amplifySdk, this).auth.list({
|
|
84
|
-
defaultTeams,
|
|
85
|
-
validate: true
|
|
86
|
-
});
|
|
87
|
-
if (accountArray) {
|
|
88
|
-
accountInfo = accountArray.find(nextAccount => nextAccount.default) || accountArray[0];
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Make sure "subscriptions" is defined since Amplify SDK requires it. (Will throw error if missing.)
|
|
93
|
-
if (accountInfo && accountInfo.org && !accountInfo.org.subscriptions) {
|
|
94
|
-
accountInfo.org.subscriptions = [];
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Return account info if found.
|
|
98
|
-
return accountInfo;
|
|
99
|
-
}
|
|
100
|
-
async createServiceAccount(options) {
|
|
101
|
-
const accountInfo = await this.getAccountInfo();
|
|
102
|
-
const result = await _classPrivateFieldGet(_amplifySdk, this).client.create(accountInfo, accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.org, options);
|
|
103
|
-
return result.client;
|
|
104
|
-
}
|
|
105
|
-
async getServiceAccounts(filterRole) {
|
|
106
|
-
const result = await _classPrivateFieldGet(_amplifySdk, this).client.list(await this.getAccountInfo());
|
|
107
|
-
let clients = result.clients || [];
|
|
108
|
-
if (filterRole) {
|
|
109
|
-
log('filter clients by ', filterRole);
|
|
110
|
-
clients = clients.filter(client => client === null || client === void 0 ? void 0 : client.roles.find(r => r === filterRole));
|
|
111
|
-
}
|
|
112
|
-
return clients;
|
|
113
|
-
}
|
|
114
|
-
async getTeams() {
|
|
115
|
-
var _account$team, _teams$find;
|
|
116
|
-
log(`getTeams`);
|
|
117
|
-
const account = await this.getAccountInfo();
|
|
118
|
-
const {
|
|
119
|
-
teams
|
|
120
|
-
} = await _classPrivateFieldGet(_amplifySdk, this).team.list(account);
|
|
121
|
-
const teamGuid = ((_account$team = account.team) === null || _account$team === void 0 ? void 0 : _account$team.guid) && ((_teams$find = teams.find(team => team.guid === account.team.guid)) === null || _teams$find === void 0 ? void 0 : _teams$find.guid);
|
|
122
|
-
return teams.map(team => ({
|
|
123
|
-
...team,
|
|
124
|
-
default: teamGuid && team.guid === teamGuid || !teamGuid && team.default
|
|
125
|
-
}));
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
exports.PlatformClient = PlatformClient;
|