@adobe/aio-cli-plugin-api-mesh 5.1.0 → 5.1.1-beta.2

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.
@@ -1 +1 @@
1
- {"version":"5.1.0","commands":{"PLUGINNAME":{"id":"PLUGINNAME","description":"Your description here","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":["$ aio PLUGINNAME:some_command"],"flags":{"someflag":{"name":"someflag","type":"option","char":"f","description":"this is some flag"}},"args":[]},"api-mesh:create":{"id":"api-mesh:create","description":"Create a mesh with the given config.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"autoConfirmAction":{"name":"autoConfirmAction","type":"boolean","char":"c","description":"Auto confirm action prompt. CLI will not check for user approval before executing the action.","allowNo":false},"json":{"name":"json","type":"boolean","description":"Output JSON","allowNo":false},"env":{"name":"env","type":"option","char":"e","description":"Path to env file","default":".env"},"secrets":{"name":"secrets","type":"option","char":"s","description":"Path to secrets file","default":false}},"args":[{"name":"file"}]},"api-mesh:delete":{"id":"api-mesh:delete","description":"Delete the config of a given mesh","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"autoConfirmAction":{"name":"autoConfirmAction","type":"boolean","char":"c","description":"Auto confirm action prompt. CLI will not check for user approval before executing the action.","allowNo":false}},"args":[]},"api-mesh:describe":{"id":"api-mesh:describe","description":"Get details of a mesh","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false}},"args":[]},"api-mesh:get":{"id":"api-mesh:get","description":"Get the config of a given mesh","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"json":{"name":"json","type":"boolean","description":"Output JSON","allowNo":false}},"args":[{"name":"file"}]},"api-mesh:init":{"id":"api-mesh:init","description":"This command will create a workspace where you can organise your API mesh configuration and other files","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":[{"description":"API mesh workspace init","command":"aio api-mesh init commerce-mesh"},{"description":"API mesh workspace init with flags","command":"aio api-mesh init commerce-mesh --path ./mesh_projects/test_mesh --git y --packageManager yarn"}],"flags":{"path":{"name":"path","type":"option","char":"p","default":"."},"packageManager":{"name":"packageManager","type":"option","char":"m","options":["npm","yarn"]},"git":{"name":"git","type":"option","char":"g","options":["y","n"]}},"args":[{"name":"projectName","description":"Project name","required":true}]},"api-mesh:log-get-bulk":{"id":"api-mesh:log-get-bulk","description":"Download all mesh logs for a selected time period.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"startTime":{"name":"startTime","type":"option","description":"Start time for the logs in UTC","required":true},"endTime":{"name":"endTime","type":"option","description":"End time for the logs in UTC","required":true},"filename":{"name":"filename","type":"option","description":"Path to the output file for logs","required":true}},"args":[]},"api-mesh:log-get":{"id":"api-mesh:log-get","description":"Get the Log of a given mesh by RayId","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false}},"args":[{"name":"rayId","description":"Fetch a single log by rayID","required":true}]},"api-mesh:log-list":{"id":"api-mesh:log-list","description":"Get recent logs of requests made to the API Mesh.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"filename":{"name":"filename","type":"option","description":"Name of CSV file to export the recent logs to"}},"args":[]},"api-mesh:run":{"id":"api-mesh:run","description":"Run a local development server that builds and compiles a mesh locally","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":[],"flags":{"port":{"name":"port","type":"option","char":"p","description":"Port number for the local dev server"},"debug":{"name":"debug","type":"boolean","description":"Enable debugging mode","allowNo":false},"env":{"name":"env","type":"option","char":"e","description":"Path to env file","default":".env"},"autoConfirmAction":{"name":"autoConfirmAction","type":"boolean","char":"c","description":"Auto confirm action prompt. CLI will not check for user approval before executing the action.","allowNo":false},"select":{"name":"select","type":"boolean","description":"Retrieve existing artifacts from the mesh","allowNo":false},"secrets":{"name":"secrets","type":"option","char":"s","description":"Path to secrets file","default":false}},"args":[{"name":"file","description":"Mesh File"}]},"api-mesh:status":{"id":"api-mesh:status","description":"Get a mesh status with a given meshid.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false}},"args":[]},"api-mesh:update":{"id":"api-mesh:update","description":"Update a mesh with the given config.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"autoConfirmAction":{"name":"autoConfirmAction","type":"boolean","char":"c","description":"Auto confirm action prompt. CLI will not check for user approval before executing the action.","allowNo":false},"env":{"name":"env","type":"option","char":"e","description":"Path to env file","default":".env"},"secrets":{"name":"secrets","type":"option","char":"s","description":"Path to secrets file","default":false}},"args":[{"name":"file"}]},"api-mesh:source:discover":{"id":"api-mesh:source:discover","description":"Return the list of avaliable sources","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"confirm":{"name":"confirm","type":"boolean","char":"c","description":"Auto confirm install action prompt. CLI will not check ask user to install source.","allowNo":false}},"args":[]},"api-mesh:source:get":{"id":"api-mesh:source:get","description":"Command returns the content of a specific source.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":["$ aio api-mesh:source:get -s=<version>@<source_name>","$ aio api-mesh:source:get -s<source_name>","$ aio api-mesh:source:get -m"],"flags":{"confirm":{"name":"confirm","type":"boolean","char":"c","description":"Auto confirm print action prompt. CLI will not check ask user to print source.","allowNo":false},"source":{"name":"source","type":"option","char":"s","description":"Source name"},"multiple":{"name":"multiple","type":"boolean","char":"m","description":"Select multiple sources","allowNo":false}},"args":[]},"api-mesh:source:install":{"id":"api-mesh:source:install","description":"Command to install the source to your API mesh.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":["$ aio api-mesh:source:install <version>@<source_name>","$ aio api-mesh:source:install <source_name> -v <variable_name>=<variable_value>","$ aio api-mesh:source:install <source_name> -f <path_to_variables_file>"],"flags":{"source":{"name":"source","type":"option","char":"s","description":"Source name"},"confirm":{"name":"confirm","type":"boolean","char":"c","description":"Auto confirm override action prompt. CLI will not check ask user to override source.","allowNo":false},"variable":{"name":"variable","type":"option","char":"v","description":"Variables required for the source"},"variable-file":{"name":"variable-file","type":"option","char":"f","description":"Variables file path"},"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false}},"args":[{"name":"source"}]}}}
1
+ {"version":"5.1.1-beta.2","commands":{"PLUGINNAME":{"id":"PLUGINNAME","description":"Your description here","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":["$ aio PLUGINNAME:some_command"],"flags":{"someflag":{"name":"someflag","type":"option","char":"f","description":"this is some flag"}},"args":[]},"api-mesh:create":{"id":"api-mesh:create","description":"Create a mesh with the given config.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"autoConfirmAction":{"name":"autoConfirmAction","type":"boolean","char":"c","description":"Auto confirm action prompt. CLI will not check for user approval before executing the action.","allowNo":false},"json":{"name":"json","type":"boolean","description":"Output JSON","allowNo":false},"env":{"name":"env","type":"option","char":"e","description":"Path to env file","default":".env"},"secrets":{"name":"secrets","type":"option","char":"s","description":"Path to secrets file","default":false}},"args":[{"name":"file"}]},"api-mesh:delete":{"id":"api-mesh:delete","description":"Delete the config of a given mesh","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"autoConfirmAction":{"name":"autoConfirmAction","type":"boolean","char":"c","description":"Auto confirm action prompt. CLI will not check for user approval before executing the action.","allowNo":false}},"args":[]},"api-mesh:describe":{"id":"api-mesh:describe","description":"Get details of a mesh","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false}},"args":[]},"api-mesh:get":{"id":"api-mesh:get","description":"Get the config of a given mesh","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"json":{"name":"json","type":"boolean","description":"Output JSON","allowNo":false}},"args":[{"name":"file"}]},"api-mesh:init":{"id":"api-mesh:init","description":"This command will create a workspace where you can organise your API mesh configuration and other files","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":[{"description":"API mesh workspace init","command":"aio api-mesh init commerce-mesh"},{"description":"API mesh workspace init with flags","command":"aio api-mesh init commerce-mesh --path ./mesh_projects/test_mesh --git y --packageManager yarn"}],"flags":{"path":{"name":"path","type":"option","char":"p","default":"."},"packageManager":{"name":"packageManager","type":"option","char":"m","options":["npm","yarn"]},"git":{"name":"git","type":"option","char":"g","options":["y","n"]}},"args":[{"name":"projectName","description":"Project name","required":true}]},"api-mesh:log-get-bulk":{"id":"api-mesh:log-get-bulk","description":"Download all mesh logs for a selected time period.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"startTime":{"name":"startTime","type":"option","description":"Start time for the logs in UTC","required":true},"endTime":{"name":"endTime","type":"option","description":"End time for the logs in UTC","required":true},"filename":{"name":"filename","type":"option","description":"Path to the output file for logs","required":true}},"args":[]},"api-mesh:log-get":{"id":"api-mesh:log-get","description":"Get the Log of a given mesh by RayId","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false}},"args":[{"name":"rayId","description":"Fetch a single log by rayID","required":true}]},"api-mesh:log-list":{"id":"api-mesh:log-list","description":"Get recent logs of requests made to the API Mesh.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"filename":{"name":"filename","type":"option","description":"Name of CSV file to export the recent logs to"}},"args":[]},"api-mesh:run":{"id":"api-mesh:run","description":"Run a local development server that builds and compiles a mesh locally","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":[],"flags":{"port":{"name":"port","type":"option","char":"p","description":"Port number for the local dev server"},"debug":{"name":"debug","type":"boolean","description":"Enable debugging mode","allowNo":false},"env":{"name":"env","type":"option","char":"e","description":"Path to env file","default":".env"},"autoConfirmAction":{"name":"autoConfirmAction","type":"boolean","char":"c","description":"Auto confirm action prompt. CLI will not check for user approval before executing the action.","allowNo":false},"select":{"name":"select","type":"boolean","description":"Retrieve existing artifacts from the mesh","allowNo":false},"secrets":{"name":"secrets","type":"option","char":"s","description":"Path to secrets file","default":false}},"args":[{"name":"file","description":"Mesh File"}]},"api-mesh:status":{"id":"api-mesh:status","description":"Get a mesh status with a given meshid.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false}},"args":[]},"api-mesh:update":{"id":"api-mesh:update","description":"Update a mesh with the given config.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"autoConfirmAction":{"name":"autoConfirmAction","type":"boolean","char":"c","description":"Auto confirm action prompt. CLI will not check for user approval before executing the action.","allowNo":false},"env":{"name":"env","type":"option","char":"e","description":"Path to env file","default":".env"},"secrets":{"name":"secrets","type":"option","char":"s","description":"Path to secrets file","default":false}},"args":[{"name":"file"}]},"api-mesh:cache:purge":{"id":"api-mesh:cache:purge","description":"Cache purge for a given mesh","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false},"autoConfirmAction":{"name":"autoConfirmAction","type":"boolean","char":"c","description":"Auto confirm action prompt. CLI will not check for user approval before executing the action.","allowNo":false},"all":{"name":"all","type":"boolean","char":"a","description":"Purge all cache. CLI will purge all cache data.","required":true,"allowNo":false}},"args":[]},"api-mesh:source:discover":{"id":"api-mesh:source:discover","description":"Return the list of avaliable sources","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"flags":{"confirm":{"name":"confirm","type":"boolean","char":"c","description":"Auto confirm install action prompt. CLI will not check ask user to install source.","allowNo":false}},"args":[]},"api-mesh:source:get":{"id":"api-mesh:source:get","description":"Command returns the content of a specific source.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":["$ aio api-mesh:source:get -s=<version>@<source_name>","$ aio api-mesh:source:get -s<source_name>","$ aio api-mesh:source:get -m"],"flags":{"confirm":{"name":"confirm","type":"boolean","char":"c","description":"Auto confirm print action prompt. CLI will not check ask user to print source.","allowNo":false},"source":{"name":"source","type":"option","char":"s","description":"Source name"},"multiple":{"name":"multiple","type":"boolean","char":"m","description":"Select multiple sources","allowNo":false}},"args":[]},"api-mesh:source:install":{"id":"api-mesh:source:install","description":"Command to install the source to your API mesh.","pluginName":"@adobe/aio-cli-plugin-api-mesh","pluginType":"core","aliases":[],"examples":["$ aio api-mesh:source:install <version>@<source_name>","$ aio api-mesh:source:install <source_name> -v <variable_name>=<variable_value>","$ aio api-mesh:source:install <source_name> -f <path_to_variables_file>"],"flags":{"source":{"name":"source","type":"option","char":"s","description":"Source name"},"confirm":{"name":"confirm","type":"boolean","char":"c","description":"Auto confirm override action prompt. CLI will not check ask user to override source.","allowNo":false},"variable":{"name":"variable","type":"option","char":"v","description":"Variables required for the source"},"variable-file":{"name":"variable-file","type":"option","char":"f","description":"Variables file path"},"ignoreCache":{"name":"ignoreCache","type":"boolean","char":"i","description":"Ignore cache and force manual org -> project -> workspace selection","allowNo":false}},"args":[{"name":"source"}]}}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/aio-cli-plugin-api-mesh",
3
- "version": "5.1.0",
3
+ "version": "5.1.1-beta.2",
4
4
  "description": "Adobe I/O CLI plugin to develop and manage API mesh sources",
5
5
  "keywords": [
6
6
  "oclif-plugin"
@@ -0,0 +1,259 @@
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('axios');
14
+ jest.mock('@adobe/aio-lib-env');
15
+ jest.mock('@adobe/aio-lib-ims');
16
+ jest.mock('@adobe/aio-cli-lib-console');
17
+ jest.mock('@adobe/aio-cli-lib-console', () => ({
18
+ init: jest.fn().mockResolvedValue(mockConsoleCLIInstance),
19
+ cleanStdOut: jest.fn(),
20
+ }));
21
+ jest.mock('../../../helpers', () => ({
22
+ initSdk: jest.fn().mockResolvedValue({}),
23
+ initRequestId: jest.fn().mockResolvedValue({}),
24
+ promptConfirm: jest.fn().mockResolvedValue(true),
25
+ }));
26
+ jest.mock('../../../lib/devConsole');
27
+ const mockConsoleCLIInstance = {};
28
+ const selectedOrg = { id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' };
29
+ const selectedProject = { id: '5678', title: 'Project01' };
30
+ const selectedWorkspace = { id: '123456789', title: 'Workspace01' };
31
+ const CachePurgeCommand = require('../cache/purge');
32
+ const { initSdk, initRequestId, promptConfirm } = require('../../../helpers');
33
+ const {
34
+ getMeshId,
35
+ deleteMesh,
36
+ getApiKeyCredential,
37
+ unsubscribeCredentialFromMeshService,
38
+ cachePurge,
39
+ } = require('../../../lib/devConsole');
40
+ let logSpy = null;
41
+ let errorLogSpy = null;
42
+ let parseSpy = null;
43
+ const mockIgnoreCacheFlag = Promise.resolve(true);
44
+ const mockAutoApproveAction = Promise.resolve(false);
45
+
46
+ describe('cache purge command tests', () => {
47
+ beforeEach(() => {
48
+ initSdk.mockResolvedValue({
49
+ imsOrgCode: selectedOrg.code,
50
+ projectId: selectedProject.id,
51
+ workspaceId: selectedWorkspace.id,
52
+ });
53
+ global.requestId = 'dummy_request_id';
54
+ logSpy = jest.spyOn(CachePurgeCommand.prototype, 'log');
55
+ errorLogSpy = jest.spyOn(CachePurgeCommand.prototype, 'error');
56
+
57
+ getMeshId.mockResolvedValue('mesh_id');
58
+ deleteMesh.mockResolvedValue({ status: 'success' });
59
+ getApiKeyCredential.mockResolvedValue({
60
+ id_integration: 'dummy_integration_id',
61
+ client_id: 'dummy_client_id',
62
+ });
63
+ unsubscribeCredentialFromMeshService.mockResolvedValue(['dummy_service']);
64
+
65
+ parseSpy = jest.spyOn(CachePurgeCommand.prototype, 'parse');
66
+ });
67
+
68
+ afterEach(() => {
69
+ jest.restoreAllMocks();
70
+ });
71
+
72
+ test('should fail if all flag is missing', async () => {
73
+ parseSpy.mockResolvedValueOnce({
74
+ args: {},
75
+ flags: {
76
+ ignoreCache: mockIgnoreCacheFlag,
77
+ autoConfirmAction: mockAutoApproveAction,
78
+ all: Promise.resolve(false),
79
+ },
80
+ });
81
+
82
+ const runResult = CachePurgeCommand.run();
83
+
84
+ return runResult.catch(err => {
85
+ expect(err.message).toMatchInlineSnapshot(
86
+ `"Unable to purge cache. If the error persists please contact support. RequestId: dummy_request_id"`,
87
+ );
88
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`
89
+ [
90
+ [
91
+ "Unable to purge cache. If the error persists please contact support. RequestId: dummy_request_id",
92
+ ],
93
+ ]
94
+ `);
95
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
96
+ [
97
+ [
98
+ "Unable to purge cache. If the error persists please contact support. RequestId: dummy_request_id",
99
+ ],
100
+ ]
101
+ `);
102
+ });
103
+ });
104
+
105
+ test('should fail if unable to get mesh ID', async () => {
106
+ parseSpy.mockResolvedValueOnce({
107
+ args: {},
108
+ flags: {
109
+ ignoreCache: mockIgnoreCacheFlag,
110
+ autoConfirmAction: mockAutoApproveAction,
111
+ all: Promise.resolve(true),
112
+ },
113
+ });
114
+ getMeshId.mockResolvedValueOnce(null);
115
+
116
+ const runResult = CachePurgeCommand.run();
117
+
118
+ return runResult.catch(err => {
119
+ expect(err.message).toMatchInlineSnapshot(
120
+ `"Unable to purge cache. No mesh found for Org(CODE1234@AdobeOrg) -> Project(5678) -> Workspace(123456789). Check the details and try again."`,
121
+ );
122
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`[]`);
123
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
124
+ [
125
+ [
126
+ "Unable to purge cache. No mesh found for Org(CODE1234@AdobeOrg) -> Project(5678) -> Workspace(123456789). Check the details and try again.",
127
+ ],
128
+ ]
129
+ `);
130
+ });
131
+ });
132
+
133
+ test('should not purge cache if user prompt returns false', async () => {
134
+ parseSpy.mockResolvedValueOnce({
135
+ args: {},
136
+ flags: {
137
+ ignoreCache: mockIgnoreCacheFlag,
138
+ autoConfirmAction: mockAutoApproveAction,
139
+ all: Promise.resolve(true),
140
+ },
141
+ });
142
+ promptConfirm.mockResolvedValueOnce(false);
143
+
144
+ const runResult = await CachePurgeCommand.run();
145
+
146
+ expect(runResult).toBe('Cache purge cancelled');
147
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`
148
+ [
149
+ [
150
+ "Cache purge cancelled",
151
+ ],
152
+ ]
153
+ `);
154
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`[]`);
155
+ });
156
+
157
+ test('should not ask for prompt if autoConfirmAction is set', async () => {
158
+ parseSpy.mockResolvedValueOnce({
159
+ args: {},
160
+ flags: {
161
+ ignoreCache: mockIgnoreCacheFlag,
162
+ autoConfirmAction: Promise.resolve(true),
163
+ all: Promise.resolve(true),
164
+ },
165
+ });
166
+ cachePurge.mockResolvedValueOnce({ success: true });
167
+ const runResult = await CachePurgeCommand.run();
168
+
169
+ expect(runResult).toMatchInlineSnapshot(`
170
+ {
171
+ "success": true,
172
+ }
173
+ `);
174
+ expect(promptConfirm).not.toHaveBeenCalled();
175
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`
176
+ [
177
+ [
178
+ "Successfully purged cache for mesh %s",
179
+ "mesh_id",
180
+ ],
181
+ ]
182
+ `);
183
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`[]`);
184
+ });
185
+
186
+ test('should fail if cache purge fails', async () => {
187
+ parseSpy.mockResolvedValueOnce({
188
+ args: {},
189
+ flags: {
190
+ ignoreCache: mockIgnoreCacheFlag,
191
+ autoConfirmAction: Promise.resolve(false),
192
+ all: Promise.resolve(true),
193
+ },
194
+ });
195
+ cachePurge.mockRejectedValueOnce(new Error('cache purge failed'));
196
+
197
+ const runResult = CachePurgeCommand.run();
198
+
199
+ await expect(runResult).rejects.toEqual(
200
+ new Error(
201
+ 'Unable to purge cache. If the error persists please contact support. RequestId: dummy_request_id',
202
+ ),
203
+ );
204
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`
205
+ [
206
+ [
207
+ "cache purge failed",
208
+ ],
209
+ ]
210
+ `);
211
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`
212
+ [
213
+ [
214
+ "Unable to purge cache. If the error persists please contact support. RequestId: dummy_request_id",
215
+ ],
216
+ ]
217
+ `);
218
+ });
219
+
220
+ test('should purge cache if correct args are provided', async () => {
221
+ parseSpy.mockResolvedValueOnce({
222
+ args: {},
223
+ flags: {
224
+ ignoreCache: mockIgnoreCacheFlag,
225
+ autoConfirmAction: Promise.resolve(true),
226
+ all: Promise.resolve(true),
227
+ },
228
+ });
229
+ cachePurge.mockResolvedValueOnce({ success: true });
230
+ const runResult = await CachePurgeCommand.run();
231
+
232
+ expect(initRequestId).toHaveBeenCalled();
233
+ expect(runResult).toMatchInlineSnapshot(`
234
+ {
235
+ "success": true,
236
+ }
237
+ `);
238
+ expect(cachePurge.mock.calls).toMatchInlineSnapshot(`
239
+ [
240
+ [
241
+ "CODE1234@AdobeOrg",
242
+ "5678",
243
+ "123456789",
244
+ "mesh_id",
245
+ ],
246
+ ]
247
+ `);
248
+
249
+ expect(logSpy.mock.calls).toMatchInlineSnapshot(`
250
+ [
251
+ [
252
+ "Successfully purged cache for mesh %s",
253
+ "mesh_id",
254
+ ],
255
+ ]
256
+ `);
257
+ expect(errorLogSpy.mock.calls).toMatchInlineSnapshot(`[]`);
258
+ });
259
+ });
@@ -0,0 +1,94 @@
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
+ const {
17
+ ignoreCacheFlag,
18
+ autoConfirmActionFlag,
19
+ cachePurgeAllActionFlag,
20
+ } = require('../../../utils');
21
+ const { getMeshId, cachePurge } = require('../../../lib/devConsole');
22
+
23
+ require('dotenv').config();
24
+
25
+ class CachePurgeCommand extends Command {
26
+ static flags = {
27
+ ignoreCache: ignoreCacheFlag,
28
+ autoConfirmAction: autoConfirmActionFlag,
29
+ all: cachePurgeAllActionFlag,
30
+ };
31
+
32
+ async run() {
33
+ await initRequestId();
34
+
35
+ logger.info(`RequestId: ${global.requestId}`);
36
+
37
+ const { flags } = await this.parse(CachePurgeCommand);
38
+
39
+ const ignoreCache = await flags.ignoreCache;
40
+ const autoConfirmAction = await flags.autoConfirmAction;
41
+
42
+ const { imsOrgCode, projectId, workspaceId } = await initSdk({
43
+ ignoreCache,
44
+ });
45
+
46
+ let meshId = null;
47
+
48
+ try {
49
+ meshId = await getMeshId(imsOrgCode, 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
+ }
55
+
56
+ if (!meshId) {
57
+ this.error(
58
+ `Unable to purge cache. No mesh found for Org(${imsOrgCode}) -> Project(${projectId}) -> Workspace(${workspaceId}). Check the details and try again.`,
59
+ );
60
+ }
61
+ let shouldContinue = !!autoConfirmAction;
62
+ if (!autoConfirmAction) {
63
+ shouldContinue = await promptConfirm(`Cache will purge ALL data. Do you wish to continue?`);
64
+ }
65
+ if (!shouldContinue) {
66
+ this.log('Cache purge cancelled');
67
+
68
+ return 'Cache purge cancelled';
69
+ }
70
+ try {
71
+ const cachePurgeResponse = await cachePurge(imsOrgCode, projectId, workspaceId, meshId);
72
+
73
+ if (cachePurgeResponse) {
74
+ this.log('Successfully purged cache for mesh %s', meshId);
75
+
76
+ return cachePurgeResponse;
77
+ } else {
78
+ throw new Error(
79
+ `Unable to purge cache. If the error persists please contact support. RequestId: ${global.requestId}`,
80
+ );
81
+ }
82
+ } catch (error) {
83
+ this.log(error.message);
84
+
85
+ this.error(
86
+ `Unable to purge cache. If the error persists please contact support. RequestId: ${global.requestId}`,
87
+ );
88
+ }
89
+ }
90
+ }
91
+
92
+ CachePurgeCommand.description = 'Cache purge for a given mesh';
93
+
94
+ module.exports = CachePurgeCommand;
@@ -521,6 +521,94 @@ const deleteMesh = async (organizationId, projectId, workspaceId, meshId) => {
521
521
  }
522
522
  };
