@adobe/aio-cli-plugin-api-mesh 5.2.3 → 5.2.4-alpha.0
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/oclif.manifest.json +1 -1
- package/package.json +5 -10
- package/src/commands/{api-mesh.js → PLUGINNAME/__tests__/index.test.js} +15 -13
- package/src/commands/PLUGINNAME/index.js +32 -0
- package/src/commands/api-mesh/__tests__/cache-purge.test.js +2 -2
- package/src/commands/api-mesh/__tests__/create.test.js +9 -21
- package/src/commands/api-mesh/__tests__/delete.test.js +2 -2
- package/src/commands/api-mesh/__tests__/describe.test.js +2 -2
- package/src/commands/api-mesh/__tests__/get-log-forwarding.test.js +149 -0
- package/src/commands/api-mesh/__tests__/get.test.js +2 -2
- package/src/commands/api-mesh/__tests__/log-get-bulk.test.js +2 -2
- package/src/commands/api-mesh/__tests__/log-get.test.js +2 -2
- package/src/commands/api-mesh/__tests__/log-list.test.js +2 -2
- package/src/commands/api-mesh/__tests__/run.test.js +67 -193
- package/src/commands/api-mesh/__tests__/set-log-forwarding.test.js +246 -0
- package/src/commands/api-mesh/__tests__/status.test.js +2 -2
- package/src/commands/api-mesh/__tests__/update.test.js +4 -6
- package/src/commands/api-mesh/cache/purge.js +1 -1
- package/src/commands/api-mesh/config/get/log-forwarding.js +78 -0
- package/src/commands/api-mesh/config/set/log-forwarding.js +156 -0
- package/src/commands/api-mesh/create.js +4 -3
- package/src/commands/api-mesh/delete.js +1 -1
- package/src/commands/api-mesh/describe.js +1 -1
- package/src/commands/api-mesh/get.js +1 -1
- package/src/commands/api-mesh/log-get-bulk.js +1 -1
- package/src/commands/api-mesh/log-get.js +1 -1
- package/src/commands/api-mesh/log-list.js +1 -1
- package/src/commands/api-mesh/run.js +162 -208
- package/src/commands/api-mesh/source/__tests__/install.test.js +2 -2
- package/src/commands/api-mesh/source/install.js +1 -1
- package/src/commands/api-mesh/status.js +1 -1
- package/src/commands/api-mesh/update.js +4 -3
- package/src/helpers.js +29 -20
- package/src/{worker.js → index.js} +7 -9
- package/src/lib/{devConsole.js → smsClient.js} +186 -1
- package/src/server.js +32 -74
- package/src/utils.js +46 -10
- package/src/wranglerServer.js +80 -0
- package/src/meshArtifact.js +0 -231
- package/src/project.js +0 -56
- package/src/wranglerCli.js +0 -54
- package/wrangler.toml +0 -13
|
@@ -0,0 +1,246 @@
|
|
|
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 SetLogForwardingCommand = require('../config/set/log-forwarding');
|
|
14
|
+
const {
|
|
15
|
+
initSdk,
|
|
16
|
+
promptConfirm,
|
|
17
|
+
promptSelect,
|
|
18
|
+
promptInput,
|
|
19
|
+
promptInputSecret,
|
|
20
|
+
} = require('../../../helpers');
|
|
21
|
+
const { getMeshId, setLogForwarding } = require('../../../lib/smsClient');
|
|
22
|
+
|
|
23
|
+
jest.mock('../../../helpers', () => ({
|
|
24
|
+
initSdk: jest.fn().mockResolvedValue({}),
|
|
25
|
+
initRequestId: jest.fn().mockResolvedValue({}),
|
|
26
|
+
promptConfirm: jest.fn().mockResolvedValue(true),
|
|
27
|
+
promptSelect: jest.fn().mockResolvedValue('New Relic'),
|
|
28
|
+
promptInput: jest.fn().mockResolvedValue('https://log-api.newrelic.com/log/v1'),
|
|
29
|
+
promptInputSecret: jest.fn().mockResolvedValue('abcdef0123456789abcdef0123456789abcdef01'),
|
|
30
|
+
}));
|
|
31
|
+
jest.mock('../../../lib/smsClient');
|
|
32
|
+
jest.mock('../../../classes/logger');
|
|
33
|
+
|
|
34
|
+
describe('SetLogForwardingCommand', () => {
|
|
35
|
+
let parseSpy;
|
|
36
|
+
let logSpy;
|
|
37
|
+
let errorSpy;
|
|
38
|
+
|
|
39
|
+
beforeEach(() => {
|
|
40
|
+
// Setup spies and mock functions
|
|
41
|
+
parseSpy = jest.spyOn(SetLogForwardingCommand.prototype, 'parse').mockResolvedValue({
|
|
42
|
+
flags: {
|
|
43
|
+
ignoreCache: false,
|
|
44
|
+
autoConfirmAction: false,
|
|
45
|
+
json: false,
|
|
46
|
+
},
|
|
47
|
+
args: [], // Empty args since we are using prompts
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
logSpy = jest.spyOn(SetLogForwardingCommand.prototype, 'log');
|
|
51
|
+
errorSpy = jest.spyOn(SetLogForwardingCommand.prototype, 'error').mockImplementation(() => {
|
|
52
|
+
throw new Error(errorSpy.mock.calls[0][0]);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
initSdk.mockResolvedValue({
|
|
56
|
+
imsOrgId: 'orgId',
|
|
57
|
+
imsOrgCode: 'orgCode',
|
|
58
|
+
projectId: 'projectId',
|
|
59
|
+
workspaceId: 'workspaceId',
|
|
60
|
+
workspaceName: 'workspaceName',
|
|
61
|
+
});
|
|
62
|
+
getMeshId.mockResolvedValue('meshId');
|
|
63
|
+
setLogForwarding.mockResolvedValue({ success: true, result: true });
|
|
64
|
+
global.requestId = 'dummy_request_id';
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
afterEach(() => {
|
|
68
|
+
jest.clearAllMocks();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('Test New Relic destination', () => {
|
|
72
|
+
/** Success Scenario */
|
|
73
|
+
test('sets log forwarding with valid parameters', async () => {
|
|
74
|
+
const command = new SetLogForwardingCommand([], {});
|
|
75
|
+
await command.run();
|
|
76
|
+
|
|
77
|
+
expect(promptSelect).toHaveBeenCalledWith('Select log forwarding destination:', [
|
|
78
|
+
'New Relic',
|
|
79
|
+
]);
|
|
80
|
+
expect(promptInput).toHaveBeenCalledWith('Enter base URI:');
|
|
81
|
+
expect(promptInputSecret).toHaveBeenCalledWith('Enter license key:');
|
|
82
|
+
expect(setLogForwarding).toHaveBeenCalledWith(
|
|
83
|
+
'orgCode',
|
|
84
|
+
'projectId',
|
|
85
|
+
'workspaceId',
|
|
86
|
+
'meshId',
|
|
87
|
+
{
|
|
88
|
+
destination: 'newrelic',
|
|
89
|
+
config: {
|
|
90
|
+
baseUri: 'https://log-api.newrelic.com/log/v1',
|
|
91
|
+
licenseKey: 'abcdef0123456789abcdef0123456789abcdef01',
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
);
|
|
95
|
+
expect(logSpy).toHaveBeenCalledWith('Log forwarding set successfully for meshId');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
/** Error Scenarios */
|
|
99
|
+
test('throws an error if mesh ID is not found', async () => {
|
|
100
|
+
getMeshId.mockResolvedValueOnce(null);
|
|
101
|
+
|
|
102
|
+
const command = new SetLogForwardingCommand([], {});
|
|
103
|
+
await expect(command.run()).rejects.toThrow(
|
|
104
|
+
'Unable to get meshId. No mesh found for Org(orgCode) -> Project(projectId) -> Workspace(workspaceId). Check the details and try again.',
|
|
105
|
+
);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
/** Input Validation */
|
|
109
|
+
test('throws an error if base URI does not include protocol', async () => {
|
|
110
|
+
promptInput.mockResolvedValueOnce('log-api.newrelic.com/log/v1'); // Missing https://
|
|
111
|
+
|
|
112
|
+
const command = new SetLogForwardingCommand([], {});
|
|
113
|
+
await expect(command.run()).rejects.toThrow(
|
|
114
|
+
'The URI value must include the protocol (https://)',
|
|
115
|
+
);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('throws an error if license key has wrong format', async () => {
|
|
119
|
+
promptInputSecret.mockResolvedValueOnce('wrongformat'); // Too short
|
|
120
|
+
|
|
121
|
+
const command = new SetLogForwardingCommand([], {});
|
|
122
|
+
await expect(command.run()).rejects.toThrow(
|
|
123
|
+
`The license key is in the wrong format. Expected: 40 characters (received: ${11})`,
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('prompts for missing destination', async () => {
|
|
128
|
+
parseSpy.mockResolvedValueOnce({
|
|
129
|
+
flags: {
|
|
130
|
+
// No destination provided
|
|
131
|
+
ignoreCache: false,
|
|
132
|
+
autoConfirmAction: false,
|
|
133
|
+
json: false,
|
|
134
|
+
},
|
|
135
|
+
args: [],
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const command = new SetLogForwardingCommand([], {});
|
|
139
|
+
await command.run();
|
|
140
|
+
|
|
141
|
+
expect(promptSelect).toHaveBeenCalledWith('Select log forwarding destination:', [
|
|
142
|
+
'New Relic',
|
|
143
|
+
]);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test('throws an error if destination selection is cancelled', async () => {
|
|
147
|
+
parseSpy.mockResolvedValueOnce({
|
|
148
|
+
flags: {
|
|
149
|
+
// No destination provided
|
|
150
|
+
ignoreCache: false,
|
|
151
|
+
autoConfirmAction: false,
|
|
152
|
+
json: false,
|
|
153
|
+
},
|
|
154
|
+
args: [],
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
promptSelect.mockResolvedValueOnce(null); // User cancels selection
|
|
158
|
+
|
|
159
|
+
const command = new SetLogForwardingCommand([], {});
|
|
160
|
+
await expect(command.run()).rejects.toThrow('Destination is required');
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test('throws an error if base URI is empty', async () => {
|
|
164
|
+
promptInput.mockResolvedValueOnce(''); // Empty base URI
|
|
165
|
+
|
|
166
|
+
const command = new SetLogForwardingCommand([], {});
|
|
167
|
+
await expect(command.run()).rejects.toThrow('Base URI is required');
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test('throws an error if license key is empty', async () => {
|
|
171
|
+
promptInputSecret.mockResolvedValueOnce(''); // Empty license key
|
|
172
|
+
|
|
173
|
+
const command = new SetLogForwardingCommand([], {});
|
|
174
|
+
await expect(command.run()).rejects.toThrow('License key is required');
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test('returns cancellation message when user declines confirmation', async () => {
|
|
178
|
+
promptConfirm.mockResolvedValueOnce(false); // User declines
|
|
179
|
+
|
|
180
|
+
const command = new SetLogForwardingCommand([], {});
|
|
181
|
+
const result = await command.run();
|
|
182
|
+
|
|
183
|
+
expect(result).toBe('set-log-forwarding cancelled');
|
|
184
|
+
expect(setLogForwarding).not.toHaveBeenCalled();
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
/** Flag Handling */
|
|
188
|
+
test('skips confirmation when autoConfirmAction flag is set', async () => {
|
|
189
|
+
parseSpy.mockResolvedValueOnce({
|
|
190
|
+
flags: {
|
|
191
|
+
ignoreCache: false,
|
|
192
|
+
autoConfirmAction: true, // Auto-confirm enabled
|
|
193
|
+
json: false,
|
|
194
|
+
},
|
|
195
|
+
args: [],
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
const command = new SetLogForwardingCommand([], {});
|
|
199
|
+
await command.run();
|
|
200
|
+
|
|
201
|
+
expect(promptConfirm).not.toHaveBeenCalled();
|
|
202
|
+
expect(setLogForwarding).toHaveBeenCalled();
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
test('sets log forwarding with auto-confirmation', async () => {
|
|
206
|
+
parseSpy.mockResolvedValueOnce({
|
|
207
|
+
flags: {
|
|
208
|
+
ignoreCache: false,
|
|
209
|
+
autoConfirmAction: true, // Auto-confirm enabled
|
|
210
|
+
json: false,
|
|
211
|
+
},
|
|
212
|
+
args: [],
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
const command = new SetLogForwardingCommand([], {});
|
|
216
|
+
await command.run();
|
|
217
|
+
|
|
218
|
+
expect(promptConfirm).not.toHaveBeenCalled();
|
|
219
|
+
expect(setLogForwarding).toHaveBeenCalledWith(
|
|
220
|
+
'orgCode',
|
|
221
|
+
'projectId',
|
|
222
|
+
'workspaceId',
|
|
223
|
+
'meshId',
|
|
224
|
+
{
|
|
225
|
+
destination: 'newrelic',
|
|
226
|
+
config: {
|
|
227
|
+
baseUri: 'https://log-api.newrelic.com/log/v1',
|
|
228
|
+
licenseKey: 'abcdef0123456789abcdef0123456789abcdef01',
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
);
|
|
232
|
+
expect(logSpy).toHaveBeenCalledWith('Log forwarding set successfully for meshId');
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
test('logs error message when setLogForwarding fails', async () => {
|
|
236
|
+
const errorMessage = 'Unable to set log forwarding details';
|
|
237
|
+
setLogForwarding.mockRejectedValueOnce(new Error(errorMessage));
|
|
238
|
+
|
|
239
|
+
const command = new SetLogForwardingCommand([], {});
|
|
240
|
+
await expect(command.run()).rejects.toThrow(
|
|
241
|
+
'Failed to set log forwarding details. Try again. RequestId: dummy_request_id',
|
|
242
|
+
);
|
|
243
|
+
expect(logSpy).toHaveBeenCalledWith(errorMessage);
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
});
|
|
@@ -8,7 +8,7 @@ const mockMeshId = '00000000-0000-0000-0000-000000000000';
|
|
|
8
8
|
global.requestId = 'dummy_request_id';
|
|
9
9
|
|
|
10
10
|
// Create mock modules and functions
|
|
11
|
-
jest.mock('../../../lib/
|
|
11
|
+
jest.mock('../../../lib/smsClient');
|
|
12
12
|
jest.mock('../../../helpers');
|
|
13
13
|
const parseSpy = jest.spyOn(StatusCommand.prototype, 'parse');
|
|
14
14
|
const logSpy = jest.spyOn(StatusCommand.prototype, 'log');
|
|
@@ -16,7 +16,7 @@ const errorLogSpy = jest.spyOn(StatusCommand.prototype, 'error');
|
|
|
16
16
|
|
|
17
17
|
// Prepare mocks
|
|
18
18
|
const { initSdk } = require('../../../helpers');
|
|
19
|
-
const { getMeshId, getMesh, getMeshDeployments } = require('../../../lib/
|
|
19
|
+
const { getMeshId, getMesh, getMeshDeployments } = require('../../../lib/smsClient');
|
|
20
20
|
initSdk.mockResolvedValue({
|
|
21
21
|
imsOrgId: mockOrg.id,
|
|
22
22
|
imsOrgCode: mockOrg.code,
|
|
@@ -17,14 +17,14 @@ jest.mock('../../../helpers', () => ({
|
|
|
17
17
|
initSdk: jest.fn().mockResolvedValue({}),
|
|
18
18
|
initRequestId: jest.fn().mockResolvedValue({}),
|
|
19
19
|
promptConfirm: jest.fn().mockResolvedValue(true),
|
|
20
|
-
importFiles: jest.fn().mockResolvedValue(
|
|
20
|
+
importFiles: jest.fn().mockResolvedValue(),
|
|
21
21
|
}));
|
|
22
22
|
jest.mock('@adobe/aio-cli-lib-console', () => ({
|
|
23
23
|
init: jest.fn().mockResolvedValue(mockConsoleCLIInstance),
|
|
24
24
|
cleanStdOut: jest.fn(),
|
|
25
25
|
}));
|
|
26
26
|
jest.mock('@adobe/aio-lib-ims');
|
|
27
|
-
jest.mock('../../../lib/
|
|
27
|
+
jest.mock('../../../lib/smsClient');
|
|
28
28
|
|
|
29
29
|
const mockConsoleCLIInstance = {};
|
|
30
30
|
|
|
@@ -36,7 +36,7 @@ const { readFile } = require('fs/promises');
|
|
|
36
36
|
|
|
37
37
|
const UpdateCommand = require('../update');
|
|
38
38
|
const { initSdk, initRequestId, promptConfirm, importFiles } = require('../../../helpers');
|
|
39
|
-
const { getMeshId, updateMesh } = require('../../../lib/
|
|
39
|
+
const { getMeshId, updateMesh } = require('../../../lib/smsClient');
|
|
40
40
|
|
|
41
41
|
let logSpy = null;
|
|
42
42
|
let errorLogSpy = null;
|
|
@@ -547,9 +547,7 @@ describe('update command tests', () => {
|
|
|
547
547
|
});
|
|
548
548
|
|
|
549
549
|
importFiles.mockResolvedValueOnce({
|
|
550
|
-
|
|
551
|
-
meshConfig,
|
|
552
|
-
},
|
|
550
|
+
meshConfig,
|
|
553
551
|
});
|
|
554
552
|
|
|
555
553
|
const output = await UpdateCommand.run();
|
|
@@ -18,7 +18,7 @@ const {
|
|
|
18
18
|
autoConfirmActionFlag,
|
|
19
19
|
cachePurgeAllActionFlag,
|
|
20
20
|
} = require('../../../utils');
|
|
21
|
-
const { getMeshId, cachePurge } = require('../../../lib/
|
|
21
|
+
const { getMeshId, cachePurge } = require('../../../lib/smsClient');
|
|
22
22
|
|
|
23
23
|
require('dotenv').config();
|
|
24
24
|
|
|
@@ -0,0 +1,78 @@
|
|
|
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/core');
|
|
13
|
+
const { initSdk, initRequestId } = require('../../../../helpers');
|
|
14
|
+
const logger = require('../../../../classes/logger');
|
|
15
|
+
const { ignoreCacheFlag, jsonFlag } = require('../../../../utils');
|
|
16
|
+
const { getLogForwarding, getMeshId } = require('../../../../lib/smsClient');
|
|
17
|
+
|
|
18
|
+
class GetLogForwardingCommand extends Command {
|
|
19
|
+
static flags = {
|
|
20
|
+
ignoreCache: ignoreCacheFlag,
|
|
21
|
+
json: jsonFlag,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
static enableJsonFlag = true;
|
|
25
|
+
|
|
26
|
+
async run() {
|
|
27
|
+
await initRequestId();
|
|
28
|
+
|
|
29
|
+
logger.info(`RequestId: ${global.requestId}`);
|
|
30
|
+
|
|
31
|
+
const { flags } = await this.parse(GetLogForwardingCommand);
|
|
32
|
+
|
|
33
|
+
const ignoreCache = await flags.ignoreCache;
|
|
34
|
+
|
|
35
|
+
const { imsOrgCode, projectId, workspaceId, workspaceName } = await initSdk({
|
|
36
|
+
ignoreCache,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
let meshId = null;
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
meshId = await getMeshId(imsOrgCode, projectId, workspaceId, workspaceName);
|
|
43
|
+
} catch (err) {
|
|
44
|
+
this.log(err.message);
|
|
45
|
+
this.error(
|
|
46
|
+
`Unable to get mesh ID. Check the details and try again. RequestId: ${global.requestId}`,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
// mesh could not be found
|
|
50
|
+
if (!meshId) {
|
|
51
|
+
this.error(
|
|
52
|
+
`Unable to get meshId. No mesh found for Org(${imsOrgCode}) -> Project(${projectId}) -> Workspace(${workspaceId}). Check the details and try again.`,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const response = await getLogForwarding(imsOrgCode, projectId, workspaceId, meshId);
|
|
57
|
+
if (response && response.data) {
|
|
58
|
+
this.log(
|
|
59
|
+
'Successfully retrieved log forwarding details: \n',
|
|
60
|
+
JSON.stringify(response.data, null, 2),
|
|
61
|
+
);
|
|
62
|
+
return { imsOrgCode, projectId, workspaceId, workspaceName };
|
|
63
|
+
} else {
|
|
64
|
+
this.error(
|
|
65
|
+
`Unable to get log forwarding details. Try again. RequestId: ${global.requestId}`,
|
|
66
|
+
);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
} catch (error) {
|
|
70
|
+
this.log(error.message);
|
|
71
|
+
this.error(`Failed to get log forwarding details. Try again. RequestId: ${global.requestId}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
GetLogForwardingCommand.description = `Get log forwarding details for a given mesh`;
|
|
77
|
+
|
|
78
|
+
module.exports = GetLogForwardingCommand;
|
|
@@ -0,0 +1,156 @@
|
|
|
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/core');
|
|
13
|
+
const {
|
|
14
|
+
initSdk,
|
|
15
|
+
initRequestId,
|
|
16
|
+
promptConfirm,
|
|
17
|
+
promptSelect,
|
|
18
|
+
promptInput,
|
|
19
|
+
promptInputSecret,
|
|
20
|
+
} = require('../../../../helpers');
|
|
21
|
+
const logger = require('../../../../classes/logger');
|
|
22
|
+
const {
|
|
23
|
+
ignoreCacheFlag,
|
|
24
|
+
autoConfirmActionFlag,
|
|
25
|
+
jsonFlag,
|
|
26
|
+
destinations,
|
|
27
|
+
} = require('../../../../utils');
|
|
28
|
+
const { setLogForwarding, getMeshId } = require('../../../../lib/smsClient');
|
|
29
|
+
|
|
30
|
+
class SetLogForwardingCommand extends Command {
|
|
31
|
+
static flags = {
|
|
32
|
+
ignoreCache: ignoreCacheFlag,
|
|
33
|
+
autoConfirmAction: autoConfirmActionFlag,
|
|
34
|
+
json: jsonFlag,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
static enableJsonFlag = true;
|
|
38
|
+
|
|
39
|
+
async run() {
|
|
40
|
+
await initRequestId();
|
|
41
|
+
|
|
42
|
+
logger.info(`RequestId: ${global.requestId}`);
|
|
43
|
+
|
|
44
|
+
const { flags } = await this.parse(SetLogForwardingCommand);
|
|
45
|
+
|
|
46
|
+
const ignoreCache = await flags.ignoreCache;
|
|
47
|
+
const autoConfirmAction = await flags.autoConfirmAction;
|
|
48
|
+
|
|
49
|
+
let destinationConfig;
|
|
50
|
+
try {
|
|
51
|
+
destinationConfig = await this.inputAndValidateConfigs(destinations);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
this.error(error.message);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const { imsOrgCode, projectId, workspaceId, workspaceName } = await initSdk({
|
|
57
|
+
ignoreCache,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
let meshId = null;
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
meshId = await getMeshId(imsOrgCode, projectId, workspaceId, workspaceName);
|
|
64
|
+
} catch (err) {
|
|
65
|
+
this.log(err.message);
|
|
66
|
+
this.error(
|
|
67
|
+
`Unable to get mesh ID. Check the details and try again. RequestId: ${global.requestId}`,
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// mesh could not be found
|
|
72
|
+
if (!meshId) {
|
|
73
|
+
this.error(
|
|
74
|
+
`Unable to get meshId. No mesh found for Org(${imsOrgCode}) -> Project(${projectId}) -> Workspace(${workspaceId}). Check the details and try again.`,
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
let shouldContinue = true;
|
|
79
|
+
|
|
80
|
+
if (!autoConfirmAction) {
|
|
81
|
+
shouldContinue = await promptConfirm(
|
|
82
|
+
`Are you sure you want to set log forwarding to ${destinationConfig.destination}?`,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (shouldContinue) {
|
|
87
|
+
try {
|
|
88
|
+
const response = await setLogForwarding(
|
|
89
|
+
imsOrgCode,
|
|
90
|
+
projectId,
|
|
91
|
+
workspaceId,
|
|
92
|
+
meshId,
|
|
93
|
+
destinationConfig,
|
|
94
|
+
);
|
|
95
|
+
if (response && response.result) {
|
|
96
|
+
this.log(`Log forwarding set successfully for ${meshId}`);
|
|
97
|
+
return { destinationConfig, imsOrgCode, projectId, workspaceId, workspaceName };
|
|
98
|
+
} else {
|
|
99
|
+
this.error(
|
|
100
|
+
`Unable to set log forwarding details. Try again. RequestId: ${global.requestId}`,
|
|
101
|
+
);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
} catch (error) {
|
|
105
|
+
this.log(error.message);
|
|
106
|
+
this.error(
|
|
107
|
+
`Failed to set log forwarding details. Try again. RequestId: ${global.requestId}`,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
this.log('log-forwarding cancelled');
|
|
112
|
+
return 'set-log-forwarding cancelled';
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async inputAndValidateConfigs(destinations) {
|
|
117
|
+
// Prompt for destination
|
|
118
|
+
const destinationKey = await promptSelect(
|
|
119
|
+
'Select log forwarding destination:',
|
|
120
|
+
Object.keys(destinations),
|
|
121
|
+
);
|
|
122
|
+
if (!destinationKey) {
|
|
123
|
+
throw new Error('Destination is required');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const destinationConfig = destinations[destinationKey];
|
|
127
|
+
const inputs = {};
|
|
128
|
+
|
|
129
|
+
// For each input defined in the destination config, prompt and validate
|
|
130
|
+
for (const inputConfig of destinationConfig.inputs) {
|
|
131
|
+
// Prompt for input value (regular or secret based on config)
|
|
132
|
+
const promptFn = inputConfig.isSecret ? promptInputSecret : promptInput;
|
|
133
|
+
const value = await promptFn(inputConfig.promptMessage);
|
|
134
|
+
|
|
135
|
+
// Validate the input
|
|
136
|
+
if (inputConfig.validate) {
|
|
137
|
+
inputConfig.validate(value);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Store the validated input
|
|
141
|
+
inputs[inputConfig.name] = value;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
destination: destinationConfig.name,
|
|
146
|
+
config: inputs,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
SetLogForwardingCommand.description = `Sets the log forwarding destination for API mesh.
|
|
152
|
+
- Select a log forwarding destination - Choose from available options (for example, New Relic).
|
|
153
|
+
- Enter the base URI - Provide the URI for the log forwarding service. Ensure it includes the protocol (for example, if the hosted region of the New Relic account is the U.S, the base URI could be 'https://log-api.newrelic.com/log/v1').
|
|
154
|
+
- Enter the license key - Provide the INGEST-LICENSE API key type.`;
|
|
155
|
+
|
|
156
|
+
module.exports = SetLogForwardingCommand;
|
|
@@ -26,7 +26,7 @@ const {
|
|
|
26
26
|
validateSecretsFile,
|
|
27
27
|
encryptSecrets,
|
|
28
28
|
} = require('../../utils');
|
|
29
|
-
const { createMesh, getPublicEncryptionKey } = require('../../lib/
|
|
29
|
+
const { createMesh, getPublicEncryptionKey } = require('../../lib/smsClient');
|
|
30
30
|
const { buildMeshUrl } = require('../../urlBuilder');
|
|
31
31
|
|
|
32
32
|
class CreateCommand extends Command {
|
|
@@ -99,7 +99,7 @@ class CreateCommand extends Command {
|
|
|
99
99
|
// if local files are present, import them in files array in meshConfig
|
|
100
100
|
if (filesList.length) {
|
|
101
101
|
try {
|
|
102
|
-
|
|
102
|
+
data = await importFiles(data, filesList, args.file, flags.autoConfirmAction);
|
|
103
103
|
} catch (err) {
|
|
104
104
|
this.log(err.message);
|
|
105
105
|
this.error('Unable to import the files in the mesh config. Check the file and try again.');
|
|
@@ -112,7 +112,8 @@ class CreateCommand extends Command {
|
|
|
112
112
|
await validateSecretsFile(secretsFilePath);
|
|
113
113
|
const secretsData = await interpolateSecrets(secretsFilePath, this);
|
|
114
114
|
const publicKey = await getPublicEncryptionKey(imsOrgCode);
|
|
115
|
-
|
|
115
|
+
const encryptedSecrets = await encryptSecrets(publicKey, secretsData);
|
|
116
|
+
data.secrets = encryptedSecrets;
|
|
116
117
|
} catch (err) {
|
|
117
118
|
this.log(err.message);
|
|
118
119
|
this.error('Unable to import secrets. Check the file and try again.');
|
|
@@ -14,7 +14,7 @@ const { Command } = require('@oclif/command');
|
|
|
14
14
|
const logger = require('../../classes/logger');
|
|
15
15
|
const { initSdk, initRequestId, promptConfirm } = require('../../helpers');
|
|
16
16
|
const { ignoreCacheFlag, autoConfirmActionFlag } = require('../../utils');
|
|
17
|
-
const { getMeshId, deleteMesh } = require('../../lib/
|
|
17
|
+
const { getMeshId, deleteMesh } = require('../../lib/smsClient');
|
|
18
18
|
|
|
19
19
|
require('dotenv').config();
|
|
20
20
|
|
|
@@ -13,7 +13,7 @@ const { Command } = require('@oclif/command');
|
|
|
13
13
|
const logger = require('../../classes/logger');
|
|
14
14
|
const { initSdk, initRequestId } = require('../../helpers');
|
|
15
15
|
const { ignoreCacheFlag } = require('../../utils');
|
|
16
|
-
const { describeMesh } = require('../../lib/
|
|
16
|
+
const { describeMesh } = require('../../lib/smsClient');
|
|
17
17
|
const { buildMeshUrl } = require('../../urlBuilder');
|
|
18
18
|
|
|
19
19
|
require('dotenv').config();
|
|
@@ -15,7 +15,7 @@ const { writeFile } = require('fs/promises');
|
|
|
15
15
|
const logger = require('../../classes/logger');
|
|
16
16
|
const { initSdk, initRequestId } = require('../../helpers');
|
|
17
17
|
const { ignoreCacheFlag, jsonFlag } = require('../../utils');
|
|
18
|
-
const { getMeshId, getMesh } = require('../../lib/
|
|
18
|
+
const { getMeshId, getMesh } = require('../../lib/smsClient');
|
|
19
19
|
const { buildMeshUrl } = require('../../urlBuilder');
|
|
20
20
|
|
|
21
21
|
require('dotenv').config();
|
|
@@ -2,7 +2,7 @@ const { Command } = require('@oclif/core');
|
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const { initRequestId, initSdk, promptConfirm } = require('../../helpers');
|
|
5
|
-
const { getMeshId, getPresignedUrls } = require('../../lib/
|
|
5
|
+
const { getMeshId, getPresignedUrls } = require('../../lib/smsClient');
|
|
6
6
|
const logger = require('../../classes/logger');
|
|
7
7
|
const axios = require('axios');
|
|
8
8
|
const {
|
|
@@ -12,7 +12,7 @@ const { Command } = require('@oclif/core');
|
|
|
12
12
|
const logger = require('../../classes/logger');
|
|
13
13
|
const { initSdk, initRequestId } = require('../../helpers');
|
|
14
14
|
const { ignoreCacheFlag } = require('../../utils');
|
|
15
|
-
const { getMeshId, getLogsByRayId } = require('../../lib/
|
|
15
|
+
const { getMeshId, getLogsByRayId } = require('../../lib/smsClient');
|
|
16
16
|
require('dotenv').config();
|
|
17
17
|
|
|
18
18
|
class FetchLogsCommand extends Command {
|
|
@@ -3,7 +3,7 @@ const { Command } = require('@oclif/core');
|
|
|
3
3
|
const logger = require('../../classes/logger');
|
|
4
4
|
const { initSdk, initRequestId } = require('../../helpers');
|
|
5
5
|
const { ignoreCacheFlag, fileNameFlag } = require('../../utils');
|
|
6
|
-
const { getMeshId, listLogs } = require('../../lib/
|
|
6
|
+
const { getMeshId, listLogs } = require('../../lib/smsClient');
|
|
7
7
|
const { appendFileSync, existsSync } = require('fs');
|
|
8
8
|
const { ux } = require('@oclif/core/lib/cli-ux');
|
|
9
9
|
const path = require('path');
|