@adobe/aio-cli-plugin-api-mesh 1.0.0-beta → 1.0.1-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 +8 -6
- package/oclif.manifest.json +1 -1
- package/package.json +92 -98
- package/src/classes/SchemaServiceClient.js +345 -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 +76 -0
- package/src/commands/api-mesh/__tests__/delete.test.js +82 -0
- package/src/commands/api-mesh/__tests__/get.test.js +76 -0
- package/src/commands/api-mesh/__tests__/update.test.js +77 -0
- package/src/commands/api-mesh/create.js +67 -0
- package/src/commands/api-mesh/delete.js +53 -0
- package/src/commands/api-mesh/get.js +69 -0
- package/src/commands/api-mesh/update.js +65 -0
- package/src/helpers.js +164 -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
|
@@ -0,0 +1,82 @@
|
|
|
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 mockConsoleCLIInstance = {};
|
|
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
|
+
|
|
41
|
+
jest.mock('@adobe/aio-cli-lib-console', () => ({
|
|
42
|
+
init: jest.fn().mockResolvedValue(mockConsoleCLIInstance),
|
|
43
|
+
cleanStdOut: jest.fn(),
|
|
44
|
+
}));
|
|
45
|
+
jest.mock('@adobe/aio-lib-ims');
|
|
46
|
+
|
|
47
|
+
const DeleteCommand = require('../delete');
|
|
48
|
+
const { SchemaServiceClient } = require('../../../classes/SchemaServiceClient');
|
|
49
|
+
|
|
50
|
+
describe('delete command tests', () => {
|
|
51
|
+
beforeEach(() => {
|
|
52
|
+
setDefaultMockConsoleCLI();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
afterEach(() => {
|
|
56
|
+
jest.restoreAllMocks();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('delete-mesh-missing-meshId', async () => {
|
|
60
|
+
const runResult = DeleteCommand.run([]);
|
|
61
|
+
|
|
62
|
+
return runResult.catch(err => {
|
|
63
|
+
expect(err).toHaveProperty(
|
|
64
|
+
'message',
|
|
65
|
+
expect.stringMatching(
|
|
66
|
+
/^Unable to delete mesh\. Please check the details and try again\. If the error persists please contact support\. RequestId: [a-z A-Z 0-9 -_]+/,
|
|
67
|
+
),
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('delete-mesh-with-meshId', async () => {
|
|
73
|
+
jest
|
|
74
|
+
.spyOn(SchemaServiceClient.prototype, 'deleteMesh')
|
|
75
|
+
.mockImplementation(() => Promise.resolve({}));
|
|
76
|
+
expect.assertions(1);
|
|
77
|
+
const meshId = 'sample_merchant';
|
|
78
|
+
const runResult = DeleteCommand.run([meshId]);
|
|
79
|
+
|
|
80
|
+
await expect(runResult).resolves.toEqual({});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
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('get-mesh-missing-meshId', async () => {
|
|
57
|
+
const runResult = GetCommand.run([]);
|
|
58
|
+
|
|
59
|
+
return runResult.catch(err => {
|
|
60
|
+
expect(err).toHaveProperty(
|
|
61
|
+
'message',
|
|
62
|
+
expect.stringMatching(
|
|
63
|
+
/^Unable to get mesh\. Please check the details and try again\. If the error persists please contact support\. RequestId: [a-z A-Z 0-9 -_]+/,
|
|
64
|
+
),
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('get-mesh-with-meshId', async () => {
|
|
70
|
+
jest.spyOn(SchemaServiceClient.prototype, 'getMesh').mockImplementation(meshId => mockGetMesh);
|
|
71
|
+
expect.assertions(1);
|
|
72
|
+
const meshId = 'sample_merchant';
|
|
73
|
+
const runResult = GetCommand.run([meshId]);
|
|
74
|
+
await expect(runResult).resolves.toEqual(mockGetMesh);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
const orgs = [{ id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' }];
|
|
16
|
+
const selectedOrg = { id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' };
|
|
17
|
+
|
|
18
|
+
const projects = [{ id: '5678', title: 'Project01' }];
|
|
19
|
+
const selectedProject = { id: '5678', title: 'Project01' };
|
|
20
|
+
|
|
21
|
+
const workspaces = [{ id: '123456789', title: 'Workspace01' }];
|
|
22
|
+
const selectedWorkspace = { id: '123456789', title: 'Workspace01' };
|
|
23
|
+
|
|
24
|
+
function setDefaultMockConsoleCLI() {
|
|
25
|
+
mockConsoleCLIInstance.getToken = jest.fn().mockReturnValue('test_token');
|
|
26
|
+
mockConsoleCLIInstance.getCliEnv = jest.fn().mockReturnValue('prod');
|
|
27
|
+
|
|
28
|
+
mockConsoleCLIInstance.getOrganizations = jest.fn().mockResolvedValue(orgs);
|
|
29
|
+
mockConsoleCLIInstance.promptForSelectOrganization = jest.fn().mockResolvedValue(selectedOrg);
|
|
30
|
+
|
|
31
|
+
mockConsoleCLIInstance.getProjects = jest.fn().mockResolvedValue(projects);
|
|
32
|
+
mockConsoleCLIInstance.promptForSelectProject = jest.fn().mockResolvedValue(selectedProject);
|
|
33
|
+
|
|
34
|
+
mockConsoleCLIInstance.getWorkspaces = jest.fn().mockResolvedValue(workspaces);
|
|
35
|
+
mockConsoleCLIInstance.promptForSelectWorkspace = jest.fn().mockResolvedValue(selectedWorkspace);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
jest.mock('@adobe/aio-cli-lib-console', () => ({
|
|
39
|
+
init: jest.fn().mockResolvedValue(mockConsoleCLIInstance),
|
|
40
|
+
cleanStdOut: jest.fn(),
|
|
41
|
+
}));
|
|
42
|
+
jest.mock('@adobe/aio-lib-ims');
|
|
43
|
+
const UpdateCommand = require('../update');
|
|
44
|
+
const { SchemaServiceClient } = require('../../../classes/SchemaServiceClient');
|
|
45
|
+
const mockUpdateMesh = require('../../__fixtures__/sample_mesh.json');
|
|
46
|
+
|
|
47
|
+
describe('update command tests', () => {
|
|
48
|
+
beforeEach(() => {
|
|
49
|
+
setDefaultMockConsoleCLI();
|
|
50
|
+
const response = mockUpdateMesh;
|
|
51
|
+
jest.spyOn(SchemaServiceClient.prototype, 'updateMesh').mockImplementation(data => response);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
afterEach(() => {
|
|
55
|
+
jest.restoreAllMocks();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('update-mesh-missing-meshId-file', async () => {
|
|
59
|
+
expect.assertions(2);
|
|
60
|
+
const runResult = UpdateCommand.run([]);
|
|
61
|
+
await expect(runResult instanceof Promise).toBeTruthy();
|
|
62
|
+
await expect(runResult).rejects.toEqual(
|
|
63
|
+
new Error(
|
|
64
|
+
'Unable to read the mesh configuration file provided. Please check the file and try again.',
|
|
65
|
+
),
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
test('update-mesh-with-configuration', async () => {
|
|
69
|
+
expect.assertions(2);
|
|
70
|
+
const runResult = UpdateCommand.run([
|
|
71
|
+
'sample_merchant',
|
|
72
|
+
'src/commands/__fixtures__/sample_mesh.json',
|
|
73
|
+
]);
|
|
74
|
+
await expect(runResult instanceof Promise).toBeTruthy();
|
|
75
|
+
await expect(runResult).resolves.toEqual(mockUpdateMesh);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
const { schemaServiceClient, imsOrgId, projectId, workspaceId } = await initSdk();
|
|
28
|
+
|
|
29
|
+
let data;
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
data = JSON.parse(await readFile(args.file, 'utf8'));
|
|
33
|
+
} catch (error) {
|
|
34
|
+
logger.error(error);
|
|
35
|
+
|
|
36
|
+
this.log(error.message);
|
|
37
|
+
this.error(
|
|
38
|
+
'Unable to read the mesh configuration file provided. Please check the file and try again.',
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
const mesh = await schemaServiceClient.createMesh(imsOrgId, projectId, workspaceId, data);
|
|
44
|
+
|
|
45
|
+
if (mesh) {
|
|
46
|
+
this.log('Successfully created mesh %s', mesh.meshId);
|
|
47
|
+
this.log(JSON.stringify(mesh, null, 2));
|
|
48
|
+
|
|
49
|
+
return mesh;
|
|
50
|
+
} else {
|
|
51
|
+
this.error(`Unable to create a mesh. Please try again. RequestId: ${global.requestId}`, {
|
|
52
|
+
exit: false,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
} catch (error) {
|
|
56
|
+
this.log(error.message);
|
|
57
|
+
|
|
58
|
+
this.error(
|
|
59
|
+
`Unable to create a mesh. Please check the mesh configuration file and try again. If the error persists please contact support. RequestId: ${global.requestId}`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
CreateCommand.description = 'Create a mesh with the given config.';
|
|
66
|
+
|
|
67
|
+
module.exports = CreateCommand;
|
|
@@ -0,0 +1,53 @@
|
|
|
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 DeleteCommand extends Command {
|
|
19
|
+
static args = [{ name: 'meshId' }];
|
|
20
|
+
|
|
21
|
+
async run() {
|
|
22
|
+
await initRequestId();
|
|
23
|
+
|
|
24
|
+
logger.info(`RequestId: ${global.requestId}`);
|
|
25
|
+
|
|
26
|
+
const { args } = this.parse(DeleteCommand);
|
|
27
|
+
|
|
28
|
+
const { schemaServiceClient, imsOrgId, projectId, workspaceId } = await initSdk();
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const response = await schemaServiceClient.deleteMesh(
|
|
32
|
+
imsOrgId,
|
|
33
|
+
projectId,
|
|
34
|
+
workspaceId,
|
|
35
|
+
args.meshId,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
this.log('Successfully deleted mesh %s', args.meshId);
|
|
39
|
+
|
|
40
|
+
return response;
|
|
41
|
+
} catch (error) {
|
|
42
|
+
this.log(error.message);
|
|
43
|
+
|
|
44
|
+
this.error(
|
|
45
|
+
`Unable to delete mesh. Please check the details and try again. If the error persists please contact support. RequestId: ${global.requestId}`,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
DeleteCommand.description = 'Delete the config of a given mesh';
|
|
52
|
+
|
|
53
|
+
module.exports = DeleteCommand;
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
const { schemaServiceClient, imsOrgId, projectId, workspaceId } = await initSdk();
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
const mesh = await schemaServiceClient.getMesh(imsOrgId, projectId, workspaceId, args.meshId);
|
|
33
|
+
|
|
34
|
+
if (mesh) {
|
|
35
|
+
this.log('Successfully retrieved mesh %s', JSON.stringify(mesh, null, 2));
|
|
36
|
+
|
|
37
|
+
if (args.file) {
|
|
38
|
+
try {
|
|
39
|
+
const { meshConfig } = mesh;
|
|
40
|
+
await writeFile(args.file, JSON.stringify({ meshConfig }, null, 2));
|
|
41
|
+
|
|
42
|
+
this.log('Successfully wrote mesh to file %s', args.file);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
this.log('Unable to write mesh to file %s', args.file);
|
|
45
|
+
|
|
46
|
+
logger.error(error);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return mesh;
|
|
51
|
+
} else {
|
|
52
|
+
this.error(
|
|
53
|
+
`Unable to get mesh with the ID ${args.meshId}. Please check the mesh ID and try again. RequestId: ${global.requestId}`,
|
|
54
|
+
{ exit: false },
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
} catch (error) {
|
|
58
|
+
this.log(error.message);
|
|
59
|
+
|
|
60
|
+
this.error(
|
|
61
|
+
`Unable to get mesh. Please check the details and try again. If the error persists please contact support. RequestId: ${global.requestId}`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
GetCommand.description = 'Get the config of a given mesh';
|
|
68
|
+
|
|
69
|
+
module.exports = GetCommand;
|
|
@@ -0,0 +1,65 @@
|
|
|
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 logger = require('../../classes/logger');
|
|
15
|
+
const { initSdk, initRequestId } = require('../../helpers');
|
|
16
|
+
|
|
17
|
+
class UpdateCommand extends Command {
|
|
18
|
+
static args = [{ name: 'meshId' }, { name: 'file' }];
|
|
19
|
+
|
|
20
|
+
async run() {
|
|
21
|
+
await initRequestId();
|
|
22
|
+
|
|
23
|
+
logger.info(`RequestId: ${global.requestId}`);
|
|
24
|
+
|
|
25
|
+
const { args } = this.parse(UpdateCommand);
|
|
26
|
+
|
|
27
|
+
const { schemaServiceClient, imsOrgId, projectId, workspaceId } = await initSdk();
|
|
28
|
+
let data;
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
data = JSON.parse(await readFile(args.file, 'utf8'));
|
|
32
|
+
} catch (error) {
|
|
33
|
+
logger.error(error);
|
|
34
|
+
|
|
35
|
+
this.log(error.message);
|
|
36
|
+
this.error(
|
|
37
|
+
'Unable to read the mesh configuration file provided. Please check the file and try again.',
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const response = await schemaServiceClient.updateMesh(
|
|
43
|
+
imsOrgId,
|
|
44
|
+
projectId,
|
|
45
|
+
workspaceId,
|
|
46
|
+
args.meshId,
|
|
47
|
+
data,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
this.log('Successfully updated the mesh with the id: %s', args.meshId);
|
|
51
|
+
|
|
52
|
+
return response;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
this.log(error.message);
|
|
55
|
+
|
|
56
|
+
this.error(
|
|
57
|
+
`Unable to update the mesh. Please check the mesh configuration file and try again. If the error persists please contact support. RequestId: ${global.requestId}`,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
UpdateCommand.description = 'Update a mesh with the given config.';
|
|
64
|
+
|
|
65
|
+
module.exports = UpdateCommand;
|