@adobe/aio-cli-plugin-api-mesh 1.0.3-beta → 1.1.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 +61 -7
- package/oclif.manifest.json +1 -1
- package/package.json +5 -2
- package/src/commands/api-mesh/__tests__/create.test.js +446 -33
- package/src/commands/api-mesh/__tests__/delete.test.js +267 -52
- package/src/commands/api-mesh/__tests__/describe.test.js +210 -40
- package/src/commands/api-mesh/__tests__/get.test.js +298 -36
- package/src/commands/api-mesh/__tests__/update.test.js +237 -61
- package/src/commands/api-mesh/create.js +92 -18
- package/src/commands/api-mesh/delete.js +76 -29
- package/src/commands/api-mesh/describe.js +27 -3
- package/src/commands/api-mesh/get.js +46 -26
- package/src/commands/api-mesh/source/__fixtures__/0.0.1-test-01.json +44 -0
- package/src/commands/api-mesh/source/__fixtures__/0.0.1-test-02.json +44 -0
- package/src/commands/api-mesh/source/__fixtures__/connectors-metadata.json +16 -0
- package/src/commands/api-mesh/source/__tests__/discover.test.js +58 -0
- package/src/commands/api-mesh/source/__tests__/get.test.js +123 -0
- package/src/commands/api-mesh/source/discover.js +70 -0
- package/src/commands/api-mesh/source/get.js +138 -0
- package/src/commands/api-mesh/update.js +54 -26
- package/src/constants.js +21 -0
- package/src/helpers.js +213 -44
- package/src/lib/devConsole.js +746 -0
- package/src/utils.js +18 -1
- package/src/classes/SchemaServiceClient.js +0 -416
package/src/utils.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @returns {string}
|
|
10
10
|
*/
|
|
11
|
-
function objToString(obj, path, defaultString = '') {
|
|
11
|
+
function objToString(obj, path = [], defaultString = '') {
|
|
12
12
|
try {
|
|
13
13
|
// Cache the current object
|
|
14
14
|
let current = obj;
|
|
@@ -34,6 +34,23 @@ function objToString(obj, path, defaultString = '') {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
const { Flags } = require('@oclif/core');
|
|
38
|
+
|
|
39
|
+
const ignoreCacheFlag = Flags.boolean({
|
|
40
|
+
char: 'i',
|
|
41
|
+
description: 'Ignore cache and force manual org -> project -> workspace selection',
|
|
42
|
+
default: false,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const autoConfirmActionFlag = Flags.boolean({
|
|
46
|
+
char: 'c',
|
|
47
|
+
description:
|
|
48
|
+
'Auto confirm action prompt. CLI will not check for user approval before executing the action.',
|
|
49
|
+
default: false,
|
|
50
|
+
});
|
|
51
|
+
|
|
37
52
|
module.exports = {
|
|
38
53
|
objToString,
|
|
54
|
+
ignoreCacheFlag,
|
|
55
|
+
autoConfirmActionFlag,
|
|
39
56
|
};
|
|
@@ -1,416 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2021 Adobe. All rights reserved.
|
|
3
|
-
This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
Unless required by applicable law or agreed to in writing, software distributed under
|
|
7
|
-
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
8
|
-
OF ANY KIND, either express or implied. See the License for the specific language
|
|
9
|
-
governing permissions and limitations under the License.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
const axios = require('axios');
|
|
13
|
-
const logger = require('../classes/logger');
|
|
14
|
-
const { objToString } = require('../utils');
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* This class provides methods to call Schema Management Service APIs.
|
|
18
|
-
* Before calling any method initialize the instance by calling the `init` method on it
|
|
19
|
-
* with valid values for baseUrl, apiKey and accessToken
|
|
20
|
-
*/
|
|
21
|
-
class SchemaServiceClient {
|
|
22
|
-
init(baseUrl, accessToken, apiKey) {
|
|
23
|
-
this.devConsoleUrl = baseUrl;
|
|
24
|
-
this.accessToken = accessToken;
|
|
25
|
-
this.apiKey = apiKey;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async describeMesh(organizationId, projectId, workspaceId) {
|
|
29
|
-
const config = {
|
|
30
|
-
method: 'get',
|
|
31
|
-
url: `${this.devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/describe?API_KEY=${this.apiKey}`,
|
|
32
|
-
headers: {
|
|
33
|
-
'Authorization': `Bearer ${this.accessToken}`,
|
|
34
|
-
'x-request-id': global.requestId,
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
logger.info(
|
|
39
|
-
'Initiating GET %s',
|
|
40
|
-
`${this.devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/describe?API_KEY=${this.apiKey}`,
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
const response = await axios(config);
|
|
45
|
-
|
|
46
|
-
logger.info('Response from GET %s', response.status);
|
|
47
|
-
|
|
48
|
-
if (response && response.status === 200) {
|
|
49
|
-
logger.info(`Mesh Config : ${objToString(response, ['data'])}`);
|
|
50
|
-
|
|
51
|
-
return response.data;
|
|
52
|
-
} else {
|
|
53
|
-
// Non 200 response received
|
|
54
|
-
logger.error(
|
|
55
|
-
`Something went wrong: ${objToString(
|
|
56
|
-
response,
|
|
57
|
-
['data'],
|
|
58
|
-
'Unable to get mesh',
|
|
59
|
-
)}. Received ${response.status} response instead of 200`,
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
throw new Error(
|
|
63
|
-
`Something went wrong: ${objToString(response, ['data'], 'Unable to get mesh')}`,
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
} catch (error) {
|
|
67
|
-
if (error.response.status === 400) {
|
|
68
|
-
// The request was made and the server responded with a 400 status code
|
|
69
|
-
logger.error('Mesh not found');
|
|
70
|
-
|
|
71
|
-
return null;
|
|
72
|
-
} else {
|
|
73
|
-
// The request was made and the server responded with a different status code
|
|
74
|
-
logger.error('Error while describing mesh');
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
async getMesh(organizationId, projectId, workspaceId, meshId) {
|
|
80
|
-
const config = {
|
|
81
|
-
method: 'get',
|
|
82
|
-
url: `${this.devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}?API_KEY=${this.apiKey}`,
|
|
83
|
-
headers: {
|
|
84
|
-
'Authorization': `Bearer ${this.accessToken}`,
|
|
85
|
-
'x-request-id': global.requestId,
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
logger.info(
|
|
90
|
-
'Initiating GET %s',
|
|
91
|
-
`${this.devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}?API_KEY=${this.apiKey}`,
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
const response = await axios(config);
|
|
96
|
-
|
|
97
|
-
logger.info('Response from GET %s', response.status);
|
|
98
|
-
|
|
99
|
-
if (response && response.status === 200) {
|
|
100
|
-
logger.info(`Mesh Config : ${objToString(response, ['data'])}`);
|
|
101
|
-
|
|
102
|
-
return response.data;
|
|
103
|
-
} else {
|
|
104
|
-
// Non 200 response received
|
|
105
|
-
logger.error(
|
|
106
|
-
`Something went wrong: ${objToString(
|
|
107
|
-
response,
|
|
108
|
-
['data'],
|
|
109
|
-
'Unable to get mesh',
|
|
110
|
-
)}. Received ${response.status} response instead of 200`,
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
throw new Error(
|
|
114
|
-
`Something went wrong: ${objToString(response, ['data'], 'Unable to get mesh')}`,
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
} catch (error) {
|
|
118
|
-
logger.info('Response from GET %s', error.response.status);
|
|
119
|
-
|
|
120
|
-
if (error.response.status === 404) {
|
|
121
|
-
// The request was made and the server responded with a 404 status code
|
|
122
|
-
logger.error('Mesh not found');
|
|
123
|
-
|
|
124
|
-
return null;
|
|
125
|
-
} else if (error.response && error.response.data) {
|
|
126
|
-
// The request was made and the server responded with an unsupported status code
|
|
127
|
-
logger.error(
|
|
128
|
-
'Error while getting mesh. Response: %s',
|
|
129
|
-
objToString(error, ['response', 'data'], 'Unable to get mesh'),
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
if (error.response.data.messages) {
|
|
133
|
-
const message = objToString(
|
|
134
|
-
error,
|
|
135
|
-
['response', 'data', 'messages', '0', 'message'],
|
|
136
|
-
'Unable to get mesh',
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
throw new Error(message);
|
|
140
|
-
} else if (error.response.data.message) {
|
|
141
|
-
const message = objToString(error, ['response', 'data', 'message'], 'Unable to get mesh');
|
|
142
|
-
|
|
143
|
-
throw new Error(message);
|
|
144
|
-
} else {
|
|
145
|
-
const message = objToString(error, ['response', 'data'], 'Unable to get mesh');
|
|
146
|
-
|
|
147
|
-
throw new Error(message);
|
|
148
|
-
}
|
|
149
|
-
} else {
|
|
150
|
-
// The request was made but no response was received
|
|
151
|
-
logger.error(
|
|
152
|
-
'Error while getting mesh. No response received from the server: %s',
|
|
153
|
-
objToString(error, [], 'Unable to get mesh'),
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
throw new Error('Unable to get mesh from Schema Management Service: %s', error.message);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
async createMesh(organizationId, projectId, workspaceId, data) {
|
|
162
|
-
const config = {
|
|
163
|
-
method: 'post',
|
|
164
|
-
url: `${this.devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes?API_KEY=${this.apiKey}`,
|
|
165
|
-
headers: {
|
|
166
|
-
'Authorization': `Bearer ${this.accessToken}`,
|
|
167
|
-
'Content-Type': 'application/json',
|
|
168
|
-
'x-request-id': global.requestId,
|
|
169
|
-
},
|
|
170
|
-
data: JSON.stringify(data),
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
logger.info(
|
|
174
|
-
'Initiating POST %s',
|
|
175
|
-
`${this.devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes?API_KEY=${this.apiKey}`,
|
|
176
|
-
);
|
|
177
|
-
|
|
178
|
-
try {
|
|
179
|
-
const response = await axios(config);
|
|
180
|
-
|
|
181
|
-
logger.info('Response from POST %s', response.status);
|
|
182
|
-
|
|
183
|
-
if (response && response.status === 201) {
|
|
184
|
-
logger.info(`Mesh Config : ${objToString(response, ['data'])}`);
|
|
185
|
-
|
|
186
|
-
return response.data;
|
|
187
|
-
} else {
|
|
188
|
-
// Non 201 response received
|
|
189
|
-
logger.error(
|
|
190
|
-
`Something went wrong: ${objToString(
|
|
191
|
-
response,
|
|
192
|
-
['data'],
|
|
193
|
-
'Unable to create mesh',
|
|
194
|
-
)}. Received ${response.status} response instead of 201`,
|
|
195
|
-
);
|
|
196
|
-
|
|
197
|
-
throw new Error(response.data.message);
|
|
198
|
-
}
|
|
199
|
-
} catch (error) {
|
|
200
|
-
if (error.response.status === 409) {
|
|
201
|
-
// The request was made and the server responded with a 409 status code
|
|
202
|
-
logger.error('Error while creating mesh: %j', error.response.data);
|
|
203
|
-
|
|
204
|
-
throw new Error('Selected org, project and workspace already has a mesh');
|
|
205
|
-
} else if (error.response && error.response.data) {
|
|
206
|
-
// The request was made and the server responded with an unsupported status code
|
|
207
|
-
logger.error(
|
|
208
|
-
'Error while creating mesh. Response: %s',
|
|
209
|
-
objToString(error, ['response', 'data'], 'Unable to create mesh'),
|
|
210
|
-
);
|
|
211
|
-
|
|
212
|
-
if (error.response.data.messages) {
|
|
213
|
-
const message = objToString(
|
|
214
|
-
error,
|
|
215
|
-
['response', 'data', 'messages'],
|
|
216
|
-
'Unable to create mesh',
|
|
217
|
-
);
|
|
218
|
-
|
|
219
|
-
throw new Error(message);
|
|
220
|
-
} else if (error.response.data.message) {
|
|
221
|
-
const message = objToString(
|
|
222
|
-
error,
|
|
223
|
-
['response', 'data', 'message'],
|
|
224
|
-
'Unable to create mesh',
|
|
225
|
-
);
|
|
226
|
-
|
|
227
|
-
throw new Error(message);
|
|
228
|
-
} else {
|
|
229
|
-
const message = objToString(error, ['response', 'data'], 'Unable to create mesh');
|
|
230
|
-
|
|
231
|
-
throw new Error(message);
|
|
232
|
-
}
|
|
233
|
-
} else {
|
|
234
|
-
// The request was made but no response was received
|
|
235
|
-
logger.error(
|
|
236
|
-
'Error while creating mesh. No response received from the server: %s',
|
|
237
|
-
objToString(error, [], 'Unable to create mesh'),
|
|
238
|
-
);
|
|
239
|
-
|
|
240
|
-
throw new Error('Unable to create mesh in Schema Management Service: %s', error.message);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
async updateMesh(organizationId, projectId, workspaceId, meshId, data) {
|
|
246
|
-
const config = {
|
|
247
|
-
method: 'put',
|
|
248
|
-
url: `${this.devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}?API_KEY=${this.apiKey}`,
|
|
249
|
-
headers: {
|
|
250
|
-
'Authorization': `Bearer ${this.accessToken}`,
|
|
251
|
-
'Content-Type': 'application/json',
|
|
252
|
-
'x-request-id': global.requestId,
|
|
253
|
-
},
|
|
254
|
-
data: JSON.stringify(data),
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
logger.info(
|
|
258
|
-
'Initiating PUT %s',
|
|
259
|
-
`${this.devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}?API_KEY=${this.apiKey}`,
|
|
260
|
-
);
|
|
261
|
-
|
|
262
|
-
try {
|
|
263
|
-
const response = await axios(config);
|
|
264
|
-
|
|
265
|
-
logger.info('Response from POST %s', response.status);
|
|
266
|
-
|
|
267
|
-
if (response && response.status === 204) {
|
|
268
|
-
return response.data;
|
|
269
|
-
} else {
|
|
270
|
-
// Non 204 response received
|
|
271
|
-
logger.error(
|
|
272
|
-
`Something went wrong: ${objToString(
|
|
273
|
-
response,
|
|
274
|
-
['data'],
|
|
275
|
-
'Unable to update mesh',
|
|
276
|
-
)}. Received ${response.status} response instead of 204`,
|
|
277
|
-
);
|
|
278
|
-
|
|
279
|
-
throw new Error(
|
|
280
|
-
`Something went wrong: ${objToString(response, ['data'], 'Unable to update mesh')}`,
|
|
281
|
-
);
|
|
282
|
-
}
|
|
283
|
-
} catch (error) {
|
|
284
|
-
logger.info('Response from PUT %s', error.response.status);
|
|
285
|
-
|
|
286
|
-
if (error.response.status === 404) {
|
|
287
|
-
// The request was made and the server responded with a 404 status code
|
|
288
|
-
logger.error('Mesh not found');
|
|
289
|
-
|
|
290
|
-
throw new Error('Mesh not found');
|
|
291
|
-
} else if (error.response && error.response.data) {
|
|
292
|
-
// The request was made and the server responded with an unsupported status code
|
|
293
|
-
logger.error(
|
|
294
|
-
'Error while updating mesh. Response: %s',
|
|
295
|
-
objToString(error, ['response', 'data'], 'Unable to update mesh'),
|
|
296
|
-
);
|
|
297
|
-
|
|
298
|
-
if (error.response.data.messages) {
|
|
299
|
-
const message = objToString(
|
|
300
|
-
error,
|
|
301
|
-
['response', 'data', 'messages', '0', 'message'],
|
|
302
|
-
'Unable to update mesh',
|
|
303
|
-
);
|
|
304
|
-
|
|
305
|
-
throw new Error(message);
|
|
306
|
-
} else if (error.response.data.message) {
|
|
307
|
-
const message = objToString(
|
|
308
|
-
error,
|
|
309
|
-
['response', 'data', 'message'],
|
|
310
|
-
'Unable to update mesh',
|
|
311
|
-
);
|
|
312
|
-
|
|
313
|
-
throw new Error(message);
|
|
314
|
-
} else {
|
|
315
|
-
const message = objToString(error, ['response', 'data'], 'Unable to update mesh');
|
|
316
|
-
|
|
317
|
-
throw new Error(message);
|
|
318
|
-
}
|
|
319
|
-
} else {
|
|
320
|
-
// The request was made but no response was received
|
|
321
|
-
logger.error(
|
|
322
|
-
'Error while updating mesh. No response received from the server: %s',
|
|
323
|
-
objToString(error, [], 'Unable to update mesh'),
|
|
324
|
-
);
|
|
325
|
-
|
|
326
|
-
throw new Error('Unable to update mesh from Schema Management Service: %s', error.message);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
async deleteMesh(organizationId, projectId, workspaceId, meshId) {
|
|
332
|
-
const config = {
|
|
333
|
-
method: 'delete',
|
|
334
|
-
url: `${this.devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}?API_KEY=${this.apiKey}`,
|
|
335
|
-
headers: {
|
|
336
|
-
'Authorization': `Bearer ${this.accessToken}`,
|
|
337
|
-
'x-request-id': global.requestId,
|
|
338
|
-
},
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
logger.info(
|
|
342
|
-
'Initiating DELETE %s',
|
|
343
|
-
`${this.devConsoleUrl}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}?API_KEY=${this.apiKey}`,
|
|
344
|
-
);
|
|
345
|
-
|
|
346
|
-
try {
|
|
347
|
-
const response = await axios(config);
|
|
348
|
-
|
|
349
|
-
logger.info('Response from DELETE %s', response.status);
|
|
350
|
-
|
|
351
|
-
if (response && response.status === 204) {
|
|
352
|
-
return response;
|
|
353
|
-
} else {
|
|
354
|
-
// Non 204 response received
|
|
355
|
-
logger.error(
|
|
356
|
-
`Something went wrong: ${objToString(
|
|
357
|
-
response,
|
|
358
|
-
['data'],
|
|
359
|
-
'Unable to delete mesh',
|
|
360
|
-
)}. Received ${response.status} response instead of 204`,
|
|
361
|
-
);
|
|
362
|
-
|
|
363
|
-
throw new Error(
|
|
364
|
-
`Something went wrong: ${objToString(response, ['data'], 'Unable to delete mesh')}`,
|
|
365
|
-
);
|
|
366
|
-
}
|
|
367
|
-
} catch (error) {
|
|
368
|
-
logger.info('Response from DELETE %s', error.response.status);
|
|
369
|
-
|
|
370
|
-
if (error.response.status === 404) {
|
|
371
|
-
// The request was made and the server responded with a 404 status code
|
|
372
|
-
logger.error('Mesh not found');
|
|
373
|
-
|
|
374
|
-
throw new Error('Mesh not found');
|
|
375
|
-
} else if (error.response && error.response.data) {
|
|
376
|
-
// The request was made and the server responded with an unsupported status code
|
|
377
|
-
logger.error(
|
|
378
|
-
'Error while deleting mesh. Response: %s',
|
|
379
|
-
objToString(error, ['response', 'data'], 'Unable to delete mesh'),
|
|
380
|
-
);
|
|
381
|
-
|
|
382
|
-
if (error.response.data.messages) {
|
|
383
|
-
const message = objToString(
|
|
384
|
-
error,
|
|
385
|
-
['response', 'data', 'messages', '0', 'message'],
|
|
386
|
-
'Unable to delete mesh',
|
|
387
|
-
);
|
|
388
|
-
|
|
389
|
-
throw new Error(message);
|
|
390
|
-
} else if (error.response.data.message) {
|
|
391
|
-
const message = objToString(
|
|
392
|
-
error,
|
|
393
|
-
['response', 'data', 'message'],
|
|
394
|
-
'Unable to delete mesh',
|
|
395
|
-
);
|
|
396
|
-
|
|
397
|
-
throw new Error(message);
|
|
398
|
-
} else {
|
|
399
|
-
const message = objToString(error, ['response', 'data'], 'Unable to delete mesh');
|
|
400
|
-
|
|
401
|
-
throw new Error(message);
|
|
402
|
-
}
|
|
403
|
-
} else {
|
|
404
|
-
// The request was made but no response was received
|
|
405
|
-
logger.error(
|
|
406
|
-
'Error while deleting mesh. No response received from the server: %s',
|
|
407
|
-
objToString(error, [], 'Unable to delete mesh'),
|
|
408
|
-
);
|
|
409
|
-
|
|
410
|
-
throw new Error('Unable to delete mesh from Schema Management Service: %s', error.message);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
module.exports = { SchemaServiceClient };
|