@adobe/aio-cli-plugin-api-mesh 1.0.3-beta → 1.0.4-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.
@@ -10,104 +10,280 @@ 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 inquirer = require('inquirer');
13
+ jest.mock('axios');
14
+ jest.mock('fs/promises');
15
+ jest.mock('@adobe/aio-lib-env');
16
+ jest.mock('../../../helpers', () => ({
17
+ initSdk: jest.fn().mockResolvedValue({}),
18
+ initRequestId: jest.fn().mockResolvedValue({}),
19
+ promptConfirm: jest.fn().mockResolvedValue(true),
20
+ }));
21
+ jest.mock('@adobe/aio-cli-lib-console', () => ({
22
+ init: jest.fn().mockResolvedValue(mockConsoleCLIInstance),
23
+ cleanStdOut: jest.fn(),
24
+ }));
25
+ jest.mock('@adobe/aio-lib-ims');
26
+ jest.mock('../../../lib/devConsole');
14
27
 
15
28
  const mockConsoleCLIInstance = {};
16
- jest.mock('@adobe/aio-lib-env');
17
- const orgs = [{ id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' }];
18
- const selectedOrg = { id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' };
19
29
 
20
- const projects = [{ id: '5678', title: 'Project01' }];
30
+ const selectedOrg = { id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' };
21
31
  const selectedProject = { id: '5678', title: 'Project01' };
22
-
23
- const workspaces = [{ id: '123456789', title: 'Workspace01' }];
24
32
  const selectedWorkspace = { id: '123456789', title: 'Workspace01' };
25
33
 
26
- function setDefaultMockConsoleCLI() {
27
- mockConsoleCLIInstance.getToken = jest.fn().mockReturnValue('test_token');
28
- mockConsoleCLIInstance.getCliEnv = jest.fn().mockReturnValue('prod');
34
+ const { readFile } = require('fs/promises');
29
35
 
30
- mockConsoleCLIInstance.getOrganizations = jest.fn().mockResolvedValue(orgs);
31
- mockConsoleCLIInstance.promptForSelectOrganization = jest.fn().mockResolvedValue(selectedOrg);
32
-
33
- mockConsoleCLIInstance.getProjects = jest.fn().mockResolvedValue(projects);
34
- mockConsoleCLIInstance.promptForSelectProject = jest.fn().mockResolvedValue(selectedProject);
35
-
36
- mockConsoleCLIInstance.getWorkspaces = jest.fn().mockResolvedValue(workspaces);
37
- mockConsoleCLIInstance.promptForSelectWorkspace = jest.fn().mockResolvedValue(selectedWorkspace);
38
- }
36
+ const UpdateCommand = require('../update');
37
+ const { initSdk, initRequestId, promptConfirm } = require('../../../helpers');
38
+ const { getMeshId, updateMesh } = require('../../../lib/devConsole');
39
39
 
40
- jest.mock('inquirer', () => ({
41
- createPromptModule: jest.fn().mockReturnValue(
42
- jest.fn().mockResolvedValue({
43
- res: true,
44
- }),
45
- ),
46
- }));
40
+ let logSpy = null;
41
+ let errorLogSpy = null;
47
42
 
48
- jest.mock('@adobe/aio-cli-lib-console', () => ({
49
- init: jest.fn().mockResolvedValue(mockConsoleCLIInstance),
50
- cleanStdOut: jest.fn(),
51
- }));
52
- jest.mock('@adobe/aio-lib-ims');
43
+ let parseSpy = null;
53
44
 
54
- const UpdateCommand = require('../update');
55
- const { SchemaServiceClient } = require('../../../classes/SchemaServiceClient');
56
- const mockUpdateMesh = require('../../__fixtures__/sample_mesh.json');
45
+ const mockIgnoreCacheFlag = Promise.resolve(true);
46
+ const mockAutoApproveAction = Promise.resolve(false);
57
47
 
58
48
  describe('update command tests', () => {
59
49
  beforeEach(() => {
60
- setDefaultMockConsoleCLI();
61
- const response = mockUpdateMesh;
62
- jest.spyOn(SchemaServiceClient.prototype, 'updateMesh').mockImplementation(data => response);
50
+ initSdk.mockResolvedValue({
51
+ imsOrgId: selectedOrg.id,
52
+ projectId: selectedProject.id,
53
+ workspaceId: selectedWorkspace.id,
54
+ });
55
+
56
+ global.requestId = 'dummy_request_id';
57
+
58
+ logSpy = jest.spyOn(UpdateCommand.prototype, 'log');
59
+ errorLogSpy = jest.spyOn(UpdateCommand.prototype, 'error');
60
+
61
+ readFile.mockResolvedValue(true);
62
+
63
+ getMeshId.mockResolvedValue('mesh_id');
64
+ updateMesh.mockResolvedValue({ status: 'success' });
65
+
66
+ parseSpy = jest.spyOn(UpdateCommand.prototype, 'parse');
67
+ parseSpy.mockResolvedValue({
68
+ args: { file: 'valid_file_path' },
69
+ flags: {
70
+ ignoreCache: mockIgnoreCacheFlag,
71
+ autoConfirmAction: mockAutoApproveAction,
72
+ },
73
+ });
63
74
  });
64
75
 
65
76
  afterEach(() => {
66
77
  jest.restoreAllMocks();
67
78
  });
68
79
 
80
+ test('should fail if mesh id is missing', async () => {
81
+ getMeshId.mockResolvedValue(null);
82
+ const runResult = UpdateCommand.run();
83
+
84
+ await expect(runResult).rejects.toMatchInlineSnapshot(
85
+ `[Error: Unable to update. No mesh found for Org(1234) -> Project(5678) -> Workspace(123456789). Please check the details and try again.]`,
86
+ );
87
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
88
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
89
+ Array [
90
+ Array [
91
+ "Unable to update. No mesh found for Org(1234) -> Project(5678) -> Workspace(123456789). Please check the details and try again.",
92
+ ],
93
+ ]
94
+ `);
95
+ });
96
+
97
+ test('should fail if getMeshId api failed', async () => {
98
+ getMeshId.mockRejectedValue(new Error('getMeshId api failed'));
99
+ const runResult = UpdateCommand.run();
100
+
101
+ await expect(runResult).rejects.toMatchInlineSnapshot(
102
+ `[Error: Unable to get mesh ID. Please check the details and try again. RequestId: dummy_request_id]`,
103
+ );
104
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
105
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
106
+ Array [
107
+ Array [
108
+ "Unable to get mesh ID. Please check the details and try again. RequestId: dummy_request_id",
109
+ ],
110
+ ]
111
+ `);
112
+ });
113
+
69
114
  test('should fail if update file path is missing', async () => {
70
- expect.assertions(2);
71
- const runResult = UpdateCommand.run(['dummy_mesh_id']);
72
- await expect(runResult instanceof Promise).toBeTruthy();
115
+ parseSpy.mockResolvedValueOnce({
116
+ args: { file: null },
117
+ flags: {
118
+ ignoreCache: mockIgnoreCacheFlag,
119
+ autoConfirmAction: mockAutoApproveAction,
120
+ },
121
+ });
122
+ const runResult = UpdateCommand.run();
123
+
73
124
  await expect(runResult).rejects.toEqual(
74
125
  new Error('Missing required args. Run aio api-mesh update --help for more info.'),
75
126
  );
127
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
128
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
129
+ Array [
130
+ Array [
131
+ "Missing required args. Run aio api-mesh update --help for more info.",
132
+ ],
133
+ ]
134
+ `);
76
135
  });
77
136
 
78
137
  test('should fail if dummy file path is provided', async () => {
79
- expect.assertions(2);
80
- const runResult = UpdateCommand.run(['dummy_mesh_id', 'dummy_file_path']);
81
- await expect(runResult instanceof Promise).toBeTruthy();
138
+ readFile.mockRejectedValueOnce(new Error('File not found'));
139
+ const runResult = UpdateCommand.run();
140
+
82
141
  await expect(runResult).rejects.toEqual(
83
142
  new Error(
84
143
  'Unable to read the mesh configuration file provided. Please check the file and try again.',
85
144
  ),
86
145
  );
146
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`
147
+ Array [
148
+ Array [
149
+ "File not found",
150
+ ],
151
+ ]
152
+ `);
153
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
154
+ Array [
155
+ Array [
156
+ "Unable to read the mesh configuration file provided. Please check the file and try again.",
157
+ ],
158
+ ]
159
+ `);
87
160
  });
88
161
 
89
- test('should pass with valid args', async () => {
90
- expect.assertions(2);
91
- const runResult = UpdateCommand.run([
92
- 'sample_merchant',
93
- 'src/commands/__fixtures__/sample_mesh.json',
94
- ]);
95
- await expect(runResult instanceof Promise).toBeTruthy();
96
- await expect(runResult).resolves.toEqual(mockUpdateMesh);
162
+ test('should not update if user prompt returns false', async () => {
163
+ promptConfirm.mockResolvedValueOnce(false);
164
+
165
+ const runResult = await UpdateCommand.run();
166
+
167
+ expect(runResult).toMatchInlineSnapshot(`"Update cancelled"`);
168
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`
169
+ Array [
170
+ Array [
171
+ "Update cancelled",
172
+ ],
173
+ ]
174
+ `);
175
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
97
176
  });
98
177
 
99
- test('should not update if user prompt returns false', async () => {
100
- inquirer.createPromptModule.mockReturnValue(
101
- jest.fn().mockResolvedValue({
102
- res: false,
103
- }),
178
+ test('should fail if updateMesh method failed', async () => {
179
+ updateMesh.mockRejectedValueOnce(new Error('dummy_error'));
180
+
181
+ const runResult = UpdateCommand.run();
182
+
183
+ await expect(runResult).rejects.toEqual(
184
+ new Error(
185
+ 'Unable to update the mesh. Please check the mesh configuration file and try again. If the error persists please contact support. RequestId: dummy_request_id',
186
+ ),
104
187
  );
188
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`
189
+ Array [
190
+ Array [
191
+ "dummy_error",
192
+ ],
193
+ ]
194
+ `);
195
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
196
+ Array [
197
+ Array [
198
+ "Unable to update the mesh. Please check the mesh configuration file and try again. If the error persists please contact support. RequestId: dummy_request_id",
199
+ ],
200
+ ]
201
+ `);
202
+ });
203
+
204
+ test('should pass with valid args', async () => {
205
+ const runResult = await UpdateCommand.run();
206
+
207
+ expect(runResult).toMatchInlineSnapshot(`
208
+ Object {
209
+ "status": "success",
210
+ }
211
+ `);
212
+ expect(initRequestId).toHaveBeenCalled();
213
+ expect(initSdk).toHaveBeenCalledWith({
214
+ ignoreCache: true,
215
+ });
216
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`
217
+ Array [
218
+ Array [
219
+ "Successfully updated the mesh with the id: %s",
220
+ "mesh_id",
221
+ ],
222
+ ]
223
+ `);
224
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
225
+ });
226
+
227
+ test('should pass with valid args and ignoreCache flag', async () => {
228
+ parseSpy.mockResolvedValueOnce({
229
+ args: { file: 'valid_file_name' },
230
+ flags: {
231
+ ignoreCache: Promise.resolve(true),
232
+ autoConfirmAction: mockAutoApproveAction,
233
+ },
234
+ });
235
+
236
+ const runResult = await UpdateCommand.run();
237
+
238
+ expect(runResult).toMatchInlineSnapshot(`
239
+ Object {
240
+ "status": "success",
241
+ }
242
+ `);
243
+ expect(initRequestId).toHaveBeenCalled();
244
+ expect(initSdk).toHaveBeenCalledWith({
245
+ ignoreCache: true,
246
+ });
247
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`
248
+ Array [
249
+ Array [
250
+ "Successfully updated the mesh with the id: %s",
251
+ "mesh_id",
252
+ ],
253
+ ]
254
+ `);
255
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
256
+ });
257
+
258
+ test('should pass with valid args if autoConfirmAction flag is set', async () => {
259
+ parseSpy.mockResolvedValueOnce({
260
+ args: { file: 'valid_file_name' },
261
+ flags: {
262
+ ignoreCache: mockIgnoreCacheFlag,
263
+ autoConfirmAction: Promise.resolve(true),
264
+ },
265
+ });
105
266
 
106
- const runResult = await UpdateCommand.run([
107
- 'sample_merchant',
108
- 'src/commands/__fixtures__/sample_mesh.json',
109
- ]);
267
+ const runResult = await UpdateCommand.run();
110
268
 
111
- expect(runResult).toBe('Update cancelled');
269
+ expect(runResult).toMatchInlineSnapshot(`
270
+ Object {
271
+ "status": "success",
272
+ }
273
+ `);
274
+ expect(initRequestId).toHaveBeenCalled();
275
+ expect(promptConfirm).not.toHaveBeenCalled();
276
+ expect(initSdk).toHaveBeenCalledWith({
277
+ ignoreCache: true,
278
+ });
279
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`
280
+ Array [
281
+ Array [
282
+ "Successfully updated the mesh with the id: %s",
283
+ "mesh_id",
284
+ ],
285
+ ]
286
+ `);
287
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`Array []`);
112
288
  });
113
289
  });
@@ -11,18 +11,34 @@ governing permissions and limitations under the License.
11
11
 
12
12
  const { Command } = require('@oclif/command');
13
13
  const { readFile } = require('fs/promises');
14
- const { initSdk, initRequestId } = require('../../helpers');
14
+
15
+ const { initSdk, initRequestId, promptConfirm } = require('../../helpers');
15
16
  const logger = require('../../classes/logger');
17
+ const CONSTANTS = require('../../constants');
18
+ const { ignoreCacheFlag, autoConfirmActionFlag } = require('../../utils');
19
+ const {
20
+ createMesh,
21
+ createAPIMeshCredentials,
22
+ subscribeCredentialToMeshService,
23
+ } = require('../../lib/devConsole');
24
+
25
+ require('dotenv').config();
26
+
27
+ const { MULTITENANT_GRAPHQL_SERVER_BASE_URL } = CONSTANTS;
16
28
 
17
29
  class CreateCommand extends Command {
18
30
  static args = [{ name: 'file' }];
31
+ static flags = {
32
+ ignoreCache: ignoreCacheFlag,
33
+ autoConfirmAction: autoConfirmActionFlag,
34
+ };
19
35
 
20
36
  async run() {
21
37
  await initRequestId();
22
38
 
23
39
  logger.info(`RequestId: ${global.requestId}`);
24
40
 
25
- const { args } = this.parse(CreateCommand);
41
+ const { args, flags } = await this.parse(CreateCommand);
26
42
 
27
43
  if (!args.file) {
28
44
  this.error('Missing file path. Run aio api-mesh create --help for more info.');
@@ -30,7 +46,12 @@ class CreateCommand extends Command {
30
46
  return;
31
47
  }
32
48
 
33
- const { schemaServiceClient, imsOrgId, projectId, workspaceId } = await initSdk();
49
+ const ignoreCache = await flags.ignoreCache;
50
+ const autoConfirmAction = await flags.autoConfirmAction;
51
+
52
+ const { imsOrgId, projectId, workspaceId } = await initSdk({
53
+ ignoreCache,
54
+ });
34
55
 
35
56
  let data;
36
57
 
@@ -45,25 +66,78 @@ class CreateCommand extends Command {
45
66
  );
46
67
  }
47
68
 
48
- try {
49
- const mesh = await schemaServiceClient.createMesh(imsOrgId, projectId, workspaceId, data);
69
+ let shouldContinue = true;
50
70
 
51
- if (mesh) {
52
- this.log('Successfully created mesh %s', mesh.meshId);
53
- this.log(JSON.stringify(mesh, null, 2));
71
+ if (!autoConfirmAction) {
72
+ shouldContinue = await promptConfirm(`Are you sure you want to create a mesh?`);
73
+ }
54
74
 
55
- return mesh;
56
- } else {
57
- this.error(`Unable to create a mesh. Please try again. RequestId: ${global.requestId}`, {
58
- exit: false,
59
- });
75
+ if (shouldContinue) {
76
+ try {
77
+ const mesh = await createMesh(imsOrgId, projectId, workspaceId, data);
78
+ let sdkList = [];
79
+
80
+ if (mesh) {
81
+ this.log('Successfully created mesh %s', mesh.meshId);
82
+ this.log(JSON.stringify(mesh, null, 2));
83
+ // create API key credential
84
+ const adobeIdIntegrationsForWorkspace = await createAPIMeshCredentials(
85
+ imsOrgId,
86
+ projectId,
87
+ workspaceId,
88
+ );
89
+
90
+ if (adobeIdIntegrationsForWorkspace) {
91
+ this.log('Successfully created API Key %s', adobeIdIntegrationsForWorkspace.apiKey);
92
+ // subscribe the credential to API mesh service
93
+ sdkList = await subscribeCredentialToMeshService(
94
+ imsOrgId,
95
+ projectId,
96
+ workspaceId,
97
+ adobeIdIntegrationsForWorkspace.id,
98
+ );
99
+
100
+ if (sdkList) {
101
+ this.log(
102
+ 'Successfully subscribed API Key %s to API Mesh service',
103
+ adobeIdIntegrationsForWorkspace.apiKey,
104
+ );
105
+
106
+ this.log(
107
+ 'Mesh Endpoint: %s\n',
108
+ `${MULTITENANT_GRAPHQL_SERVER_BASE_URL}/${mesh.meshId}/graphql?api_key=${adobeIdIntegrationsForWorkspace.apiKey}`,
109
+ );
110
+ } else {
111
+ this.log(
112
+ 'Unable to subscribe API Key %s to API Mesh service',
113
+ adobeIdIntegrationsForWorkspace.apiKey,
114
+ );
115
+ }
116
+ } else {
117
+ this.log('Unable to create API Key');
118
+ }
119
+
120
+ return {
121
+ adobeIdIntegrationsForWorkspace,
122
+ sdkList,
123
+ mesh,
124
+ };
125
+ } else {
126
+ this.error(`Unable to create a mesh. Please try again. RequestId: ${global.requestId}`, {
127
+ exit: false,
128
+ });
129
+ }
130
+ } catch (error) {
131
+ this.log(error.message);
132
+
133
+ this.error(
134
+ `Unable to create a mesh. Please check the mesh configuration file and try again. If the error persists please contact support. RequestId: ${global.requestId}`,
135
+ );
60
136
  }
61
- } catch (error) {
62
- this.log(error.message);
137
+ } else {
138
+ this.log('Create cancelled');
63
139
 
64
- this.error(
65
- `Unable to create a mesh. Please check the mesh configuration file and try again. If the error persists please contact support. RequestId: ${global.requestId}`,
66
- );
140
+ return 'Create cancelled';
67
141
  }
68
142
  }
69
143
  }
@@ -13,54 +13,101 @@ const { Command } = require('@oclif/command');
13
13
 
14
14
  const logger = require('../../classes/logger');
15
15
  const { initSdk, initRequestId, promptConfirm } = require('../../helpers');
16
+ const { ignoreCacheFlag, autoConfirmActionFlag } = require('../../utils');
17
+ const {
18
+ getMeshId,
19
+ deleteMesh,
20
+ getApiKeyCredential,
21
+ unsubscribeCredentialFromMeshService,
22
+ } = require('../../lib/devConsole');
16
23
 
17
24
  require('dotenv').config();
18
25
 
19
26
  class DeleteCommand extends Command {
20
- static args = [{ name: 'meshId' }];
27
+ static flags = {
28
+ ignoreCache: ignoreCacheFlag,
29
+ autoConfirmAction: autoConfirmActionFlag,
30
+ };
21
31
 
22
32
  async run() {
23
33
  await initRequestId();
24
34
 
25
35
  logger.info(`RequestId: ${global.requestId}`);
26
36
 
27
- const { args } = this.parse(DeleteCommand);
37
+ const { flags } = await this.parse(DeleteCommand);
28
38
 
29
- if (!args.meshId) {
30
- this.error('Missing Mesh ID. Run aio api-mesh delete --help for more info.');
39
+ const ignoreCache = await flags.ignoreCache;
40
+ const autoConfirmAction = await flags.autoConfirmAction;
31
41
 
32
- return;
33
- }
34
-
35
- const { schemaServiceClient, imsOrgId, projectId, workspaceId } = await initSdk();
42
+ const { imsOrgId, projectId, workspaceId } = await initSdk({
43
+ ignoreCache,
44
+ });
36
45
 
37
- const shouldContinue = await promptConfirm(
38
- `Are you sure you want to delete the mesh: ${args.meshId}?`,
39
- );
40
-
41
- if (shouldContinue) {
42
- try {
43
- const response = await schemaServiceClient.deleteMesh(
44
- imsOrgId,
45
- projectId,
46
- workspaceId,
47
- args.meshId,
48
- );
46
+ let meshId = null;
49
47
 
50
- this.log('Successfully deleted mesh %s', args.meshId);
48
+ try {
49
+ meshId = await getMeshId(imsOrgId, projectId, workspaceId);
50
+ } catch (err) {
51
+ this.error(
52
+ `Unable to get mesh ID. Please check the details and try again. RequestId: ${global.requestId}`,
53
+ );
54
+ }
51
55
 
52
- return response;
53
- } catch (error) {
54
- this.log(error.message);
56
+ if (meshId) {
57
+ let shouldContinue = true;
55
58
 
56
- this.error(
57
- `Unable to delete mesh. Please check the details and try again. If the error persists please contact support. RequestId: ${global.requestId}`,
59
+ if (!autoConfirmAction) {
60
+ shouldContinue = await promptConfirm(
61
+ `Are you sure you want to delete the mesh: ${meshId}?`,
58
62
  );
59
63
  }
60
- } else {
61
- this.log('Delete cancelled');
62
64
 
63
- return 'Delete cancelled';
65
+ if (shouldContinue) {
66
+ try {
67
+ const deleteMeshResponse = await deleteMesh(imsOrgId, projectId, workspaceId, meshId);
68
+
69
+ if (deleteMeshResponse) {
70
+ this.log('Successfully deleted mesh %s', meshId);
71
+
72
+ const credential = await getApiKeyCredential(imsOrgId, projectId, workspaceId);
73
+
74
+ if (credential) {
75
+ const newSDKList = await unsubscribeCredentialFromMeshService(
76
+ imsOrgId,
77
+ projectId,
78
+ workspaceId,
79
+ credential.id_integration,
80
+ );
81
+
82
+ if (newSDKList) {
83
+ this.log('Successfully unsubscribed API Key %s', credential.client_id);
84
+ } else {
85
+ this.log('Unable to unsubscribe API Key %s', credential.client_id);
86
+ }
87
+ } else {
88
+ this.log('No API Key found to unsubscribe');
89
+ }
90
+
91
+ return deleteMeshResponse;
92
+ } else {
93
+ throw new Error('Unable to delete mesh');
94
+ }
95
+ } catch (error) {
96
+ this.log(error.message);
97
+
98
+ this.error(
99
+ `Unable to delete mesh. Please check the details and try again. If the error persists please contact support. RequestId: ${global.requestId}`,
100
+ );
101
+ }
102
+ } else {
103
+ this.log('Delete cancelled');
104
+
105
+ return 'Delete cancelled';
106
+ }
107
+ } else {
108
+ this.error(
109
+ `Unable to delete. No mesh found for Org(${imsOrgId}) -> Project(${projectId}) -> Workspace(${workspaceId}). Please check the details and try again.`,
110
+ );
64
111
  }
65
112
  }
66
113
  }
@@ -10,24 +10,40 @@ governing permissions and limitations under the License.
10
10
  */
11
11
 
12
12
  const { Command } = require('@oclif/command');
13
+
13
14
  const logger = require('../../classes/logger');
14
15
  const { initSdk, initRequestId } = require('../../helpers');
16
+ const CONSTANTS = require('../../constants');
17
+ const { ignoreCacheFlag } = require('../../utils');
18
+ const { describeMesh } = require('../../lib/devConsole');
15
19
 
16
20
  require('dotenv').config();
17
21
 
22
+ const { MULTITENANT_GRAPHQL_SERVER_BASE_URL } = CONSTANTS;
23
+
18
24
  class DescribeCommand extends Command {
25
+ static flags = {
26
+ ignoreCache: ignoreCacheFlag,
27
+ };
28
+
19
29
  async run() {
20
30
  await initRequestId();
21
31
 
22
32
  logger.info(`RequestId: ${global.requestId}`);
23
33
 
24
- const { schemaServiceClient, imsOrgId, projectId, workspaceId } = await initSdk();
34
+ const { flags } = await this.parse(DescribeCommand);
35
+
36
+ const ignoreCache = await flags.ignoreCache;
37
+
38
+ const { imsOrgId, projectId, workspaceId } = await initSdk({
39
+ ignoreCache,
40
+ });
25
41
 
26
42
  try {
27
- const meshDetails = await schemaServiceClient.describeMesh(imsOrgId, projectId, workspaceId);
43
+ const meshDetails = await describeMesh(imsOrgId, projectId, workspaceId);
28
44
 
29
45
  if (meshDetails) {
30
- const { meshId } = meshDetails;
46
+ const { meshId, apiKey } = meshDetails;
31
47
 
32
48
  if (meshId) {
33
49
  this.log('Successfully retrieved mesh details \n');
@@ -36,6 +52,14 @@ class DescribeCommand extends Command {
36
52
  this.log('Workspace ID: %s', workspaceId);
37
53
  this.log('Mesh ID: %s', meshId);
38
54
 
55
+ if (apiKey) {
56
+ this.log('API Key: %s', apiKey);
57
+ this.log(
58
+ 'Mesh Endpoint: %s\n',
59
+ `${MULTITENANT_GRAPHQL_SERVER_BASE_URL}/${meshId}/graphql?api_key=${apiKey}`,
60
+ );
61
+ }
62
+
39
63
  return meshDetails;
40
64
  } else {
41
65
  this.error(