523
523
 
524
+ const cachePurge = async (organizationId, projectId, workspaceId, meshId) => {
525
+ const { accessToken } = await getDevConsoleConfig();
526
+ const config = {
527
+ method: 'post',
528
+ url: `${SMS_BASE_URL}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}/cache/purge`,
529
+ headers: {
530
+ 'Authorization': `Bearer ${accessToken}`,
531
+ 'Content-Type': 'application/json',
532
+ 'x-request-id': global.requestId,
533
+ 'x-api-key': SMS_API_KEY,
534
+ },
535
+ data: {},
536
+ };
537
+
538
+ logger.info(
539
+ 'Initiating cache purge %s',
540
+ `${SMS_BASE_URL}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}/cache/purge`,
541
+ );
542
+
543
+ try {
544
+ const response = await axios(config);
545
+
546
+ logger.info('Response from cache purge %s', response.status);
547
+
548
+ if (response && response.status === 200) {
549
+ return response;
550
+ } else {
551
+ // Non 200 response received
552
+ logger.error(
553
+ `Something went wrong: ${objToString(
554
+ response,
555
+ ['data'],
556
+ 'Unable to purge cache',
557
+ )}. Received ${response.status} response instead of 200`,
558
+ );
559
+
560
+ throw new Error(
561
+ `Something went wrong: ${objToString(response, ['data'], 'Unable to purge cache')}`,
562
+ );
563
+ }
564
+ } catch (error) {
565
+ logger.info('Response from cache purge %s', error.response.status);
566
+
567
+ if (error.response.status === 404) {
568
+ // The request was made and the server responded with a 404 status code
569
+ logger.error('Mesh not found');
570
+
571
+ throw new Error('Mesh not found');
572
+ } else if (error.response && error.response.data) {
573
+ // The request was made and the server responded with an unsupported status code
574
+ logger.error(
575
+ 'Error in cache purge. Response: %s',
576
+ objToString(error, ['response', 'data'], 'Unable to purge cache'),
577
+ );
578
+
579
+ if (error.response.data.messages) {
580
+ const message = objToString(
581
+ error,
582
+ ['response', 'data', 'messages', '0', 'message'],
583
+ 'Unable to purge cache',
584
+ );
585
+
586
+ throw new Error(message);
587
+ } else if (error.response.data.message) {
588
+ const message = objToString(
589
+ error,
590
+ ['response', 'data', 'message'],
591
+ 'Unable to purge cache',
592
+ );
593
+
594
+ throw new Error(message);
595
+ } else {
596
+ const message = objToString(error, ['response', 'data'], 'Unable to purge cache');
597
+
598
+ throw new Error(message);
599
+ }
600
+ } else {
601
+ // The request was made but no response was received
602
+ logger.error(
603
+ 'Error while purge cache. No response received from the server: %s',
604
+ objToString(error, [], 'Unable to purge cache'),
605
+ );
606
+
607
+ throw new Error('Unable to purge cache from Schema Management Service: %s', error.message);
608
+ }
609
+ }
610
+ };
611
+
524
612
  const getMeshId = async (organizationCode, projectId, workspaceId, workspaceName) => {
525
613
  const { accessToken } = await getDevConsoleConfig();
526
614
  logger.info('Initiating Mesh ID request');
@@ -1133,4 +1221,5 @@ module.exports = {
1133
1221
  getPublicEncryptionKey,
1134
1222
  getPresignedUrls,
1135
1223
  getLogsByRayId,
1224
+ cachePurge,
1136
1225
  };
package/src/utils.js CHANGED
@@ -35,6 +35,12 @@ const autoConfirmActionFlag = Flags.boolean({
35
35
  default: false,
36
36
  });
37
37
 
38
+ const cachePurgeAllActionFlag = Flags.boolean({
39
+ char: 'a',
40
+ description: 'Purge all cache. CLI will purge all cache data.',
41
+ required: true,
42
+ });
43
+
38
44
  const jsonFlag = Flags.boolean({
39
45
  description: 'Output JSON',
40
46
  default: false,
@@ -621,4 +627,5 @@ module.exports = {
621
627
  endTimeFlag,
622
628
  logFilenameFlag,
623
629
  suggestCorrectedDateFormat,
630
+ cachePurgeAllActionFlag,
624
631
  };