@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,408 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.ProductizationHelper = void 0;
|
|
7
|
-
var _types = require("../../../common/types");
|
|
8
|
-
var _utils = require("../../../common/utils");
|
|
9
|
-
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; }
|
|
10
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
11
|
-
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); }
|
|
12
|
-
class ProductizationHelper {
|
|
13
|
-
constructor(apiServerClient) {
|
|
14
|
-
_defineProperty(this, "apiServerClient", void 0);
|
|
15
|
-
this.apiServerClient = apiServerClient;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Bulk Productization of API services.
|
|
20
|
-
* @param resources array of API services to be productized
|
|
21
|
-
*/
|
|
22
|
-
async bulkProductizeAPIServices(resources, sortedDefsMap, transferOwnership) {
|
|
23
|
-
const sortedDefsArray = Array.from(sortedDefsMap.values());
|
|
24
|
-
let bulkResultMap = new Map();
|
|
25
|
-
for (const resource of resources) {
|
|
26
|
-
var _resource$spec, _resource$spec$apiSer, _resource$metadata, _resource$metadata$sc, _resource$spec6, _resource$spec6$apiSe, _resource$metadata2, _resource$spec15, _resource$spec15$apiS;
|
|
27
|
-
let bulkResult = {
|
|
28
|
-
success: [],
|
|
29
|
-
error: [],
|
|
30
|
-
warning: []
|
|
31
|
-
};
|
|
32
|
-
if (!(resource !== null && resource !== void 0 && (_resource$spec = resource.spec) !== null && _resource$spec !== void 0 && (_resource$spec$apiSer = _resource$spec.apiService) !== null && _resource$spec$apiSer !== void 0 && _resource$spec$apiSer.name)) {
|
|
33
|
-
var _resource$spec2, _resource$spec2$apiSe, _resource$spec3, _resource$spec3$apiSe;
|
|
34
|
-
let errorMessage = `Found an entry without a logical name for "kind/${_types.Kind.APIService}".`;
|
|
35
|
-
bulkResult.error.push({
|
|
36
|
-
name: resource === null || resource === void 0 ? void 0 : (_resource$spec2 = resource.spec) === null || _resource$spec2 === void 0 ? void 0 : (_resource$spec2$apiSe = _resource$spec2.apiService) === null || _resource$spec2$apiSe === void 0 ? void 0 : _resource$spec2$apiSe.name,
|
|
37
|
-
kind: _types.Kind.APIService,
|
|
38
|
-
error: new Error(errorMessage)
|
|
39
|
-
});
|
|
40
|
-
bulkResultMap.set((_resource$spec3 = resource.spec) === null || _resource$spec3 === void 0 ? void 0 : (_resource$spec3$apiSe = _resource$spec3.apiService) === null || _resource$spec3$apiSe === void 0 ? void 0 : _resource$spec3$apiSe.name, bulkResult);
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
if (!((_resource$metadata = resource.metadata) !== null && _resource$metadata !== void 0 && (_resource$metadata$sc = _resource$metadata.scope) !== null && _resource$metadata$sc !== void 0 && _resource$metadata$sc.name)) {
|
|
44
|
-
var _resource$spec4, _resource$spec4$apiSe, _resource$spec5, _resource$spec5$apiSe;
|
|
45
|
-
let errorMessage = `Found an API Service without a scope name for "kind/${_types.Kind.Environment}".`;
|
|
46
|
-
bulkResult.error.push({
|
|
47
|
-
name: resource === null || resource === void 0 ? void 0 : (_resource$spec4 = resource.spec) === null || _resource$spec4 === void 0 ? void 0 : (_resource$spec4$apiSe = _resource$spec4.apiService) === null || _resource$spec4$apiSe === void 0 ? void 0 : _resource$spec4$apiSe.name,
|
|
48
|
-
kind: _types.Kind.Environment,
|
|
49
|
-
error: new Error(errorMessage)
|
|
50
|
-
});
|
|
51
|
-
bulkResultMap.set((_resource$spec5 = resource.spec) === null || _resource$spec5 === void 0 ? void 0 : (_resource$spec5$apiSe = _resource$spec5.apiService) === null || _resource$spec5$apiSe === void 0 ? void 0 : _resource$spec5$apiSe.name, bulkResult);
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
const apiSvcResourceDef = await (0, _utils.getResourceDefinition)(sortedDefsArray, _types.Kind.APIService, _types.Kind.Environment);
|
|
55
|
-
const envResourceDef = await (0, _utils.getResourceDefinition)(sortedDefsArray, _types.Kind.Environment);
|
|
56
|
-
const assetResourceDef = await (0, _utils.getResourceDefinition)(sortedDefsArray, _types.Kind.Asset);
|
|
57
|
-
const productResourceDef = await (0, _utils.getResourceDefinition)(sortedDefsArray, _types.Kind.Product);
|
|
58
|
-
const apiSvc = await this.apiServerClient.getResourceByName({
|
|
59
|
-
resourceDef: apiSvcResourceDef,
|
|
60
|
-
resourceName: resource === null || resource === void 0 ? void 0 : (_resource$spec6 = resource.spec) === null || _resource$spec6 === void 0 ? void 0 : (_resource$spec6$apiSe = _resource$spec6.apiService) === null || _resource$spec6$apiSe === void 0 ? void 0 : _resource$spec6$apiSe.name,
|
|
61
|
-
scopeDef: envResourceDef,
|
|
62
|
-
scopeName: (_resource$metadata2 = resource.metadata) === null || _resource$metadata2 === void 0 ? void 0 : _resource$metadata2.scope.name
|
|
63
|
-
});
|
|
64
|
-
if (apiSvc.data && !apiSvc.error) {
|
|
65
|
-
var _apiSvc$data, _apiSvc$data$metadata, _resource$metadata3, _apiServiceInstances$, _apiServiceInstances$2, _assetResourcesResult2, _assetResourcesResult3, _assetResourcesResult4, _assetResourcesResult5, _bulkResult$warning;
|
|
66
|
-
const apiSvcInstanceResDef = await (0, _utils.getResourceDefinition)(sortedDefsArray, _types.Kind.APIServiceInstance, _types.Kind.Environment);
|
|
67
|
-
const query = 'metadata.references.id==' + ((_apiSvc$data = apiSvc.data) === null || _apiSvc$data === void 0 ? void 0 : (_apiSvc$data$metadata = _apiSvc$data.metadata) === null || _apiSvc$data$metadata === void 0 ? void 0 : _apiSvc$data$metadata.id);
|
|
68
|
-
const apiServiceInstances = await this.apiServerClient.getResourcesList({
|
|
69
|
-
resourceDef: apiSvcInstanceResDef,
|
|
70
|
-
scopeDef: envResourceDef,
|
|
71
|
-
scopeName: (_resource$metadata3 = resource.metadata) === null || _resource$metadata3 === void 0 ? void 0 : _resource$metadata3.scope.name,
|
|
72
|
-
query: query
|
|
73
|
-
});
|
|
74
|
-
// Donot continue if there are no api service instances
|
|
75
|
-
if (apiServiceInstances.error && ((_apiServiceInstances$ = apiServiceInstances.error) === null || _apiServiceInstances$ === void 0 ? void 0 : _apiServiceInstances$.length) > 0 || !apiServiceInstances.data || ((_apiServiceInstances$2 = apiServiceInstances.data) === null || _apiServiceInstances$2 === void 0 ? void 0 : _apiServiceInstances$2.length) === 0) {
|
|
76
|
-
var _resource$spec7, _resource$spec7$apiSe, _resource$spec8, _resource$spec8$apiSe, _resource$spec9, _resource$spec9$apiSe;
|
|
77
|
-
bulkResult.error.push({
|
|
78
|
-
name: resource === null || resource === void 0 ? void 0 : (_resource$spec7 = resource.spec) === null || _resource$spec7 === void 0 ? void 0 : (_resource$spec7$apiSe = _resource$spec7.apiService) === null || _resource$spec7$apiSe === void 0 ? void 0 : _resource$spec7$apiSe.name,
|
|
79
|
-
kind: resource.kind,
|
|
80
|
-
error: new Error('Unable to find APIServiceInstances for API Service: ' + (resource === null || resource === void 0 ? void 0 : (_resource$spec8 = resource.spec) === null || _resource$spec8 === void 0 ? void 0 : (_resource$spec8$apiSe = _resource$spec8.apiService) === null || _resource$spec8$apiSe === void 0 ? void 0 : _resource$spec8$apiSe.name))
|
|
81
|
-
});
|
|
82
|
-
bulkResultMap.set((_resource$spec9 = resource.spec) === null || _resource$spec9 === void 0 ? void 0 : (_resource$spec9$apiSe = _resource$spec9.apiService) === null || _resource$spec9$apiSe === void 0 ? void 0 : _resource$spec9$apiSe.name, bulkResult);
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
let assetResourcesResult = await this.createAssetResourcesForAPIServiceProductization(apiSvc.data, sortedDefsMap, apiServiceInstances, transferOwnership);
|
|
86
|
-
if (assetResourcesResult.error.length > 0) {
|
|
87
|
-
var _assetResourcesResult, _resource$spec10, _resource$spec10$apiS;
|
|
88
|
-
// if there is an error at any stage while productizing an api service,
|
|
89
|
-
// clean up the resources created until that stage to avoid duplicate resources hanging around
|
|
90
|
-
const asset = (_assetResourcesResult = assetResourcesResult.warning) === null || _assetResourcesResult === void 0 ? void 0 : _assetResourcesResult.find(result => result.kind === _types.Kind.Asset);
|
|
91
|
-
if (asset !== undefined) {
|
|
92
|
-
await this.cleanupResourcesOnFailure(asset, assetResourceDef);
|
|
93
|
-
}
|
|
94
|
-
bulkResult.error.push(...assetResourcesResult.error);
|
|
95
|
-
bulkResultMap.set((_resource$spec10 = resource.spec) === null || _resource$spec10 === void 0 ? void 0 : (_resource$spec10$apiS = _resource$spec10.apiService) === null || _resource$spec10$apiS === void 0 ? void 0 : _resource$spec10$apiS.name, bulkResult);
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
const assetName = (_assetResourcesResult2 = assetResourcesResult.warning) === null || _assetResourcesResult2 === void 0 ? void 0 : (_assetResourcesResult3 = _assetResourcesResult2.find(res => res.kind === _types.Kind.Asset)) === null || _assetResourcesResult3 === void 0 ? void 0 : _assetResourcesResult3.name;
|
|
99
|
-
const assetReleaseTagName = (_assetResourcesResult4 = assetResourcesResult.warning) === null || _assetResourcesResult4 === void 0 ? void 0 : (_assetResourcesResult5 = _assetResourcesResult4.find(res => res.kind === _types.Kind.ReleaseTag)) === null || _assetResourcesResult5 === void 0 ? void 0 : _assetResourcesResult5.name;
|
|
100
|
-
if (assetResourcesResult.warning) (_bulkResult$warning = bulkResult.warning) === null || _bulkResult$warning === void 0 ? void 0 : _bulkResult$warning.push(...assetResourcesResult.warning);
|
|
101
|
-
// check if asset release tag is created, then only proceed with creation of product resources
|
|
102
|
-
await this.checkForAssetReleaseTag(sortedDefsArray, assetReleaseTagName, assetName).then(async result => {
|
|
103
|
-
if (result) {
|
|
104
|
-
await this.waitForAssetActivation(assetResourceDef, assetName).then(async active => {
|
|
105
|
-
if (active) {
|
|
106
|
-
var _bulkResult$warning2;
|
|
107
|
-
let productResourcesResult = await this.createProductResourcesForAPIServiceProductization(apiSvc.data, sortedDefsMap, transferOwnership, assetName);
|
|
108
|
-
if (productResourcesResult.error.length > 0) {
|
|
109
|
-
var _assetResourcesResult6, _productResourcesResu;
|
|
110
|
-
// if there is an error at any stage while productizing an api service,
|
|
111
|
-
// clean up the resources created until that stage to avoid duplicate resources hanging around
|
|
112
|
-
const asset = (_assetResourcesResult6 = assetResourcesResult.warning) === null || _assetResourcesResult6 === void 0 ? void 0 : _assetResourcesResult6.find(result => result.kind === _types.Kind.Asset);
|
|
113
|
-
const product = (_productResourcesResu = productResourcesResult.warning) === null || _productResourcesResu === void 0 ? void 0 : _productResourcesResu.find(result => result.kind === _types.Kind.Product);
|
|
114
|
-
if (asset !== undefined) {
|
|
115
|
-
await this.cleanupResourcesOnFailure(asset, assetResourceDef);
|
|
116
|
-
}
|
|
117
|
-
if (product !== undefined) {
|
|
118
|
-
await this.cleanupResourcesOnFailure(product, productResourceDef);
|
|
119
|
-
}
|
|
120
|
-
bulkResult.error.push(...productResourcesResult.error);
|
|
121
|
-
}
|
|
122
|
-
if (productResourcesResult.warning) (_bulkResult$warning2 = bulkResult.warning) === null || _bulkResult$warning2 === void 0 ? void 0 : _bulkResult$warning2.push(...productResourcesResult.warning);
|
|
123
|
-
} else {
|
|
124
|
-
var _resource$spec11, _resource$spec11$apiS;
|
|
125
|
-
if (assetResourcesResult.warning && assetResourcesResult.warning.length > 0) {
|
|
126
|
-
const asset = assetResourcesResult.warning.find(result => result.kind === _types.Kind.Asset);
|
|
127
|
-
asset ? await this.cleanupResourcesOnFailure(asset, assetResourceDef) : undefined;
|
|
128
|
-
}
|
|
129
|
-
bulkResult.error.push({
|
|
130
|
-
name: resource === null || resource === void 0 ? void 0 : (_resource$spec11 = resource.spec) === null || _resource$spec11 === void 0 ? void 0 : (_resource$spec11$apiS = _resource$spec11.apiService) === null || _resource$spec11$apiS === void 0 ? void 0 : _resource$spec11$apiS.name,
|
|
131
|
-
kind: _types.Kind.Asset,
|
|
132
|
-
error: new Error('Asset status not set to active while productizing api service')
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
} else {
|
|
137
|
-
var _resource$spec12, _resource$spec12$apiS;
|
|
138
|
-
if (assetResourcesResult.warning && assetResourcesResult.warning.length > 0) {
|
|
139
|
-
const asset = assetResourcesResult.warning.find(result => result.kind === _types.Kind.Asset);
|
|
140
|
-
asset ? await this.cleanupResourcesOnFailure(asset, assetResourceDef) : undefined;
|
|
141
|
-
}
|
|
142
|
-
bulkResult.error.push({
|
|
143
|
-
name: resource === null || resource === void 0 ? void 0 : (_resource$spec12 = resource.spec) === null || _resource$spec12 === void 0 ? void 0 : (_resource$spec12$apiS = _resource$spec12.apiService) === null || _resource$spec12$apiS === void 0 ? void 0 : _resource$spec12$apiS.name,
|
|
144
|
-
kind: _types.Kind.ReleaseTag,
|
|
145
|
-
error: new Error('Unable to get asset release status while productizing api service')
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
} else {
|
|
150
|
-
var _resource$spec13, _resource$spec13$apiS, _resource$spec14, _resource$spec14$apiS, _resource$metadata4;
|
|
151
|
-
bulkResult.error.push({
|
|
152
|
-
name: resource === null || resource === void 0 ? void 0 : (_resource$spec13 = resource.spec) === null || _resource$spec13 === void 0 ? void 0 : (_resource$spec13$apiS = _resource$spec13.apiService) === null || _resource$spec13$apiS === void 0 ? void 0 : _resource$spec13$apiS.name,
|
|
153
|
-
kind: resource.kind,
|
|
154
|
-
error: new Error('Unable to find API Service with name: ' + (resource === null || resource === void 0 ? void 0 : (_resource$spec14 = resource.spec) === null || _resource$spec14 === void 0 ? void 0 : (_resource$spec14$apiS = _resource$spec14.apiService) === null || _resource$spec14$apiS === void 0 ? void 0 : _resource$spec14$apiS.name) + ' in Environment scope: ' + ((_resource$metadata4 = resource.metadata) === null || _resource$metadata4 === void 0 ? void 0 : _resource$metadata4.scope.name))
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
bulkResultMap.set((_resource$spec15 = resource.spec) === null || _resource$spec15 === void 0 ? void 0 : (_resource$spec15$apiS = _resource$spec15.apiService) === null || _resource$spec15$apiS === void 0 ? void 0 : _resource$spec15$apiS.name, bulkResult);
|
|
158
|
-
}
|
|
159
|
-
return bulkResultMap;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Create asset resources needed for productizing API services.
|
|
164
|
-
* @param apiService the apiService resource that needs to be productized
|
|
165
|
-
* @param sortedDefsMap sorted resource definition map
|
|
166
|
-
* @param apiServiceInstances api service instances referenced by the api service
|
|
167
|
-
* @param transferOwnership transfer ownership from api service to asset
|
|
168
|
-
*/
|
|
169
|
-
async createAssetResourcesForAPIServiceProductization(apiService, sortedDefsMap, apiServiceInstances, transferOwnership) {
|
|
170
|
-
var _apiService$owner, _apiService$spec, _apiService$spec$icon, _assetResponse$warnin;
|
|
171
|
-
let bulkResult = {
|
|
172
|
-
success: [],
|
|
173
|
-
error: [],
|
|
174
|
-
warning: []
|
|
175
|
-
};
|
|
176
|
-
let resources = [];
|
|
177
|
-
const resourceName = apiService.name;
|
|
178
|
-
const sortedDefsArray = Array.from(sortedDefsMap.values());
|
|
179
|
-
// 1. Asset.
|
|
180
|
-
const assetResourceDef = await (0, _utils.getResourceDefinition)(sortedDefsArray, _types.Kind.Asset);
|
|
181
|
-
let assetResource = (0, _utils.buildGenericResource)({
|
|
182
|
-
resourceDef: assetResourceDef
|
|
183
|
-
});
|
|
184
|
-
// carry over the title of API Service to the asset title
|
|
185
|
-
assetResource.title = apiService === null || apiService === void 0 ? void 0 : apiService.title;
|
|
186
|
-
// transfer the ownership from api service if asked to
|
|
187
|
-
if (transferOwnership && apiService !== null && apiService !== void 0 && apiService.owner) assetResource.owner = {
|
|
188
|
-
type: 'team',
|
|
189
|
-
id: apiService === null || apiService === void 0 ? void 0 : (_apiService$owner = apiService.owner) === null || _apiService$owner === void 0 ? void 0 : _apiService$owner.id
|
|
190
|
-
};
|
|
191
|
-
// 1.1 set autorelease
|
|
192
|
-
assetResource.spec = {
|
|
193
|
-
type: 'API',
|
|
194
|
-
autoRelease: {
|
|
195
|
-
releaseType: 'patch',
|
|
196
|
-
requiresInitialActivation: true
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
// 1.2 add asset icon, if one exists
|
|
200
|
-
if (apiService !== null && apiService !== void 0 && (_apiService$spec = apiService.spec) !== null && _apiService$spec !== void 0 && (_apiService$spec$icon = _apiService$spec.icon) !== null && _apiService$spec$icon !== void 0 && _apiService$spec$icon.data) {
|
|
201
|
-
var _apiService$spec2, _apiService$spec2$ico;
|
|
202
|
-
assetResource.icon = `data:image/png;base64,${apiService === null || apiService === void 0 ? void 0 : (_apiService$spec2 = apiService.spec) === null || _apiService$spec2 === void 0 ? void 0 : (_apiService$spec2$ico = _apiService$spec2.icon) === null || _apiService$spec2$ico === void 0 ? void 0 : _apiService$spec2$ico.data}`;
|
|
203
|
-
}
|
|
204
|
-
// 1.3 add asset access approval
|
|
205
|
-
assetResource.access = {
|
|
206
|
-
approval: 'automatic'
|
|
207
|
-
};
|
|
208
|
-
let assetResources = [];
|
|
209
|
-
assetResources.push(assetResource);
|
|
210
|
-
const assetResponse = await this.apiServerClient.bulkCreate(assetResources, sortedDefsMap, true);
|
|
211
|
-
if (assetResponse && assetResponse.warning && ((_assetResponse$warnin = assetResponse.warning) === null || _assetResponse$warnin === void 0 ? void 0 : _assetResponse$warnin.length) > 0 && assetResponse.error.length === 0) {
|
|
212
|
-
var _bulkResult$warning3, _assetResponse$warnin2, _assetResponse$warnin3;
|
|
213
|
-
(_bulkResult$warning3 = bulkResult.warning) === null || _bulkResult$warning3 === void 0 ? void 0 : _bulkResult$warning3.push(...assetResponse.warning);
|
|
214
|
-
const assetName = (_assetResponse$warnin2 = assetResponse.warning) === null || _assetResponse$warnin2 === void 0 ? void 0 : (_assetResponse$warnin3 = _assetResponse$warnin2.find(res => res.kind === _types.Kind.Asset)) === null || _assetResponse$warnin3 === void 0 ? void 0 : _assetResponse$warnin3.name;
|
|
215
|
-
// 1.4 Asset Mapping
|
|
216
|
-
const assetMappingResourceDef = await (0, _utils.getResourceDefinition)(sortedDefsArray, _types.Kind.AssetMapping, _types.Kind.Asset);
|
|
217
|
-
let assetMappingResource = (0, _utils.buildGenericResource)({
|
|
218
|
-
resourceDef: assetMappingResourceDef,
|
|
219
|
-
scopeName: assetName
|
|
220
|
-
});
|
|
221
|
-
// 1.5 set inputs
|
|
222
|
-
apiServiceInstances.data.forEach(instance => {
|
|
223
|
-
var _apiService$metadata, _apiService$metadata$, _instance$metadata;
|
|
224
|
-
assetMappingResource.spec = {
|
|
225
|
-
inputs: {
|
|
226
|
-
apiService: `management/${(_apiService$metadata = apiService.metadata) === null || _apiService$metadata === void 0 ? void 0 : (_apiService$metadata$ = _apiService$metadata.scope) === null || _apiService$metadata$ === void 0 ? void 0 : _apiService$metadata$.name}/${resourceName}`,
|
|
227
|
-
apiServiceInstance: `management/${(_instance$metadata = instance.metadata) === null || _instance$metadata === void 0 ? void 0 : _instance$metadata.scope.name}/${instance.name}`
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
});
|
|
231
|
-
resources.push(assetMappingResource);
|
|
232
|
-
// 1.6 Asset Release Tag
|
|
233
|
-
const assetReleaseResourceDef = await (0, _utils.getResourceDefinition)(sortedDefsArray, _types.Kind.ReleaseTag, _types.Kind.Asset);
|
|
234
|
-
let assetReleaseResource = (0, _utils.buildGenericResource)({
|
|
235
|
-
resourceDef: assetReleaseResourceDef,
|
|
236
|
-
scopeName: assetName
|
|
237
|
-
});
|
|
238
|
-
assetReleaseResource.spec = {
|
|
239
|
-
releaseType: 'major'
|
|
240
|
-
};
|
|
241
|
-
resources.push(assetReleaseResource);
|
|
242
|
-
let assetResourcesResult = await this.apiServerClient.bulkCreate(resources, sortedDefsMap, true);
|
|
243
|
-
if (assetResourcesResult && assetResourcesResult.warning && assetResourcesResult.warning.length > 0 && assetResourcesResult.error.length === 0) {
|
|
244
|
-
var _bulkResult$warning4;
|
|
245
|
-
(_bulkResult$warning4 = bulkResult.warning) === null || _bulkResult$warning4 === void 0 ? void 0 : _bulkResult$warning4.push(...assetResourcesResult.warning);
|
|
246
|
-
} else {
|
|
247
|
-
bulkResult.error.push(...assetResourcesResult.error);
|
|
248
|
-
}
|
|
249
|
-
} else {
|
|
250
|
-
bulkResult.error.push(...assetResponse.error);
|
|
251
|
-
}
|
|
252
|
-
return bulkResult;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Create product resources needed for productizing API services.
|
|
257
|
-
* @param apiService the apiService resource that needs to be productized
|
|
258
|
-
* @param sortedDefsMap sorted resource definition map
|
|
259
|
-
* @param transferOwnership transfer ownership from api service to product
|
|
260
|
-
*/
|
|
261
|
-
async createProductResourcesForAPIServiceProductization(apiService, sortedDefsMap, transferOwnership, assetName) {
|
|
262
|
-
var _apiService$owner2, _apiService$spec3, _apiService$spec3$ico;
|
|
263
|
-
let bulkResult = {
|
|
264
|
-
success: [],
|
|
265
|
-
error: [],
|
|
266
|
-
warning: []
|
|
267
|
-
};
|
|
268
|
-
const sortedDefsArray = Array.from(sortedDefsMap.values());
|
|
269
|
-
// 1. Product
|
|
270
|
-
const productResourceDef = await (0, _utils.getResourceDefinition)(sortedDefsArray, _types.Kind.Product);
|
|
271
|
-
let productResource = (0, _utils.buildGenericResource)({
|
|
272
|
-
resourceDef: productResourceDef
|
|
273
|
-
});
|
|
274
|
-
// carry over the title of API Service to the product title
|
|
275
|
-
productResource.title = apiService === null || apiService === void 0 ? void 0 : apiService.title;
|
|
276
|
-
productResource.spec = {
|
|
277
|
-
autoRelease: {
|
|
278
|
-
releaseType: 'patch',
|
|
279
|
-
requiresInitialActivation: true
|
|
280
|
-
},
|
|
281
|
-
assets: [{
|
|
282
|
-
name: assetName
|
|
283
|
-
}]
|
|
284
|
-
};
|
|
285
|
-
// transfer the ownership from api service if asked to
|
|
286
|
-
if (transferOwnership && apiService !== null && apiService !== void 0 && apiService.owner) productResource.owner = {
|
|
287
|
-
type: 'team',
|
|
288
|
-
id: apiService === null || apiService === void 0 ? void 0 : (_apiService$owner2 = apiService.owner) === null || _apiService$owner2 === void 0 ? void 0 : _apiService$owner2.id
|
|
289
|
-
};
|
|
290
|
-
// 1.1 add product icon, if one exists
|
|
291
|
-
if (apiService !== null && apiService !== void 0 && (_apiService$spec3 = apiService.spec) !== null && _apiService$spec3 !== void 0 && (_apiService$spec3$ico = _apiService$spec3.icon) !== null && _apiService$spec3$ico !== void 0 && _apiService$spec3$ico.data) {
|
|
292
|
-
var _apiService$spec4, _apiService$spec4$ico;
|
|
293
|
-
productResource.icon = `data:image/png;base64,${apiService === null || apiService === void 0 ? void 0 : (_apiService$spec4 = apiService.spec) === null || _apiService$spec4 === void 0 ? void 0 : (_apiService$spec4$ico = _apiService$spec4.icon) === null || _apiService$spec4$ico === void 0 ? void 0 : _apiService$spec4$ico.data}`;
|
|
294
|
-
}
|
|
295
|
-
let productResources = [];
|
|
296
|
-
productResources.push(productResource);
|
|
297
|
-
let productResponse = await this.apiServerClient.bulkCreate(productResources, sortedDefsMap, true);
|
|
298
|
-
if (productResponse && productResponse.warning && productResponse.warning.length > 0 && productResponse.error.length === 0) {
|
|
299
|
-
var _productResponse$warn, _productResponse$warn2, _bulkResult$warning5;
|
|
300
|
-
const productName = (_productResponse$warn = productResponse.warning) === null || _productResponse$warn === void 0 ? void 0 : (_productResponse$warn2 = _productResponse$warn.find(res => res.kind === _types.Kind.Product)) === null || _productResponse$warn2 === void 0 ? void 0 : _productResponse$warn2.name;
|
|
301
|
-
(_bulkResult$warning5 = bulkResult.warning) === null || _bulkResult$warning5 === void 0 ? void 0 : _bulkResult$warning5.push(...productResponse.warning);
|
|
302
|
-
// 1.2 Product Release Tag
|
|
303
|
-
const productReleaseResourceDef = await (0, _utils.getResourceDefinition)(sortedDefsArray, _types.Kind.ReleaseTag, _types.Kind.Product);
|
|
304
|
-
let productReleaseResource = (0, _utils.buildGenericResource)({
|
|
305
|
-
resourceDef: productReleaseResourceDef,
|
|
306
|
-
scopeName: productName
|
|
307
|
-
});
|
|
308
|
-
productReleaseResource.spec = {
|
|
309
|
-
releaseType: 'major'
|
|
310
|
-
};
|
|
311
|
-
let productResources = [];
|
|
312
|
-
productResources.push(productReleaseResource);
|
|
313
|
-
let productReleaseResult = await this.apiServerClient.bulkCreate(productResources, sortedDefsMap, true);
|
|
314
|
-
if (productReleaseResult && productReleaseResult.warning && productReleaseResult.warning.length > 0 && productReleaseResult.error.length === 0) {
|
|
315
|
-
var _bulkResult$warning6;
|
|
316
|
-
(_bulkResult$warning6 = bulkResult.warning) === null || _bulkResult$warning6 === void 0 ? void 0 : _bulkResult$warning6.push(...productReleaseResult.warning);
|
|
317
|
-
} else {
|
|
318
|
-
bulkResult.error.push(...productReleaseResult.error);
|
|
319
|
-
}
|
|
320
|
-
} else {
|
|
321
|
-
bulkResult.error.push(...productResponse.error);
|
|
322
|
-
}
|
|
323
|
-
return bulkResult;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* Verify if an asset state has been set to active
|
|
328
|
-
* @param assetResourceDef asset resource definition
|
|
329
|
-
* @param assetName name of the asset
|
|
330
|
-
*/
|
|
331
|
-
async waitForAssetActivation(assetResourceDef, assetName) {
|
|
332
|
-
const endTime = new Date();
|
|
333
|
-
endTime.setTime(endTime.getTime() + 5000);
|
|
334
|
-
const query = `name==${assetName};state==active`;
|
|
335
|
-
while (endTime > new Date()) {
|
|
336
|
-
var _parseInt;
|
|
337
|
-
const response = await this.apiServerClient.getResourceCount({
|
|
338
|
-
resourceDef: assetResourceDef,
|
|
339
|
-
query: query
|
|
340
|
-
});
|
|
341
|
-
if (((_parseInt = parseInt(response)) !== null && _parseInt !== void 0 ? _parseInt : 0) > 0) {
|
|
342
|
-
return true;
|
|
343
|
-
}
|
|
344
|
-
await new Promise(resolve => setTimeout(resolve, 500));
|
|
345
|
-
}
|
|
346
|
-
return false;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* Verify if an asset release tag has been created
|
|
351
|
-
* @param sortedDefsArray array of sorted defs
|
|
352
|
-
* @param releaseTag name of the asset release tag
|
|
353
|
-
* @param assetName name of the asset where the release tag is scoped under
|
|
354
|
-
* @param totalAttempts max number of attempts to successfully verify
|
|
355
|
-
* @param delay time in ms to wait to restart a new attempt
|
|
356
|
-
* @param retried number of retries to make
|
|
357
|
-
*/
|
|
358
|
-
async checkForAssetReleaseTag(sortedDefsArray, releaseTag, assetName, totalAttempts = 8, delay = 100, retries = 0) {
|
|
359
|
-
var _assetReleaseTag$data;
|
|
360
|
-
const assetReleaseResourceDef = await (0, _utils.getResourceDefinition)(sortedDefsArray, _types.Kind.ReleaseTag, _types.Kind.Asset);
|
|
361
|
-
const assetResourceDef = await (0, _utils.getResourceDefinition)(sortedDefsArray, _types.Kind.Asset);
|
|
362
|
-
await (0, _utils.wait)(delay);
|
|
363
|
-
let assetReleaseTag = await this.apiServerClient.getResourceByName({
|
|
364
|
-
resourceDef: assetReleaseResourceDef,
|
|
365
|
-
resourceName: releaseTag,
|
|
366
|
-
scopeDef: assetResourceDef,
|
|
367
|
-
scopeName: assetName
|
|
368
|
-
});
|
|
369
|
-
if (assetReleaseTag && assetReleaseTag.data && !assetReleaseTag.error && ((_assetReleaseTag$data = assetReleaseTag.data.status) === null || _assetReleaseTag$data === void 0 ? void 0 : _assetReleaseTag$data.level) === 'Success') {
|
|
370
|
-
return true;
|
|
371
|
-
} else if (retries < totalAttempts) {
|
|
372
|
-
// Try again after delay.
|
|
373
|
-
return await this.checkForAssetReleaseTag(sortedDefsArray, releaseTag, assetName, totalAttempts, 2 ** retries * 100, retries + 1);
|
|
374
|
-
} else {
|
|
375
|
-
// Ran out of attempts
|
|
376
|
-
return false;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* Cleanup Asset/Product resources on Productization Failures
|
|
382
|
-
* @param resource the asset/product to be cleaned up
|
|
383
|
-
* @param resourceDef corresponding resource definition
|
|
384
|
-
*/
|
|
385
|
-
async cleanupResourcesOnFailure(resource, resourceDef) {
|
|
386
|
-
// update the state of asset/product before deleting it and all the resources scoped under it
|
|
387
|
-
resource.state = 'archived';
|
|
388
|
-
const version = resource.apiVersion === undefined ? (0, _utils.getLatestServedAPIVersion)(resourceDef) : resource.apiVersion;
|
|
389
|
-
const subResourceReq = await this.apiServerClient.generateSubResourcesRequests({
|
|
390
|
-
resource: resource,
|
|
391
|
-
resourceName: resource.name,
|
|
392
|
-
resourceDef: resourceDef,
|
|
393
|
-
subResourceName: 'state',
|
|
394
|
-
version: version
|
|
395
|
-
});
|
|
396
|
-
const subResourceResult = await this.apiServerClient.resolveSubResourcesRequests(resource, subResourceReq);
|
|
397
|
-
if (subResourceResult.data && !subResourceResult.error) {
|
|
398
|
-
// delete the asset/product and all resources scoped under it if any
|
|
399
|
-
await this.apiServerClient.deleteResourceByName({
|
|
400
|
-
resourceDef: resourceDef,
|
|
401
|
-
resourceName: resource.name,
|
|
402
|
-
wait: true,
|
|
403
|
-
forceDelete: true
|
|
404
|
-
});
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
exports.ProductizationHelper = ProductizationHelper;
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.productize = void 0;
|
|
7
|
-
var _snooplogg = _interopRequireDefault(require("snooplogg"));
|
|
8
|
-
var _amplifyCliUtils = require("@axway/amplify-cli-utils");
|
|
9
|
-
var _ApiServerClient = require("../../common/ApiServerClient");
|
|
10
|
-
var _DefinitionsManager = require("../../common/DefinitionsManager");
|
|
11
|
-
var _Renderer = _interopRequireDefault(require("../../common/Renderer"));
|
|
12
|
-
var _types = require("../../common/types");
|
|
13
|
-
var _productizationHelper = require("../productize/helpers/productizationHelper");
|
|
14
|
-
var _utils = require("../../common/utils");
|
|
15
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
-
const {
|
|
17
|
-
log
|
|
18
|
-
} = (0, _snooplogg.default)('central: productize');
|
|
19
|
-
const action = async ({
|
|
20
|
-
argv,
|
|
21
|
-
console
|
|
22
|
-
}) => {
|
|
23
|
-
var _account;
|
|
24
|
-
const {
|
|
25
|
-
baseUrl,
|
|
26
|
-
file,
|
|
27
|
-
region,
|
|
28
|
-
cache,
|
|
29
|
-
transferOwnership
|
|
30
|
-
} = argv;
|
|
31
|
-
let commandIsSuccessful = true;
|
|
32
|
-
log(`verifying args`);
|
|
33
|
-
if (!file) throw new Error('To create resources from a file, please provide -f, --file [path] option');
|
|
34
|
-
log(`verifying file: ${file}`);
|
|
35
|
-
(0, _utils.verifyFile)(file);
|
|
36
|
-
const render = new _Renderer.default(console).startSpin('Productizing API Service(s)');
|
|
37
|
-
const config = (0, _amplifyCliUtils.loadConfig)();
|
|
38
|
-
const environment = !baseUrl || baseUrl === _types.ProdBaseUrls.US || baseUrl === _types.ProdBaseUrls.EU || baseUrl === _types.ProdBaseUrls.AP ? config.get('env') : 'staging';
|
|
39
|
-
const {
|
|
40
|
-
sdk
|
|
41
|
-
} = (0, _amplifyCliUtils.initSDK)({
|
|
42
|
-
env: environment
|
|
43
|
-
}, config);
|
|
44
|
-
const list = await sdk.auth.list({
|
|
45
|
-
validate: true
|
|
46
|
-
});
|
|
47
|
-
let account = undefined;
|
|
48
|
-
if (list.length === 1) {
|
|
49
|
-
account = list[0];
|
|
50
|
-
} else if (list.length > 1) {
|
|
51
|
-
// try to find the default account
|
|
52
|
-
account = list.find(a => a.name === config.get('auth.defaultAccount')) || list.find(a => a.default) || list[0];
|
|
53
|
-
}
|
|
54
|
-
const client = new _ApiServerClient.ApiServerClient({
|
|
55
|
-
baseUrl,
|
|
56
|
-
account: (_account = account) === null || _account === void 0 ? void 0 : _account.name,
|
|
57
|
-
region,
|
|
58
|
-
useCache: cache,
|
|
59
|
-
forceGetAuthInfo: true
|
|
60
|
-
});
|
|
61
|
-
const defsManager = new _DefinitionsManager.DefinitionsManager(client);
|
|
62
|
-
let results = new Map();
|
|
63
|
-
log(`executing api calls`);
|
|
64
|
-
try {
|
|
65
|
-
await defsManager.init();
|
|
66
|
-
log(`loading and verifying specs`);
|
|
67
|
-
const allowedKind = new Set().add(_types.Kind.APIService);
|
|
68
|
-
const {
|
|
69
|
-
docs
|
|
70
|
-
} = await (0, _utils.loadAndVerifySpecs)(file, allowedKind, true);
|
|
71
|
-
render.startSpin('Productizing API Service(s)\n');
|
|
72
|
-
const sortedKindsMap = defsManager.getSortedKindsMap();
|
|
73
|
-
const helper = new _productizationHelper.ProductizationHelper(client);
|
|
74
|
-
results = await helper.bulkProductizeAPIServices(docs, sortedKindsMap, transferOwnership);
|
|
75
|
-
render.stopSpin();
|
|
76
|
-
render.productizationResult(results);
|
|
77
|
-
results.forEach(value => {
|
|
78
|
-
if (value.error.length > 0) commandIsSuccessful = false;
|
|
79
|
-
});
|
|
80
|
-
} catch (e) {
|
|
81
|
-
log('command error', e);
|
|
82
|
-
render.anyError(e);
|
|
83
|
-
} finally {
|
|
84
|
-
log(`command finished, success = ${commandIsSuccessful}`);
|
|
85
|
-
!commandIsSuccessful && process.exit(1);
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
const productize = exports.productize = {
|
|
89
|
-
action,
|
|
90
|
-
desc: 'Productize one or more API Services from a file',
|
|
91
|
-
options: {
|
|
92
|
-
..._types.commonCmdArgsDescription,
|
|
93
|
-
'-f, --file [path]': {
|
|
94
|
-
desc: `Filename to use to create the resource`,
|
|
95
|
-
type: 'string'
|
|
96
|
-
},
|
|
97
|
-
'--transferOwnership': `Transfers the ownership(if exisiting) of API Service(s) to corresponding Asset(s) and Product(s)`
|
|
98
|
-
}
|
|
99
|
-
};
|