@adobe/aio-cli-plugin-api-mesh 1.0.0-beta → 1.0.3-beta
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 +10 -7
- package/oclif.manifest.json +1 -1
- package/package.json +93 -98
- package/src/classes/SchemaServiceClient.js +396 -74
- package/src/classes/UUID.js +20 -0
- package/src/classes/logger.js +19 -0
- package/src/commands/PLUGINNAME/__tests__/index.test.js +30 -0
- package/src/commands/PLUGINNAME/index.js +11 -13
- package/src/commands/__fixtures__/sample_mesh.json +14 -0
- package/src/commands/api-mesh/__tests__/create.test.js +75 -0
- package/src/commands/api-mesh/__tests__/delete.test.js +104 -0
- package/src/commands/api-mesh/__tests__/describe.test.js +79 -0
- package/src/commands/api-mesh/__tests__/get.test.js +74 -0
- package/src/commands/api-mesh/__tests__/update.test.js +113 -0
- package/src/commands/api-mesh/create.js +73 -0
- package/src/commands/api-mesh/delete.js +70 -0
- package/src/commands/api-mesh/describe.js +61 -0
- package/src/commands/api-mesh/get.js +75 -0
- package/src/commands/api-mesh/update.js +82 -0
- package/src/helpers.js +189 -63
- package/src/utils.js +39 -0
- package/src/commands/commerce-gateway/tenant/create.js +0 -42
- package/src/commands/commerce-gateway/tenant/get.js +0 -33
- package/src/commands/commerce-gateway/tenant/update.js +0 -42
|
@@ -9,7 +9,9 @@ OF ANY KIND, either express or implied. See the License for the specific languag
|
|
|
9
9
|
governing permissions and limitations under the License.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
const axios = require('axios')
|
|
12
|
+
const axios = require('axios');
|
|
13
|
+
const logger = require('../classes/logger');
|
|
14
|
+
const { objToString } = require('../utils');
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* This class provides methods to call Schema Management Service APIs.
|
|
@@ -17,78 +19,398 @@ const axios = require('axios')
|
|
|
17
19
|
* with valid values for baseUrl, apiKey and accessToken
|
|
18
20
|
*/
|
|
19
21
|
class SchemaServiceClient {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
+
}
|
|
92
414
|
}
|
|
93
415
|
|
|
94
|
-
module.exports = { SchemaServiceClient }
|
|
416
|
+
module.exports = { SchemaServiceClient };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const { v4: uuidv4 } = require('uuid');
|
|
2
|
+
// Class representing a new unique UUID which is used for request-id tracing
|
|
3
|
+
class UUID {
|
|
4
|
+
constructor(uuid = '') {
|
|
5
|
+
this.uuid = uuid;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
toString() {
|
|
9
|
+
return this.uuid;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static newUuid() {
|
|
13
|
+
const newUUID = uuidv4();
|
|
14
|
+
return new UUID(newUUID);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = {
|
|
19
|
+
UUID,
|
|
20
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const { default: pino } = require('pino');
|
|
2
|
+
|
|
3
|
+
const logger = pino({
|
|
4
|
+
level: process.env.LOG_LEVEL || 'info',
|
|
5
|
+
enabled: process.env.ENABLE_LOGGER === 'true',
|
|
6
|
+
mixin() {
|
|
7
|
+
return {
|
|
8
|
+
requestId: global.requestId,
|
|
9
|
+
};
|
|
10
|
+
},
|
|
11
|
+
transport: {
|
|
12
|
+
target: 'pino-pretty',
|
|
13
|
+
options: {
|
|
14
|
+
colorize: true,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
module.exports = logger;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 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
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const IndexCommand = require('..');
|
|
14
|
+
|
|
15
|
+
test('exports', async () => {
|
|
16
|
+
expect(typeof IndexCommand).toEqual('function');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('command tests', () => {
|
|
20
|
+
let command;
|
|
21
|
+
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
command = new IndexCommand([]);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('run', async () => {
|
|
27
|
+
command.argv = [];
|
|
28
|
+
await expect(command.run()).resolves.not.toThrowError();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -10,25 +10,23 @@ OF ANY KIND, either express or implied. See the License for the specific languag
|
|
|
10
10
|
governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
const { Command, flags } = require('@oclif/command')
|
|
14
|
-
const aioLogger = require('@adobe/aio-lib-core-logging')('PLUGINNAME', { provider: 'debug' })
|
|
13
|
+
const { Command, flags } = require('@oclif/command');
|
|
14
|
+
const aioLogger = require('@adobe/aio-lib-core-logging')('PLUGINNAME', { provider: 'debug' });
|
|
15
15
|
|
|
16
16
|
class IndexCommand extends Command {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
async run() {
|
|
18
|
+
// const { args, flags } = this.parse(IndexCommand)
|
|
19
|
+
aioLogger.debug('this is the index command.');
|
|
20
|
+
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
IndexCommand.flags = {
|
|
24
|
-
|
|
25
|
-
}
|
|
24
|
+
someflag: flags.string({ char: 'f', description: 'this is some flag' }),
|
|
25
|
+
};
|
|
26
26
|
|
|
27
27
|
// this is set in package.json, see https://github.com/oclif/oclif/issues/120
|
|
28
28
|
// if not set it will get the first (alphabetical) topic's help description
|
|
29
|
-
IndexCommand.description = 'Your description here'
|
|
30
|
-
IndexCommand.examples = [
|
|
31
|
-
'$ aio PLUGINNAME:some_command'
|
|
32
|
-
]
|
|
29
|
+
IndexCommand.description = 'Your description here';
|
|
30
|
+
IndexCommand.examples = ['$ aio PLUGINNAME:some_command'];
|
|
33
31
|
|
|
34
|
-
module.exports = IndexCommand
|
|
32
|
+
module.exports = IndexCommand;
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const mockConsoleCLIInstance = {};
|
|
14
|
+
|
|
15
|
+
jest.mock('@adobe/aio-lib-env');
|
|
16
|
+
jest.mock('@adobe/aio-cli-lib-console');
|
|
17
|
+
|
|
18
|
+
const orgs = [{ id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' }];
|
|
19
|
+
const selectedOrg = { id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' };
|
|
20
|
+
|
|
21
|
+
const projects = [{ id: '5678', title: 'Project01' }];
|
|
22
|
+
const selectedProject = { id: '5678', title: 'Project01' };
|
|
23
|
+
|
|
24
|
+
const workspaces = [{ id: '123456789', title: 'Workspace01' }];
|
|
25
|
+
const selectedWorkspace = { id: '123456789', title: 'Workspace01' };
|
|
26
|
+
|
|
27
|
+
function setDefaultMockConsoleCLI() {
|
|
28
|
+
mockConsoleCLIInstance.getToken = jest.fn().mockReturnValue('test_token');
|
|
29
|
+
mockConsoleCLIInstance.getCliEnv = jest.fn().mockReturnValue('prod');
|
|
30
|
+
|
|
31
|
+
mockConsoleCLIInstance.getOrganizations = jest.fn().mockResolvedValue(orgs);
|
|
32
|
+
mockConsoleCLIInstance.promptForSelectOrganization = jest.fn().mockResolvedValue(selectedOrg);
|
|
33
|
+
|
|
34
|
+
mockConsoleCLIInstance.getProjects = jest.fn().mockResolvedValue(projects);
|
|
35
|
+
mockConsoleCLIInstance.promptForSelectProject = jest.fn().mockResolvedValue(selectedProject);
|
|
36
|
+
|
|
37
|
+
mockConsoleCLIInstance.getWorkspaces = jest.fn().mockResolvedValue(workspaces);
|
|
38
|
+
mockConsoleCLIInstance.promptForSelectWorkspace = jest.fn().mockResolvedValue(selectedWorkspace);
|
|
39
|
+
}
|
|
40
|
+
jest.mock('@adobe/aio-cli-lib-console', () => ({
|
|
41
|
+
init: jest.fn().mockResolvedValue(mockConsoleCLIInstance),
|
|
42
|
+
cleanStdOut: jest.fn(),
|
|
43
|
+
}));
|
|
44
|
+
jest.mock('@adobe/aio-lib-ims');
|
|
45
|
+
const CreateCommand = require('../create');
|
|
46
|
+
const { SchemaServiceClient } = require('../../../classes/SchemaServiceClient');
|
|
47
|
+
const mockCreateMesh = require('../../__fixtures__/sample_mesh.json');
|
|
48
|
+
|
|
49
|
+
describe('create command tests', () => {
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
setDefaultMockConsoleCLI();
|
|
52
|
+
const response = mockCreateMesh;
|
|
53
|
+
jest.spyOn(SchemaServiceClient.prototype, 'createMesh').mockImplementation(data => response);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
afterEach(() => {
|
|
57
|
+
jest.restoreAllMocks();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('should fail mesh id is missing', async () => {
|
|
61
|
+
expect.assertions(2);
|
|
62
|
+
const runResult = CreateCommand.run([]);
|
|
63
|
+
await expect(runResult instanceof Promise).toBeTruthy();
|
|
64
|
+
await expect(runResult).rejects.toEqual(
|
|
65
|
+
new Error('Missing file path. Run aio api-mesh create --help for more info.'),
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('create-mesh-with-configuration', async () => {
|
|
70
|
+
expect.assertions(2);
|
|
71
|
+
const runResult = CreateCommand.run(['src/commands/__fixtures__/sample_mesh.json']);
|
|
72
|
+
await expect(runResult instanceof Promise).toBeTruthy();
|
|
73
|
+
await expect(runResult).resolves.toEqual(mockCreateMesh);
|
|
74
|
+
});
|
|
75
|
+
});
|