@adobe/aio-cli-plugin-api-mesh 1.5.0 → 2.0.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/README.md +4 -3
- package/oclif.manifest.json +1 -1
- package/package.json +15 -15
- package/src/commands/api-mesh/__tests__/create.test.js +121 -139
- package/src/commands/api-mesh/__tests__/delete.test.js +40 -40
- package/src/commands/api-mesh/__tests__/describe.test.js +30 -40
- package/src/commands/api-mesh/__tests__/get.test.js +60 -69
- package/src/commands/api-mesh/__tests__/update.test.js +71 -35
- package/src/commands/api-mesh/create.js +17 -6
- package/src/commands/api-mesh/describe.js +1 -1
- package/src/commands/api-mesh/get.js +1 -1
- package/src/commands/api-mesh/source/__fixtures__/0.0.1-test-01.json +1 -1
- package/src/commands/api-mesh/source/__fixtures__/0.0.1-test-02.json +1 -1
- package/src/commands/api-mesh/source/__tests__/discover.test.js +2 -2
- package/src/commands/api-mesh/source/__tests__/get.test.js +19 -16
- package/src/commands/api-mesh/source/__tests__/install.test.js +14 -14
- package/src/commands/api-mesh/source/discover.js +24 -18
- package/src/commands/api-mesh/source/get.js +15 -11
- package/src/commands/api-mesh/source/install.js +49 -41
- package/src/commands/api-mesh/status.js +96 -0
- package/src/commands/api-mesh/update.js +12 -1
- package/src/constants.js +2 -0
- package/src/helpers.js +16 -10
- package/src/utils.js +2 -4
|
@@ -45,7 +45,7 @@ class InstallCommand extends Command {
|
|
|
45
45
|
return obj;
|
|
46
46
|
}, {})
|
|
47
47
|
: {};
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
if (filepath) {
|
|
50
50
|
try {
|
|
51
51
|
variables = { ...variables, ...JSON.parse(await readFile(filepath, 'utf8')) };
|
|
@@ -68,7 +68,7 @@ class InstallCommand extends Command {
|
|
|
68
68
|
this.error(`Cannot get the list of sources: ${err}. RequestId: ${global.requestId}`);
|
|
69
69
|
}
|
|
70
70
|
const sources = flags.source ? flags.source : [args.source];
|
|
71
|
-
const sourceConfigs = {sources: [], files: {}};
|
|
71
|
+
const sourceConfigs = { sources: [], files: {} };
|
|
72
72
|
for (const source of sources) {
|
|
73
73
|
let [name, version] = source.split('@');
|
|
74
74
|
const normalizedName = this.normalizeName(name);
|
|
@@ -94,8 +94,13 @@ class InstallCommand extends Command {
|
|
|
94
94
|
const sourceProviderString = JSON.stringify(sourceConfig.provider);
|
|
95
95
|
const sourceVariables = jsonInterpolate.getJsonVariables(sourceProviderString);
|
|
96
96
|
const passedSourceVariables = this.getPassedSourceVariables(sourceVariables || [], variables);
|
|
97
|
-
const missedVariables = jsonInterpolate.getMissedVariables(
|
|
98
|
-
|
|
97
|
+
const missedVariables = jsonInterpolate.getMissedVariables(
|
|
98
|
+
passedSourceVariables,
|
|
99
|
+
sourceVariables,
|
|
100
|
+
);
|
|
101
|
+
for (const missedVariable of missedVariables
|
|
102
|
+
.map(item => item.name)
|
|
103
|
+
.filter((value, index, self) => self.indexOf(value) === index)) {
|
|
99
104
|
passedSourceVariables[missedVariable] = await promptInput(
|
|
100
105
|
`Enter the value for variable ${missedVariable}:`,
|
|
101
106
|
);
|
|
@@ -103,12 +108,12 @@ class InstallCommand extends Command {
|
|
|
103
108
|
|
|
104
109
|
const { error, data } = jsonInterpolate.interpolate(
|
|
105
110
|
JSON.stringify(sourceConfig.provider),
|
|
106
|
-
passedSourceVariables,
|
|
111
|
+
passedSourceVariables,
|
|
107
112
|
);
|
|
108
113
|
if (error) {
|
|
109
114
|
this.error(chalk.red(`${error.message}\n${error.list.map(err => err.message).join('\n')}`));
|
|
110
115
|
}
|
|
111
|
-
|
|
116
|
+
|
|
112
117
|
sourceConfigs.sources.push(JSON.parse(data));
|
|
113
118
|
sourceConfigs.files[sourceConfig.provider.name] = sourceConfig.files;
|
|
114
119
|
}
|
|
@@ -139,56 +144,58 @@ class InstallCommand extends Command {
|
|
|
139
144
|
const verifiedSources = this.verifySourceAlreadyExists(
|
|
140
145
|
mesh.meshConfig.sources,
|
|
141
146
|
sourceConfigs.sources,
|
|
142
|
-
);
|
|
147
|
+
);
|
|
143
148
|
|
|
144
149
|
let override = false;
|
|
145
150
|
if (verifiedSources.installed.length) {
|
|
146
|
-
override = flags.confirm
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
151
|
+
override = flags.confirm
|
|
152
|
+
? true
|
|
153
|
+
: await promptConfirm(
|
|
154
|
+
`The following sources are already installed: ${verifiedSources.installed
|
|
155
|
+
.map(source => source.name)
|
|
156
|
+
.join(', ')}.
|
|
150
157
|
Do you want to override?`,
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const uniqueFiles = this.getSourceFiles(
|
|
155
|
-
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const uniqueFiles = this.getSourceFiles(
|
|
162
|
+
verifiedSources.unique.map(source => source.name),
|
|
163
|
+
sourceConfigs.files,
|
|
164
|
+
);
|
|
165
|
+
const installedFiles = this.getSourceFiles(
|
|
166
|
+
verifiedSources.installed.map(source => source.name),
|
|
167
|
+
sourceConfigs.files,
|
|
168
|
+
);
|
|
156
169
|
let meshConfigFiles = mesh.meshConfig.files || [];
|
|
157
170
|
|
|
158
171
|
if (override) {
|
|
159
172
|
const installedMap = verifiedSources.installed.reduce((obj, source) => {
|
|
160
173
|
obj[source.name] = true;
|
|
161
|
-
return obj
|
|
174
|
+
return obj;
|
|
162
175
|
}, {});
|
|
163
|
-
|
|
176
|
+
|
|
164
177
|
mesh.meshConfig.sources = [
|
|
165
178
|
...mesh.meshConfig.sources.filter(source => !installedMap[source.name]),
|
|
166
|
-
...verifiedSources.installed
|
|
179
|
+
...verifiedSources.installed,
|
|
167
180
|
];
|
|
168
181
|
|
|
169
182
|
const installedFilesMap = installedFiles.reduce((obj, file) => {
|
|
170
183
|
obj[file.path] = true;
|
|
171
|
-
return obj
|
|
184
|
+
return obj;
|
|
172
185
|
}, {});
|
|
173
186
|
|
|
174
187
|
meshConfigFiles = [
|
|
175
188
|
...meshConfigFiles.filter(file => !installedFilesMap[file.path]),
|
|
176
|
-
...installedFiles
|
|
189
|
+
...installedFiles,
|
|
177
190
|
];
|
|
178
191
|
}
|
|
179
192
|
|
|
180
|
-
mesh.meshConfig.sources = [
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
meshConfigFiles = [
|
|
186
|
-
...meshConfigFiles,
|
|
187
|
-
...uniqueFiles
|
|
188
|
-
]
|
|
189
|
-
|
|
193
|
+
mesh.meshConfig.sources = [...mesh.meshConfig.sources, ...verifiedSources.unique];
|
|
194
|
+
|
|
195
|
+
meshConfigFiles = [...meshConfigFiles, ...uniqueFiles];
|
|
196
|
+
|
|
190
197
|
if (meshConfigFiles.length) {
|
|
191
|
-
mesh.meshConfig.files = meshConfigFiles
|
|
198
|
+
mesh.meshConfig.files = meshConfigFiles;
|
|
192
199
|
}
|
|
193
200
|
|
|
194
201
|
try {
|
|
@@ -224,17 +231,17 @@ class InstallCommand extends Command {
|
|
|
224
231
|
let result = [];
|
|
225
232
|
for (const source of sourcesList) {
|
|
226
233
|
if (Array.isArray(filesList[source])) {
|
|
227
|
-
result = [...result, ...filesList[source]]
|
|
234
|
+
result = [...result, ...filesList[source]];
|
|
228
235
|
}
|
|
229
236
|
}
|
|
230
237
|
return result;
|
|
231
238
|
}
|
|
232
239
|
|
|
233
240
|
getPassedSourceVariables(variablesInSource, passedVariables) {
|
|
234
|
-
const res = {}
|
|
241
|
+
const res = {};
|
|
235
242
|
variablesInSource.forEach(variable => {
|
|
236
243
|
if (passedVariables[variable.name]) {
|
|
237
|
-
res[variable.name] = passedVariables[variable.name]
|
|
244
|
+
res[variable.name] = passedVariables[variable.name];
|
|
238
245
|
}
|
|
239
246
|
});
|
|
240
247
|
return res;
|
|
@@ -259,17 +266,18 @@ class InstallCommand extends Command {
|
|
|
259
266
|
}
|
|
260
267
|
|
|
261
268
|
InstallCommand.flags = {
|
|
262
|
-
source: Flags.string({
|
|
269
|
+
'source': Flags.string({
|
|
263
270
|
char: 's',
|
|
264
271
|
description: 'Source name',
|
|
265
|
-
multiple: true,
|
|
272
|
+
multiple: true,
|
|
266
273
|
}),
|
|
267
|
-
confirm: Flags.boolean({
|
|
274
|
+
'confirm': Flags.boolean({
|
|
268
275
|
char: 'c',
|
|
269
|
-
description:
|
|
276
|
+
description:
|
|
277
|
+
'Auto confirm override action prompt. CLI will not check ask user to override source.',
|
|
270
278
|
default: false,
|
|
271
279
|
}),
|
|
272
|
-
variable: Flags.string({
|
|
280
|
+
'variable': Flags.string({
|
|
273
281
|
char: 'v',
|
|
274
282
|
description: 'Variables required for the source',
|
|
275
283
|
multiple: true,
|
|
@@ -278,7 +286,7 @@ InstallCommand.flags = {
|
|
|
278
286
|
char: 'f',
|
|
279
287
|
description: 'Variables file path',
|
|
280
288
|
}),
|
|
281
|
-
ignoreCache: ignoreCacheFlag,
|
|
289
|
+
'ignoreCache': ignoreCacheFlag,
|
|
282
290
|
};
|
|
283
291
|
|
|
284
292
|
InstallCommand.description = 'Command to install the source to your API mesh.';
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const { Command } = require('@oclif/core');
|
|
2
|
+
const logger = require('../../classes/logger');
|
|
3
|
+
const { initRequestId, initSdk } = require('../../helpers');
|
|
4
|
+
const { getMeshId, getMesh } = require('../../lib/devConsole');
|
|
5
|
+
const { ignoreCacheFlag } = require('../../utils');
|
|
6
|
+
|
|
7
|
+
require('dotenv').config();
|
|
8
|
+
|
|
9
|
+
class StatusCommand extends Command {
|
|
10
|
+
static flags = {
|
|
11
|
+
ignoreCache: ignoreCacheFlag,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
async run() {
|
|
15
|
+
await initRequestId();
|
|
16
|
+
logger.info(`RequestId: ${global.requestId}`);
|
|
17
|
+
|
|
18
|
+
const { flags } = await this.parse(StatusCommand);
|
|
19
|
+
const ignoreCache = await flags.ignoreCache;
|
|
20
|
+
|
|
21
|
+
const { imsOrgId, projectId, workspaceId } = await initSdk({
|
|
22
|
+
ignoreCache,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
let meshId = null;
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
meshId = await getMeshId(imsOrgId, projectId, workspaceId);
|
|
29
|
+
} catch (err) {
|
|
30
|
+
this.log(err.message);
|
|
31
|
+
this.error(
|
|
32
|
+
`Unable to get mesh ID. Please check the details and try again. RequestId: ${global.requestId}`,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (meshId) {
|
|
37
|
+
try {
|
|
38
|
+
const mesh = await getMesh(imsOrgId, projectId, workspaceId, meshId);
|
|
39
|
+
switch (mesh.meshStatus) {
|
|
40
|
+
case 'success':
|
|
41
|
+
this.log(
|
|
42
|
+
'******************************************************************************************************',
|
|
43
|
+
);
|
|
44
|
+
this.log('Your mesh has been successfully built.');
|
|
45
|
+
this.log(
|
|
46
|
+
'******************************************************************************************************',
|
|
47
|
+
);
|
|
48
|
+
break;
|
|
49
|
+
case 'pending':
|
|
50
|
+
this.log(
|
|
51
|
+
'******************************************************************************************************',
|
|
52
|
+
);
|
|
53
|
+
this.log('Your mesh is awaiting processing.');
|
|
54
|
+
this.log(
|
|
55
|
+
'******************************************************************************************************',
|
|
56
|
+
);
|
|
57
|
+
break;
|
|
58
|
+
case 'building':
|
|
59
|
+
this.log(
|
|
60
|
+
'******************************************************************************************************',
|
|
61
|
+
);
|
|
62
|
+
this.log(
|
|
63
|
+
'Your mesh is currently being provisioned. Please wait a few minutes before checking again.',
|
|
64
|
+
);
|
|
65
|
+
this.log(
|
|
66
|
+
'******************************************************************************************************',
|
|
67
|
+
);
|
|
68
|
+
break;
|
|
69
|
+
case 'error':
|
|
70
|
+
this.log(
|
|
71
|
+
'******************************************************************************************************',
|
|
72
|
+
);
|
|
73
|
+
this.log('Your mesh errored out with the following error. ', mesh.error);
|
|
74
|
+
this.log(
|
|
75
|
+
'******************************************************************************************************',
|
|
76
|
+
);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
} catch (err) {
|
|
80
|
+
this.log(err.message);
|
|
81
|
+
|
|
82
|
+
this.error(
|
|
83
|
+
`Unable to get the mesh status. If the error persists please contact support. RequestId: ${global.requestId}`,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
this.error(
|
|
88
|
+
`Unable to get mesh status. No mesh found for Org(${imsOrgId}) -> Project(${projectId}) -> Workspace(${workspaceId}). Please check the details and try again.`,
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
StatusCommand.description = 'Get a mesh status with a given meshid.';
|
|
95
|
+
|
|
96
|
+
module.exports = StatusCommand;
|
|
@@ -82,7 +82,18 @@ class UpdateCommand extends Command {
|
|
|
82
82
|
try {
|
|
83
83
|
const response = await updateMesh(imsOrgId, projectId, workspaceId, meshId, data);
|
|
84
84
|
|
|
85
|
-
this.log(
|
|
85
|
+
this.log(
|
|
86
|
+
'******************************************************************************************************',
|
|
87
|
+
);
|
|
88
|
+
this.log(
|
|
89
|
+
'Your mesh is being provisioned. Wait a few minutes before checking the status of your mesh %s',
|
|
90
|
+
meshId,
|
|
91
|
+
);
|
|
92
|
+
this.log('To check the status of your mesh, run:');
|
|
93
|
+
this.log('aio api-mesh:status');
|
|
94
|
+
this.log(
|
|
95
|
+
'******************************************************************************************************',
|
|
96
|
+
);
|
|
86
97
|
|
|
87
98
|
return response;
|
|
88
99
|
} catch (error) {
|
package/src/constants.js
CHANGED
|
@@ -8,6 +8,7 @@ const StageConstants = {
|
|
|
8
8
|
DEV_CONSOLE_API_KEY: 'adobe-api-manager-sms-stage',
|
|
9
9
|
DEV_CONSOLE_TRANSPORTER_API_KEY: 'UDPWeb1',
|
|
10
10
|
AIO_CLI_API_KEY: 'aio-cli-console-auth-stage',
|
|
11
|
+
SMS_BASE_URL: 'https://graph-stage.adobe.io/api-admin',
|
|
11
12
|
};
|
|
12
13
|
|
|
13
14
|
const ProdConstants = {
|
|
@@ -16,6 +17,7 @@ const ProdConstants = {
|
|
|
16
17
|
DEV_CONSOLE_API_KEY: 'adobe-graph-prod',
|
|
17
18
|
DEV_CONSOLE_TRANSPORTER_API_KEY: 'UDPWeb1',
|
|
18
19
|
AIO_CLI_API_KEY: 'aio-cli-console-auth',
|
|
20
|
+
SMS_BASE_URL: 'https://graph.adobe.io/api-admin',
|
|
19
21
|
};
|
|
20
22
|
|
|
21
23
|
module.exports = clientEnv === 'stage' ? StageConstants : ProdConstants;
|
package/src/helpers.js
CHANGED
|
@@ -26,6 +26,9 @@ const { objToString } = require('./utils');
|
|
|
26
26
|
|
|
27
27
|
const { DEV_CONSOLE_BASE_URL, DEV_CONSOLE_API_KEY, AIO_CLI_API_KEY } = CONSTANTS;
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* @param configFilePath
|
|
31
|
+
*/
|
|
29
32
|
async function getDevConsoleConfigFromFile(configFilePath) {
|
|
30
33
|
try {
|
|
31
34
|
if (!fs.existsSync(configFilePath)) {
|
|
@@ -47,7 +50,7 @@ async function getDevConsoleConfigFromFile(configFilePath) {
|
|
|
47
50
|
: data.baseUrl;
|
|
48
51
|
|
|
49
52
|
const config = {
|
|
50
|
-
baseUrl
|
|
53
|
+
baseUrl,
|
|
51
54
|
accessToken: (await getLibConsoleCLI()).accessToken,
|
|
52
55
|
apiKey: data.apiKey,
|
|
53
56
|
};
|
|
@@ -64,6 +67,9 @@ async function getDevConsoleConfigFromFile(configFilePath) {
|
|
|
64
67
|
}
|
|
65
68
|
}
|
|
66
69
|
|
|
70
|
+
/**
|
|
71
|
+
* @param configObject
|
|
72
|
+
*/
|
|
67
73
|
async function getDevConsoleConfigFromObject(configObject) {
|
|
68
74
|
const { baseUrl, apiKey } = configObject;
|
|
69
75
|
const config = {
|
|
@@ -325,15 +331,16 @@ async function getLibConsoleCLI() {
|
|
|
325
331
|
const accessToken = await getToken(CLI);
|
|
326
332
|
|
|
327
333
|
const consoleCLI = await libConsoleCLI.init({
|
|
328
|
-
accessToken
|
|
334
|
+
accessToken,
|
|
329
335
|
apiKey: AIO_CLI_API_KEY,
|
|
330
336
|
env: clientEnv,
|
|
331
337
|
});
|
|
332
338
|
|
|
333
|
-
return { consoleCLI
|
|
339
|
+
return { consoleCLI, accessToken };
|
|
334
340
|
}
|
|
335
341
|
|
|
336
342
|
/**
|
|
343
|
+
* @param options
|
|
337
344
|
* @returns {any} Returns an object with properties ready for consumption
|
|
338
345
|
*/
|
|
339
346
|
async function initSdk(options) {
|
|
@@ -377,7 +384,6 @@ async function initRequestId() {
|
|
|
377
384
|
* Function to run the CLI Y/N prompt to confirm the user's action
|
|
378
385
|
*
|
|
379
386
|
* @param {string} message
|
|
380
|
-
*
|
|
381
387
|
* @returns boolean
|
|
382
388
|
*/
|
|
383
389
|
async function promptConfirm(message) {
|
|
@@ -405,9 +411,9 @@ async function promptMultiselect(message, choices) {
|
|
|
405
411
|
const selected = await inquirer.prompt([
|
|
406
412
|
{
|
|
407
413
|
name: 'items',
|
|
408
|
-
message
|
|
414
|
+
message,
|
|
409
415
|
type: 'checkbox',
|
|
410
|
-
choices
|
|
416
|
+
choices,
|
|
411
417
|
},
|
|
412
418
|
]);
|
|
413
419
|
|
|
@@ -425,9 +431,9 @@ async function promptSelect(message, choices) {
|
|
|
425
431
|
const selected = await inquirer.prompt([
|
|
426
432
|
{
|
|
427
433
|
name: 'item',
|
|
428
|
-
message
|
|
434
|
+
message,
|
|
429
435
|
type: 'list',
|
|
430
|
-
choices
|
|
436
|
+
choices,
|
|
431
437
|
},
|
|
432
438
|
]);
|
|
433
439
|
|
|
@@ -441,11 +447,11 @@ async function promptSelect(message, choices) {
|
|
|
441
447
|
* @param {object[]} choices - list of options
|
|
442
448
|
* @returns {object[]} - selected options
|
|
443
449
|
*/
|
|
444
|
-
|
|
450
|
+
async function promptInput(message) {
|
|
445
451
|
const selected = await inquirer.prompt([
|
|
446
452
|
{
|
|
447
453
|
name: 'item',
|
|
448
|
-
message
|
|
454
|
+
message,
|
|
449
455
|
type: 'input',
|
|
450
456
|
},
|
|
451
457
|
]);
|
package/src/utils.js
CHANGED
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
* If the path evaluates to false, the default string is returned.
|
|
4
4
|
*
|
|
5
5
|
* @param {object} obj
|
|
6
|
-
* @param {
|
|
6
|
+
* @param {Array<string>} path
|
|
7
7
|
* @param {string} defaultString
|
|
8
|
-
*
|
|
9
8
|
* @returns {string}
|
|
10
9
|
*/
|
|
11
10
|
function objToString(obj, path = [], defaultString = '') {
|
|
@@ -50,8 +49,7 @@ const autoConfirmActionFlag = Flags.boolean({
|
|
|
50
49
|
});
|
|
51
50
|
|
|
52
51
|
const jsonFlag = Flags.boolean({
|
|
53
|
-
description:
|
|
54
|
-
'Output JSON',
|
|
52
|
+
description: 'Output JSON',
|
|
55
53
|
default: false,
|
|
56
54
|
});
|
|
57
55
|
|