@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.
@@ -0,0 +1,104 @@
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
+ jest.mock('@adobe/aio-lib-env');
14
+ jest.mock('@adobe/aio-cli-lib-console');
15
+
16
+ const inquirer = require('inquirer');
17
+
18
+ const mockConsoleCLIInstance = {};
19
+
20
+ const orgs = [{ id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' }];
21
+ const selectedOrg = { id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' };
22
+
23
+ const projects = [{ id: '5678', title: 'Project01' }];
24
+ const selectedProject = { id: '5678', title: 'Project01' };
25
+
26
+ const workspaces = [{ id: '123456789', title: 'Workspace01' }];
27
+ const selectedWorkspace = { id: '123456789', title: 'Workspace01' };
28
+
29
+ function setDefaultMockConsoleCLI() {
30
+ mockConsoleCLIInstance.getToken = jest.fn().mockReturnValue('test_token');
31
+ mockConsoleCLIInstance.getCliEnv = jest.fn().mockReturnValue('prod');
32
+
33
+ mockConsoleCLIInstance.getOrganizations = jest.fn().mockResolvedValue(orgs);
34
+ mockConsoleCLIInstance.promptForSelectOrganization = jest.fn().mockResolvedValue(selectedOrg);
35
+
36
+ mockConsoleCLIInstance.getProjects = jest.fn().mockResolvedValue(projects);
37
+ mockConsoleCLIInstance.promptForSelectProject = jest.fn().mockResolvedValue(selectedProject);
38
+
39
+ mockConsoleCLIInstance.getWorkspaces = jest.fn().mockResolvedValue(workspaces);
40
+ mockConsoleCLIInstance.promptForSelectWorkspace = jest.fn().mockResolvedValue(selectedWorkspace);
41
+ }
42
+
43
+ jest.mock('@adobe/aio-cli-lib-console', () => ({
44
+ init: jest.fn().mockResolvedValue(mockConsoleCLIInstance),
45
+ cleanStdOut: jest.fn(),
46
+ }));
47
+
48
+ jest.mock('@adobe/aio-lib-ims');
49
+
50
+ jest.mock('inquirer', () => ({
51
+ createPromptModule: jest.fn().mockReturnValue(
52
+ jest.fn().mockResolvedValue({
53
+ res: true,
54
+ }),
55
+ ),
56
+ }));
57
+
58
+ const DeleteCommand = require('../delete');
59
+ const { SchemaServiceClient } = require('../../../classes/SchemaServiceClient');
60
+
61
+ describe('delete command tests', () => {
62
+ beforeEach(() => {
63
+ setDefaultMockConsoleCLI();
64
+ });
65
+
66
+ afterEach(() => {
67
+ jest.restoreAllMocks();
68
+ });
69
+
70
+ test('should fail if mesh id is missing', async () => {
71
+ const runResult = DeleteCommand.run([]);
72
+
73
+ return runResult.catch(err => {
74
+ expect(err).toHaveProperty(
75
+ 'message',
76
+ expect.stringMatching(/^Missing Mesh ID. Run aio api-mesh delete --help for more info/),
77
+ );
78
+ });
79
+ });
80
+
81
+ test('should delete if correct args are provided', async () => {
82
+ jest
83
+ .spyOn(SchemaServiceClient.prototype, 'deleteMesh')
84
+ .mockImplementation(() => Promise.resolve({}));
85
+ expect.assertions(1);
86
+ const meshId = 'sample_merchant';
87
+ const runResult = DeleteCommand.run([meshId]);
88
+
89
+ await expect(runResult).resolves.toEqual({});
90
+ });
91
+
92
+ test('should not delete if user prompt returns false', async () => {
93
+ inquirer.createPromptModule.mockReturnValue(
94
+ jest.fn().mockResolvedValue({
95
+ res: false,
96
+ }),
97
+ );
98
+
99
+ const meshId = 'sample_merchant';
100
+ const runResult = await DeleteCommand.run([meshId]);
101
+
102
+ expect(runResult).toBe('Delete cancelled');
103
+ });
104
+ });
@@ -0,0 +1,79 @@
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
+ jest.mock('@adobe/aio-lib-env');
15
+ jest.mock('@adobe/aio-cli-lib-console');
16
+ const orgs = [{ id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' }];
17
+ const selectedOrg = { id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' };
18
+
19
+ const projects = [{ id: '5678', title: 'Project01' }];
20
+ const selectedProject = { id: '5678', title: 'Project01' };
21
+
22
+ const workspaces = [{ id: '123456789', title: 'Workspace01' }];
23
+ const selectedWorkspace = { id: '123456789', title: 'Workspace01' };
24
+
25
+ function setDefaultMockConsoleCLI() {
26
+ mockConsoleCLIInstance.getToken = jest.fn().mockReturnValue('test_token');
27
+ mockConsoleCLIInstance.getCliEnv = jest.fn().mockReturnValue('prod');
28
+
29
+ mockConsoleCLIInstance.getOrganizations = jest.fn().mockResolvedValue(orgs);
30
+ mockConsoleCLIInstance.promptForSelectOrganization = jest.fn().mockResolvedValue(selectedOrg);
31
+
32
+ mockConsoleCLIInstance.getProjects = jest.fn().mockResolvedValue(projects);
33
+ mockConsoleCLIInstance.promptForSelectProject = jest.fn().mockResolvedValue(selectedProject);
34
+
35
+ mockConsoleCLIInstance.getWorkspaces = jest.fn().mockResolvedValue(workspaces);
36
+ mockConsoleCLIInstance.promptForSelectWorkspace = jest.fn().mockResolvedValue(selectedWorkspace);
37
+ }
38
+
39
+ jest.mock('@adobe/aio-cli-lib-console', () => ({
40
+ init: jest.fn().mockResolvedValue(mockConsoleCLIInstance),
41
+ cleanStdOut: jest.fn(),
42
+ }));
43
+
44
+ jest.mock('@adobe/aio-lib-ims');
45
+
46
+ const DescribeCommand = require('../describe');
47
+ const { SchemaServiceClient } = require('../../../classes/SchemaServiceClient');
48
+
49
+ describe('describe command tests', () => {
50
+ beforeEach(() => {
51
+ setDefaultMockConsoleCLI();
52
+ });
53
+
54
+ afterEach(() => {
55
+ jest.restoreAllMocks();
56
+ });
57
+
58
+ test('should error if wrong details are provided', async () => {
59
+ const runResult = DescribeCommand.run([]);
60
+
61
+ return runResult.catch(err => {
62
+ expect(err).toHaveProperty(
63
+ 'message',
64
+ expect.stringMatching(
65
+ /^Unable to get mesh details\. Please check the details and try again\. If the error persists please contact support\. RequestId: [a-z A-Z 0-9 -_]+/,
66
+ ),
67
+ );
68
+ });
69
+ });
70
+
71
+ test('should return meshId if correct details are provided', async () => {
72
+ const meshId = 'sample-mesh-id';
73
+ jest.spyOn(SchemaServiceClient.prototype, 'describeMesh').mockResolvedValue({ meshId });
74
+
75
+ const runResult = await DescribeCommand.run();
76
+
77
+ await expect(runResult).toEqual({ meshId });
78
+ });
79
+ });
@@ -0,0 +1,74 @@
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
+ jest.mock('@adobe/aio-lib-env');
15
+ jest.mock('@adobe/aio-cli-lib-console');
16
+ const orgs = [{ id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' }];
17
+ const selectedOrg = { id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' };
18
+
19
+ const projects = [{ id: '5678', title: 'Project01' }];
20
+ const selectedProject = { id: '5678', title: 'Project01' };
21
+
22
+ const workspaces = [{ id: '123456789', title: 'Workspace01' }];
23
+ const selectedWorkspace = { id: '123456789', title: 'Workspace01' };
24
+
25
+ function setDefaultMockConsoleCLI() {
26
+ mockConsoleCLIInstance.getToken = jest.fn().mockReturnValue('test_token');
27
+ mockConsoleCLIInstance.getCliEnv = jest.fn().mockReturnValue('prod');
28
+
29
+ mockConsoleCLIInstance.getOrganizations = jest.fn().mockResolvedValue(orgs);
30
+ mockConsoleCLIInstance.promptForSelectOrganization = jest.fn().mockResolvedValue(selectedOrg);
31
+
32
+ mockConsoleCLIInstance.getProjects = jest.fn().mockResolvedValue(projects);
33
+ mockConsoleCLIInstance.promptForSelectProject = jest.fn().mockResolvedValue(selectedProject);
34
+
35
+ mockConsoleCLIInstance.getWorkspaces = jest.fn().mockResolvedValue(workspaces);
36
+ mockConsoleCLIInstance.promptForSelectWorkspace = jest.fn().mockResolvedValue(selectedWorkspace);
37
+ }
38
+
39
+ jest.mock('@adobe/aio-cli-lib-console', () => ({
40
+ init: jest.fn().mockResolvedValue(mockConsoleCLIInstance),
41
+ cleanStdOut: jest.fn(),
42
+ }));
43
+ jest.mock('@adobe/aio-lib-ims');
44
+ const GetCommand = require('../get');
45
+ const { SchemaServiceClient } = require('../../../classes/SchemaServiceClient');
46
+ const mockGetMesh = require('../../__fixtures__/sample_mesh.json');
47
+
48
+ describe('get command tests', () => {
49
+ beforeEach(() => {
50
+ setDefaultMockConsoleCLI();
51
+ });
52
+ afterEach(() => {
53
+ jest.restoreAllMocks();
54
+ });
55
+
56
+ test('should fail if mesh id is missing', async () => {
57
+ const runResult = GetCommand.run([]);
58
+
59
+ return runResult.catch(err => {
60
+ expect(err).toHaveProperty(
61
+ 'message',
62
+ expect.stringMatching(/^Missing Mesh ID. Run aio api-mesh get --help for more info./),
63
+ );
64
+ });
65
+ });
66
+
67
+ test('should pass if mesh id is provided', async () => {
68
+ jest.spyOn(SchemaServiceClient.prototype, 'getMesh').mockImplementation(meshId => mockGetMesh);
69
+ expect.assertions(1);
70
+ const meshId = 'sample_merchant';
71
+ const runResult = GetCommand.run([meshId]);
72
+ await expect(runResult).resolves.toEqual(mockGetMesh);
73
+ });
74
+ });
@@ -0,0 +1,113 @@
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 inquirer = require('inquirer');
14
+
15
+ 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
+
20
+ const projects = [{ id: '5678', title: 'Project01' }];
21
+ const selectedProject = { id: '5678', title: 'Project01' };
22
+
23
+ const workspaces = [{ id: '123456789', title: 'Workspace01' }];
24
+ const selectedWorkspace = { id: '123456789', title: 'Workspace01' };
25
+
26
+ function setDefaultMockConsoleCLI() {
27
+ mockConsoleCLIInstance.getToken = jest.fn().mockReturnValue('test_token');
28
+ mockConsoleCLIInstance.getCliEnv = jest.fn().mockReturnValue('prod');
29
+
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
+ }
39
+
40
+ jest.mock('inquirer', () => ({
41
+ createPromptModule: jest.fn().mockReturnValue(
42
+ jest.fn().mockResolvedValue({
43
+ res: true,
44
+ }),
45
+ ),
46
+ }));
47
+
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');
53
+
54
+ const UpdateCommand = require('../update');
55
+ const { SchemaServiceClient } = require('../../../classes/SchemaServiceClient');
56
+ const mockUpdateMesh = require('../../__fixtures__/sample_mesh.json');
57
+
58
+ describe('update command tests', () => {
59
+ beforeEach(() => {
60
+ setDefaultMockConsoleCLI();
61
+ const response = mockUpdateMesh;
62
+ jest.spyOn(SchemaServiceClient.prototype, 'updateMesh').mockImplementation(data => response);
63
+ });
64
+
65
+ afterEach(() => {
66
+ jest.restoreAllMocks();
67
+ });
68
+
69
+ 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();
73
+ await expect(runResult).rejects.toEqual(
74
+ new Error('Missing required args. Run aio api-mesh update --help for more info.'),
75
+ );
76
+ });
77
+
78
+ 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();
82
+ await expect(runResult).rejects.toEqual(
83
+ new Error(
84
+ 'Unable to read the mesh configuration file provided. Please check the file and try again.',
85
+ ),
86
+ );
87
+ });
88
+
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);
97
+ });
98
+
99
+ test('should not update if user prompt returns false', async () => {
100
+ inquirer.createPromptModule.mockReturnValue(
101
+ jest.fn().mockResolvedValue({
102
+ res: false,
103
+ }),
104
+ );
105
+
106
+ const runResult = await UpdateCommand.run([
107
+ 'sample_merchant',
108
+ 'src/commands/__fixtures__/sample_mesh.json',
109
+ ]);
110
+
111
+ expect(runResult).toBe('Update cancelled');
112
+ });
113
+ });
@@ -0,0 +1,73 @@
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 { Command } = require('@oclif/command');
13
+ const { readFile } = require('fs/promises');
14
+ const { initSdk, initRequestId } = require('../../helpers');
15
+ const logger = require('../../classes/logger');
16
+
17
+ class CreateCommand extends Command {
18
+ static args = [{ name: 'file' }];
19
+
20
+ async run() {
21
+ await initRequestId();
22
+
23
+ logger.info(`RequestId: ${global.requestId}`);
24
+
25
+ const { args } = this.parse(CreateCommand);
26
+
27
+ if (!args.file) {
28
+ this.error('Missing file path. Run aio api-mesh create --help for more info.');
29
+
30
+ return;
31
+ }
32
+
33
+ const { schemaServiceClient, imsOrgId, projectId, workspaceId } = await initSdk();
34
+
35
+ let data;
36
+
37
+ try {
38
+ data = JSON.parse(await readFile(args.file, 'utf8'));
39
+ } catch (error) {
40
+ logger.error(error);
41
+
42
+ this.log(error.message);
43
+ this.error(
44
+ 'Unable to read the mesh configuration file provided. Please check the file and try again.',
45
+ );
46
+ }
47
+
48
+ try {
49
+ const mesh = await schemaServiceClient.createMesh(imsOrgId, projectId, workspaceId, data);
50
+
51
+ if (mesh) {
52
+ this.log('Successfully created mesh %s', mesh.meshId);
53
+ this.log(JSON.stringify(mesh, null, 2));
54
+
55
+ return mesh;
56
+ } else {
57
+ this.error(`Unable to create a mesh. Please try again. RequestId: ${global.requestId}`, {
58
+ exit: false,
59
+ });
60
+ }
61
+ } catch (error) {
62
+ this.log(error.message);
63
+
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
+ );
67
+ }
68
+ }
69
+ }
70
+
71
+ CreateCommand.description = 'Create a mesh with the given config.';
72
+
73
+ module.exports = CreateCommand;
@@ -0,0 +1,70 @@
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 { Command } = require('@oclif/command');
13
+
14
+ const logger = require('../../classes/logger');
15
+ const { initSdk, initRequestId, promptConfirm } = require('../../helpers');
16
+
17
+ require('dotenv').config();
18
+
19
+ class DeleteCommand extends Command {
20
+ static args = [{ name: 'meshId' }];
21
+
22
+ async run() {
23
+ await initRequestId();
24
+
25
+ logger.info(`RequestId: ${global.requestId}`);
26
+
27
+ const { args } = this.parse(DeleteCommand);
28
+
29
+ if (!args.meshId) {
30
+ this.error('Missing Mesh ID. Run aio api-mesh delete --help for more info.');
31
+
32
+ return;
33
+ }
34
+
35
+ const { schemaServiceClient, imsOrgId, projectId, workspaceId } = await initSdk();
36
+
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
+ );
49
+
50
+ this.log('Successfully deleted mesh %s', args.meshId);
51
+
52
+ return response;
53
+ } catch (error) {
54
+ this.log(error.message);
55
+
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}`,
58
+ );
59
+ }
60
+ } else {
61
+ this.log('Delete cancelled');
62
+
63
+ return 'Delete cancelled';
64
+ }
65
+ }
66
+ }
67
+
68
+ DeleteCommand.description = 'Delete the config of a given mesh';
69
+
70
+ module.exports = DeleteCommand;
@@ -0,0 +1,61 @@
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 { Command } = require('@oclif/command');
13
+ const logger = require('../../classes/logger');
14
+ const { initSdk, initRequestId } = require('../../helpers');
15
+
16
+ require('dotenv').config();
17
+
18
+ class DescribeCommand extends Command {
19
+ async run() {
20
+ await initRequestId();
21
+
22
+ logger.info(`RequestId: ${global.requestId}`);
23
+
24
+ const { schemaServiceClient, imsOrgId, projectId, workspaceId } = await initSdk();
25
+
26
+ try {
27
+ const meshDetails = await schemaServiceClient.describeMesh(imsOrgId, projectId, workspaceId);
28
+
29
+ if (meshDetails) {
30
+ const { meshId } = meshDetails;
31
+
32
+ if (meshId) {
33
+ this.log('Successfully retrieved mesh details \n');
34
+ this.log('Org ID: %s', imsOrgId);
35
+ this.log('Project ID: %s', projectId);
36
+ this.log('Workspace ID: %s', workspaceId);
37
+ this.log('Mesh ID: %s', meshId);
38
+
39
+ return meshDetails;
40
+ } else {
41
+ this.error(
42
+ `Unable to get mesh details. Please check the details and try again. RequestId: ${global.requestId}`,
43
+ { exit: false },
44
+ );
45
+ }
46
+ } else {
47
+ throw new Error(`Unable to get mesh details`);
48
+ }
49
+ } catch (error) {
50
+ this.log(error.message);
51
+
52
+ this.error(
53
+ `Unable to get mesh details. Please check the details and try again. If the error persists please contact support. RequestId: ${global.requestId}`,
54
+ );
55
+ }
56
+ }
57
+ }
58
+
59
+ DescribeCommand.description = 'Get details of a mesh';
60
+
61
+ module.exports = DescribeCommand;
@@ -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
+ 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 { Command } = require('@oclif/command');
13
+ const { writeFile } = require('fs/promises');
14
+ const logger = require('../../classes/logger');
15
+ const { initSdk, initRequestId } = require('../../helpers');
16
+
17
+ require('dotenv').config();
18
+
19
+ class GetCommand extends Command {
20
+ static args = [{ name: 'meshId' }, { name: 'file' }];
21
+
22
+ async run() {
23
+ await initRequestId();
24
+
25
+ logger.info(`RequestId: ${global.requestId}`);
26
+
27
+ const { args } = this.parse(GetCommand);
28
+
29
+ if (!args.meshId) {
30
+ this.error('Missing Mesh ID. Run aio api-mesh get --help for more info.');
31
+
32
+ return;
33
+ }
34
+
35
+ const { schemaServiceClient, imsOrgId, projectId, workspaceId } = await initSdk();
36
+
37
+ try {
38
+ const mesh = await schemaServiceClient.getMesh(imsOrgId, projectId, workspaceId, args.meshId);
39
+
40
+ if (mesh) {
41
+ this.log('Successfully retrieved mesh %s', JSON.stringify(mesh, null, 2));
42
+
43
+ if (args.file) {
44
+ try {
45
+ const { meshConfig } = mesh;
46
+ await writeFile(args.file, JSON.stringify({ meshConfig }, null, 2));
47
+
48
+ this.log('Successfully wrote mesh to file %s', args.file);
49
+ } catch (error) {
50
+ this.log('Unable to write mesh to file %s', args.file);
51
+
52
+ logger.error(error);
53
+ }
54
+ }
55
+
56
+ return mesh;
57
+ } else {
58
+ this.error(
59
+ `Unable to get mesh with the ID ${args.meshId}. Please check the mesh ID and try again. RequestId: ${global.requestId}`,
60
+ { exit: false },
61
+ );
62
+ }
63
+ } catch (error) {
64
+ this.log(error.message);
65
+
66
+ this.error(
67
+ `Unable to get mesh. Please check the details and try again. If the error persists please contact support. RequestId: ${global.requestId}`,
68
+ );
69
+ }
70
+ }
71
+ }
72
+
73
+ GetCommand.description = 'Get the config of a given mesh';
74
+
75
+ module.exports = GetCommand;