@adobe/aio-cli-plugin-api-mesh 5.2.3 → 5.2.4-alpha.1
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 +4 -2
- package/src/commands/api-mesh/__tests__/cache-purge.test.js +3 -4
- package/src/commands/api-mesh/__tests__/create.test.js +4 -19
- package/src/commands/api-mesh/__tests__/delete-log-forwarding.test.js +106 -0
- package/src/commands/api-mesh/__tests__/delete.test.js +3 -4
- package/src/commands/api-mesh/__tests__/describe.test.js +3 -5
- package/src/commands/api-mesh/__tests__/get-log-forwarding.test.js +149 -0
- package/src/commands/api-mesh/__tests__/get.test.js +4 -4
- package/src/commands/api-mesh/__tests__/log-get-bulk.test.js +21 -215
- 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 +2 -2
- 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 +6 -7
- package/src/commands/api-mesh/cache/purge.js +2 -4
- package/src/commands/api-mesh/config/delete/log-forwarding.js +80 -0
- 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 +21 -4
- package/src/commands/api-mesh/delete.js +2 -4
- package/src/commands/api-mesh/describe.js +2 -4
- package/src/commands/api-mesh/get.js +2 -4
- package/src/commands/api-mesh/log-get-bulk.js +6 -27
- package/src/commands/api-mesh/log-get.js +2 -4
- package/src/commands/api-mesh/log-list.js +2 -4
- package/src/commands/api-mesh/run.js +2 -9
- package/src/commands/api-mesh/source/__tests__/install.test.js +2 -2
- package/src/commands/api-mesh/source/discover.js +2 -9
- package/src/commands/api-mesh/source/get.js +1 -8
- package/src/commands/api-mesh/source/install.js +2 -3
- package/src/commands/api-mesh/status.js +2 -3
- package/src/commands/api-mesh/update.js +20 -4
- package/src/helpers.js +72 -5
- package/src/hooks/initMetadata.js +8 -0
- package/src/lib/{devConsole.js → smsClient.js} +299 -0
- package/src/utils.js +60 -22
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const { Command } = require('@oclif/core');
|
|
2
2
|
|
|
3
3
|
const logger = require('../../classes/logger');
|
|
4
|
-
const {
|
|
5
|
-
const { getMeshId, getMesh, getMeshDeployments } = require('../../lib/
|
|
4
|
+
const { initSdk } = require('../../helpers');
|
|
5
|
+
const { getMeshId, getMesh, getMeshDeployments } = require('../../lib/smsClient');
|
|
6
6
|
const { ignoreCacheFlag } = require('../../utils');
|
|
7
7
|
|
|
8
8
|
require('dotenv').config();
|
|
@@ -13,7 +13,6 @@ class StatusCommand extends Command {
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
async run() {
|
|
16
|
-
await initRequestId();
|
|
17
16
|
logger.info(`RequestId: ${global.requestId}`);
|
|
18
17
|
|
|
19
18
|
const { flags } = await this.parse(StatusCommand);
|
|
@@ -10,9 +10,10 @@ governing permissions and limitations under the License.
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
const { Command } = require('@oclif/command');
|
|
13
|
+
const chalk = require('chalk');
|
|
13
14
|
|
|
14
15
|
const logger = require('../../classes/logger');
|
|
15
|
-
const { initSdk,
|
|
16
|
+
const { initSdk, promptConfirm, importFiles } = require('../../helpers');
|
|
16
17
|
const {
|
|
17
18
|
ignoreCacheFlag,
|
|
18
19
|
autoConfirmActionFlag,
|
|
@@ -26,7 +27,7 @@ const {
|
|
|
26
27
|
validateSecretsFile,
|
|
27
28
|
encryptSecrets,
|
|
28
29
|
} = require('../../utils');
|
|
29
|
-
const { getMeshId, updateMesh, getPublicEncryptionKey } = require('../../lib/
|
|
30
|
+
const { getMeshId, updateMesh, getPublicEncryptionKey } = require('../../lib/smsClient');
|
|
30
31
|
|
|
31
32
|
class UpdateCommand extends Command {
|
|
32
33
|
static args = [{ name: 'file' }];
|
|
@@ -38,8 +39,6 @@ class UpdateCommand extends Command {
|
|
|
38
39
|
};
|
|
39
40
|
|
|
40
41
|
async run() {
|
|
41
|
-
await initRequestId();
|
|
42
|
-
|
|
43
42
|
logger.info(`RequestId: ${global.requestId}`);
|
|
44
43
|
|
|
45
44
|
const { args, flags } = await this.parse(UpdateCommand);
|
|
@@ -129,6 +128,23 @@ class UpdateCommand extends Command {
|
|
|
129
128
|
if (meshId) {
|
|
130
129
|
let shouldContinue = true;
|
|
131
130
|
|
|
131
|
+
if (
|
|
132
|
+
data?.meshConfig?.responseConfig?.includeHTTPDetails &&
|
|
133
|
+
workspaceName.toLowerCase() === 'production'
|
|
134
|
+
) {
|
|
135
|
+
this.warn(
|
|
136
|
+
`Your mesh has ${chalk.yellowBright('includeHTTPDetails')} set to ${chalk.redBright(
|
|
137
|
+
'true',
|
|
138
|
+
)}. This is a security risk and should not be used in production.\n` +
|
|
139
|
+
`When ${chalk.yellowBright('includeHTTPDetails')} is set to ${chalk.redBright(
|
|
140
|
+
'true',
|
|
141
|
+
)} it exposes HTTP request and response details in the mesh logs, which can cause sensitive information to be exposed.\n` +
|
|
142
|
+
`Consider setting ${chalk.yellowBright('includeHTTPDetails')} to ${chalk.greenBright(
|
|
143
|
+
'false',
|
|
144
|
+
)} in the meshConfig.`,
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
132
148
|
if (!autoConfirmAction) {
|
|
133
149
|
shouldContinue = await promptConfirm(
|
|
134
150
|
`Are you sure you want to update the mesh: ${meshId}?`,
|
package/src/helpers.js
CHANGED
|
@@ -437,10 +437,38 @@ async function initSdk(options) {
|
|
|
437
437
|
/**
|
|
438
438
|
* Generates a static global requestid for the lifecycle of this command request
|
|
439
439
|
*/
|
|
440
|
-
|
|
440
|
+
function initRequestId() {
|
|
441
441
|
global.requestId = UUID.newUuid().toString();
|
|
442
442
|
}
|
|
443
443
|
|
|
444
|
+
/**
|
|
445
|
+
*
|
|
446
|
+
* This function initializes the metadata headers for the command execution
|
|
447
|
+
*
|
|
448
|
+
* @param {*} config
|
|
449
|
+
*/
|
|
450
|
+
function initMetadata(config) {
|
|
451
|
+
try {
|
|
452
|
+
const { version, plugins, userAgent, platform, arch } = config;
|
|
453
|
+
const currentIntalledVersion = getCurrentInstalledPluginVersion(plugins);
|
|
454
|
+
|
|
455
|
+
const metadataHeaders = {
|
|
456
|
+
'x-aio-cli-version': version,
|
|
457
|
+
'x-aio-cli-user-agent': userAgent,
|
|
458
|
+
'x-aio-cli-platform': platform,
|
|
459
|
+
'x-aio-cli-arch': arch,
|
|
460
|
+
'x-aio-cli-plugin-api-mesh-version': currentIntalledVersion,
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
global.metadataHeaders = metadataHeaders;
|
|
464
|
+
} catch (error) {
|
|
465
|
+
logger.error('Unable to initialize metadata headers');
|
|
466
|
+
logger.error(error.message);
|
|
467
|
+
|
|
468
|
+
global.metadataHeaders = {};
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
444
472
|
/**
|
|
445
473
|
* Function to run the CLI Y/N prompt to confirm the user's action
|
|
446
474
|
*
|
|
@@ -519,6 +547,24 @@ async function promptInput(message) {
|
|
|
519
547
|
return selected.item;
|
|
520
548
|
}
|
|
521
549
|
|
|
550
|
+
/**
|
|
551
|
+
* Function to prompt for a secret/password input that masks the characters
|
|
552
|
+
*
|
|
553
|
+
* @param {string} message - prompt message
|
|
554
|
+
* @returns {Promise<string>} - the entered secret value
|
|
555
|
+
*/
|
|
556
|
+
async function promptInputSecret(message) {
|
|
557
|
+
const selected = await inquirer.prompt([
|
|
558
|
+
{
|
|
559
|
+
name: 'item',
|
|
560
|
+
message,
|
|
561
|
+
type: 'password',
|
|
562
|
+
},
|
|
563
|
+
]);
|
|
564
|
+
|
|
565
|
+
return selected.item;
|
|
566
|
+
}
|
|
567
|
+
|
|
522
568
|
/**
|
|
523
569
|
* Import the files in the files array in meshConfig
|
|
524
570
|
*
|
|
@@ -894,17 +940,36 @@ async function writeSecretsFile(secretsData, meshId) {
|
|
|
894
940
|
|
|
895
941
|
/**
|
|
896
942
|
*
|
|
897
|
-
* This function
|
|
943
|
+
* This function gets the current installed version of the plugin
|
|
898
944
|
*
|
|
899
945
|
* @param {*} installedPlugins
|
|
900
|
-
* @returns {
|
|
946
|
+
* @returns {string || null} - current installed version of the plugin
|
|
901
947
|
*/
|
|
902
|
-
|
|
948
|
+
function getCurrentInstalledPluginVersion(installedPlugins) {
|
|
903
949
|
try {
|
|
904
950
|
const meshPlugin = installedPlugins.find(
|
|
905
951
|
({ name }) => name === '@adobe/aio-cli-plugin-api-mesh',
|
|
906
952
|
);
|
|
907
|
-
|
|
953
|
+
|
|
954
|
+
return meshPlugin.version;
|
|
955
|
+
} catch (err) {
|
|
956
|
+
logger.error('Unable to get current installed version');
|
|
957
|
+
logger.error(err.message);
|
|
958
|
+
|
|
959
|
+
return null;
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
/**
|
|
964
|
+
*
|
|
965
|
+
* This function fetches current installed version the system and the latest version from npm
|
|
966
|
+
*
|
|
967
|
+
* @param {*} installedPlugins
|
|
968
|
+
* @returns { currentVersion: string, latestVersion: string }
|
|
969
|
+
*/
|
|
970
|
+
async function getPluginVersionDetails(installedPlugins) {
|
|
971
|
+
try {
|
|
972
|
+
const currentVersion = getCurrentInstalledPluginVersion(installedPlugins);
|
|
908
973
|
|
|
909
974
|
let config = {
|
|
910
975
|
method: 'get',
|
|
@@ -959,10 +1024,12 @@ module.exports = {
|
|
|
959
1024
|
objToString,
|
|
960
1025
|
promptInput,
|
|
961
1026
|
promptConfirm,
|
|
1027
|
+
promptInputSecret,
|
|
962
1028
|
getLibConsoleCLI,
|
|
963
1029
|
getDevConsoleConfig,
|
|
964
1030
|
initSdk,
|
|
965
1031
|
initRequestId,
|
|
1032
|
+
initMetadata,
|
|
966
1033
|
promptSelect,
|
|
967
1034
|
promptMultiselect,
|
|
968
1035
|
importFiles,
|
|
@@ -119,6 +119,7 @@ const listLogs = async (organizationCode, projectId, workspaceId, meshId, fileNa
|
|
|
119
119
|
method: 'get',
|
|
120
120
|
url: fileName ? url + `?filename=${fileName}` : url,
|
|
121
121
|
headers: {
|
|
122
|
+
...global?.metadataHeaders,
|
|
122
123
|
'Authorization': `Bearer ${accessToken}`,
|
|
123
124
|
'x-request-id': global.requestId,
|
|
124
125
|
'x-api-key': SMS_API_KEY,
|
|
@@ -147,6 +148,7 @@ const getMesh = async (organizationId, projectId, workspaceId, workspaceName, me
|
|
|
147
148
|
method: 'get',
|
|
148
149
|
url: `${SMS_BASE_URL}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}`,
|
|
149
150
|
headers: {
|
|
151
|
+
...global?.metadataHeaders,
|
|
150
152
|
'Authorization': `Bearer ${accessToken}`,
|
|
151
153
|
'x-request-id': global.requestId,
|
|
152
154
|
'workspaceName': workspaceName,
|
|
@@ -238,6 +240,7 @@ const createMesh = async (
|
|
|
238
240
|
method: 'post',
|
|
239
241
|
url: `${SMS_BASE_URL}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes`,
|
|
240
242
|
headers: {
|
|
243
|
+
...global?.metadataHeaders,
|
|
241
244
|
'Authorization': `Bearer ${accessToken}`,
|
|
242
245
|
'Content-Type': 'application/json',
|
|
243
246
|
'x-request-id': global.requestId,
|
|
@@ -350,6 +353,7 @@ const updateMesh = async (
|
|
|
350
353
|
method: 'put',
|
|
351
354
|
url: `${SMS_BASE_URL}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}`,
|
|
352
355
|
headers: {
|
|
356
|
+
...global?.metadataHeaders,
|
|
353
357
|
'Authorization': `Bearer ${accessToken}`,
|
|
354
358
|
'Content-Type': 'application/json',
|
|
355
359
|
'x-request-id': global.requestId,
|
|
@@ -441,6 +445,7 @@ const deleteMesh = async (organizationId, projectId, workspaceId, meshId) => {
|
|
|
441
445
|
method: 'delete',
|
|
442
446
|
url: `${SMS_BASE_URL}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}`,
|
|
443
447
|
headers: {
|
|
448
|
+
...global?.metadataHeaders,
|
|
444
449
|
'Authorization': `Bearer ${accessToken}`,
|
|
445
450
|
'x-request-id': global.requestId,
|
|
446
451
|
'x-api-key': SMS_API_KEY,
|
|
@@ -527,6 +532,7 @@ const cachePurge = async (organizationId, projectId, workspaceId, meshId) => {
|
|
|
527
532
|
method: 'post',
|
|
528
533
|
url: `${SMS_BASE_URL}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}/cache/purge`,
|
|
529
534
|
headers: {
|
|
535
|
+
...global?.metadataHeaders,
|
|
530
536
|
'Authorization': `Bearer ${accessToken}`,
|
|
531
537
|
'Content-Type': 'application/json',
|
|
532
538
|
'x-request-id': global.requestId,
|
|
@@ -617,6 +623,7 @@ const getMeshId = async (organizationCode, projectId, workspaceId, workspaceName
|
|
|
617
623
|
method: 'get',
|
|
618
624
|
url: `${SMS_BASE_URL}/organizations/${organizationCode}/projects/${projectId}/workspaces/${workspaceId}/mesh`,
|
|
619
625
|
headers: {
|
|
626
|
+
...global?.metadataHeaders,
|
|
620
627
|
'Authorization': `Bearer ${accessToken}`,
|
|
621
628
|
'x-request-id': global.requestId,
|
|
622
629
|
'workspaceName': workspaceName,
|
|
@@ -903,6 +910,7 @@ const getMeshArtifact = async (organizationId, projectId, workspaceId, workspace
|
|
|
903
910
|
method: 'get',
|
|
904
911
|
url: `${SMS_BASE_URL}/organizations/${organizationId}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}/artifact`,
|
|
905
912
|
headers: {
|
|
913
|
+
...global?.metadataHeaders,
|
|
906
914
|
'Authorization': `Bearer ${accessToken}`,
|
|
907
915
|
'x-request-id': global.requestId,
|
|
908
916
|
'workspaceName': workspaceName,
|
|
@@ -961,6 +969,7 @@ const getTenantFeatures = async organizationCode => {
|
|
|
961
969
|
method: 'get',
|
|
962
970
|
url: `${SMS_BASE_URL}/organizations/${organizationCode}/features`,
|
|
963
971
|
headers: {
|
|
972
|
+
...global?.metadataHeaders,
|
|
964
973
|
'Authorization': `Bearer ${accessToken}`,
|
|
965
974
|
'x-request-id': global.requestId,
|
|
966
975
|
'x-api-key': SMS_API_KEY,
|
|
@@ -1016,6 +1025,7 @@ const getMeshDeployments = async (organizationCode, projectId, workspaceId, mesh
|
|
|
1016
1025
|
method: 'get',
|
|
1017
1026
|
url: `${SMS_BASE_URL}/organizations/${organizationCode}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}/deployments/latest`,
|
|
1018
1027
|
headers: {
|
|
1028
|
+
...global?.metadataHeaders,
|
|
1019
1029
|
'Authorization': `Bearer ${accessToken}`,
|
|
1020
1030
|
'x-request-id': global.requestId,
|
|
1021
1031
|
'x-api-key': SMS_API_KEY,
|
|
@@ -1072,6 +1082,7 @@ const getPublicEncryptionKey = async organizationCode => {
|
|
|
1072
1082
|
method: 'get',
|
|
1073
1083
|
url: `${SMS_BASE_URL}/organizations/${organizationCode}/getPublicKey`,
|
|
1074
1084
|
headers: {
|
|
1085
|
+
...global?.metadataHeaders,
|
|
1075
1086
|
'Authorization': `Bearer ${accessToken}`,
|
|
1076
1087
|
'x-request-id': global.requestId,
|
|
1077
1088
|
'x-api-key': SMS_API_KEY,
|
|
@@ -1117,6 +1128,7 @@ const getPresignedUrls = async (
|
|
|
1117
1128
|
method: 'get',
|
|
1118
1129
|
url: `${SMS_BASE_URL}/organizations/${organizationCode}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}/logs?startDateTime=${startTime}&endDateTime=${endTime}`,
|
|
1119
1130
|
headers: {
|
|
1131
|
+
...global?.metadataHeaders,
|
|
1120
1132
|
'Authorization': `Bearer ${accessToken}`,
|
|
1121
1133
|
'x-request-id': global.requestId,
|
|
1122
1134
|
'x-api-key': SMS_API_KEY,
|
|
@@ -1156,6 +1168,7 @@ const getLogsByRayId = async (organizationCode, projectId, workspaceId, meshId,
|
|
|
1156
1168
|
method: 'get',
|
|
1157
1169
|
url: `${SMS_BASE_URL}/organizations/${organizationCode}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}/logs/${rayId}`,
|
|
1158
1170
|
headers: {
|
|
1171
|
+
...global?.metadataHeaders,
|
|
1159
1172
|
'Authorization': `Bearer ${accessToken}`,
|
|
1160
1173
|
'x-request-id': global.requestId,
|
|
1161
1174
|
'x-api-key': SMS_API_KEY,
|
|
@@ -1201,6 +1214,289 @@ const getLogsByRayId = async (organizationCode, projectId, workspaceId, meshId,
|
|
|
1201
1214
|
}
|
|
1202
1215
|
};
|
|
1203
1216
|
|
|
1217
|
+
/**
|
|
1218
|
+
* @param {string} organizationCode - The IMS org code
|
|
1219
|
+
* @param {string} projectId - The project ID
|
|
1220
|
+
* @param {string} workspaceId - The workspace ID
|
|
1221
|
+
* @param {string} meshId - The mesh ID
|
|
1222
|
+
* @param {Object} logConfig - The log forwarding configuration
|
|
1223
|
+
*/
|
|
1224
|
+
const setLogForwarding = async (organizationCode, projectId, workspaceId, meshId, logConfig) => {
|
|
1225
|
+
const { accessToken } = await getDevConsoleConfig();
|
|
1226
|
+
const config = {
|
|
1227
|
+
method: 'POST',
|
|
1228
|
+
url: `${SMS_BASE_URL}/organizations/${organizationCode}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}/log/forwarding`,
|
|
1229
|
+
headers: {
|
|
1230
|
+
'Authorization': `Bearer ${accessToken}`,
|
|
1231
|
+
'Content-Type': 'application/json',
|
|
1232
|
+
'x-request-id': global.requestId,
|
|
1233
|
+
'x-api-key': SMS_API_KEY,
|
|
1234
|
+
},
|
|
1235
|
+
data: JSON.stringify(logConfig),
|
|
1236
|
+
};
|
|
1237
|
+
|
|
1238
|
+
logger.info(
|
|
1239
|
+
'Initiating POST %s',
|
|
1240
|
+
`${SMS_BASE_URL}/organizations/${organizationCode}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}/log/forwarding`,
|
|
1241
|
+
);
|
|
1242
|
+
|
|
1243
|
+
try {
|
|
1244
|
+
const response = await axios(config);
|
|
1245
|
+
|
|
1246
|
+
logger.info('Response from POST %s', response.status);
|
|
1247
|
+
|
|
1248
|
+
if (response?.status === 200) {
|
|
1249
|
+
logger.info(`Log forwarding configuration: ${objToString(response, ['data'])}`);
|
|
1250
|
+
return {
|
|
1251
|
+
result: response.data.result,
|
|
1252
|
+
message: response.data.message,
|
|
1253
|
+
};
|
|
1254
|
+
} else {
|
|
1255
|
+
// not 200 response
|
|
1256
|
+
logger.error(
|
|
1257
|
+
`Something went wrong: ${objToString(
|
|
1258
|
+
response,
|
|
1259
|
+
['data'],
|
|
1260
|
+
'Unable to set log forwarding details.',
|
|
1261
|
+
)}. Received ${response.status}, expected 200`,
|
|
1262
|
+
);
|
|
1263
|
+
throw new Error(response.data.message);
|
|
1264
|
+
}
|
|
1265
|
+
} catch (error) {
|
|
1266
|
+
if (error.response && error.response.status === 400) {
|
|
1267
|
+
// The request was made and the server responded with a 400 status code
|
|
1268
|
+
logger.error('Error setting log forwarding configuration: %j', error.response.data);
|
|
1269
|
+
|
|
1270
|
+
throw new Error('Invalid input parameters.');
|
|
1271
|
+
}
|
|
1272
|
+
// request made but no response received
|
|
1273
|
+
else if (error.request && !error.response) {
|
|
1274
|
+
logger.error('No response received from server when setting log forwarding configuration');
|
|
1275
|
+
throw new Error('Unable to set log forwarding details. Check the details and try again.');
|
|
1276
|
+
}
|
|
1277
|
+
// response received with error
|
|
1278
|
+
else if (error.response && error.response.data) {
|
|
1279
|
+
logger.error(
|
|
1280
|
+
'Error setting log forwarding configuration: %s',
|
|
1281
|
+
objToString(error, ['response', 'data'], 'Unable to set log forwarding'),
|
|
1282
|
+
);
|
|
1283
|
+
|
|
1284
|
+
// response a message or messages field
|
|
1285
|
+
|
|
1286
|
+
if (error.response.data.message || error.response.data.messages) {
|
|
1287
|
+
const message = objToString(
|
|
1288
|
+
error,
|
|
1289
|
+
['response', 'data', 'message' || 'messages'],
|
|
1290
|
+
'Unable to set log forwarding',
|
|
1291
|
+
);
|
|
1292
|
+
throw new Error(message);
|
|
1293
|
+
}
|
|
1294
|
+
// response contains error but no specific message field
|
|
1295
|
+
else {
|
|
1296
|
+
const message = objToString(error, ['response', 'data'], 'Unable to set log forwarding');
|
|
1297
|
+
throw new Error(message);
|
|
1298
|
+
}
|
|
1299
|
+
} else {
|
|
1300
|
+
// Something else happened while setting up the request
|
|
1301
|
+
logger.error('Error setting log forwarding configuration: %s', error.message);
|
|
1302
|
+
throw new Error(`Something went wrong while setting log forwarding. ${error.message}`);
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
};
|
|
1306
|
+
|
|
1307
|
+
/**
|
|
1308
|
+
* @param {string} organizationCode - The IMS org code
|
|
1309
|
+
* @param {string} projectId - The project ID
|
|
1310
|
+
* @param {string} workspaceId - The workspace ID
|
|
1311
|
+
* @param {string} meshId - The mesh ID
|
|
1312
|
+
*/
|
|
1313
|
+
const getLogForwarding = async (organizationCode, projectId, workspaceId, meshId) => {
|
|
1314
|
+
const { accessToken } = await getDevConsoleConfig();
|
|
1315
|
+
const config = {
|
|
1316
|
+
method: 'GET',
|
|
1317
|
+
url: `${SMS_BASE_URL}/organizations/${organizationCode}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}/log/forwarding`,
|
|
1318
|
+
headers: {
|
|
1319
|
+
'Authorization': `Bearer ${accessToken}`,
|
|
1320
|
+
'Content-Type': 'application/json',
|
|
1321
|
+
'x-request-id': global.requestId,
|
|
1322
|
+
'x-api-key': SMS_API_KEY,
|
|
1323
|
+
},
|
|
1324
|
+
};
|
|
1325
|
+
|
|
1326
|
+
logger.info(
|
|
1327
|
+
'Initiating POST %s',
|
|
1328
|
+
`${SMS_BASE_URL}/organizations/${organizationCode}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}/log/forwarding`,
|
|
1329
|
+
);
|
|
1330
|
+
|
|
1331
|
+
try {
|
|
1332
|
+
const response = await axios(config);
|
|
1333
|
+
|
|
1334
|
+
logger.info('Response from GET %s', response.status);
|
|
1335
|
+
|
|
1336
|
+
if (response?.status === 200) {
|
|
1337
|
+
logger.info(`Get log forwarding configuration: ${objToString(response, ['data'])}`);
|
|
1338
|
+
return {
|
|
1339
|
+
data: response.data,
|
|
1340
|
+
};
|
|
1341
|
+
} else {
|
|
1342
|
+
// not 200 response
|
|
1343
|
+
logger.error(
|
|
1344
|
+
`Something went wrong: ${objToString(
|
|
1345
|
+
response,
|
|
1346
|
+
['data'],
|
|
1347
|
+
'Unable to get log forwarding details.',
|
|
1348
|
+
)}. Received ${response.status}, expected 200`,
|
|
1349
|
+
);
|
|
1350
|
+
throw new Error(response.data.message);
|
|
1351
|
+
}
|
|
1352
|
+
} catch (error) {
|
|
1353
|
+
if (error.response && error.response.status === 400) {
|
|
1354
|
+
// The request was made and the server responded with a 400 status code
|
|
1355
|
+
logger.error('Error getting the log forwarding configuration: %j', error.response.data);
|
|
1356
|
+
|
|
1357
|
+
throw new Error('Invalid input parameters.');
|
|
1358
|
+
} else if (error.response && error.response.status === 404) {
|
|
1359
|
+
logger.error('Log forwarding details not found');
|
|
1360
|
+
|
|
1361
|
+
return null;
|
|
1362
|
+
}
|
|
1363
|
+
// request made but no response received
|
|
1364
|
+
else if (error.request && !error.response) {
|
|
1365
|
+
logger.error('No response from server when getting the log forwarding configuration');
|
|
1366
|
+
throw new Error('Unable to get log forwarding details. Check the details and try again.');
|
|
1367
|
+
}
|
|
1368
|
+
// response received with error
|
|
1369
|
+
else if (error.response && error.response.data) {
|
|
1370
|
+
logger.error(
|
|
1371
|
+
'Error getting the log forwarding configuration: %s',
|
|
1372
|
+
objToString(error, ['response', 'data'], 'Unable to get log forwarding'),
|
|
1373
|
+
);
|
|
1374
|
+
|
|
1375
|
+
// response a message or messages field
|
|
1376
|
+
|
|
1377
|
+
if (error.response.data.message || error.response.data.messages) {
|
|
1378
|
+
const message = objToString(
|
|
1379
|
+
error,
|
|
1380
|
+
['response', 'data', 'message' || 'messages'],
|
|
1381
|
+
'Unable to get log forwarding',
|
|
1382
|
+
);
|
|
1383
|
+
throw new Error(message);
|
|
1384
|
+
}
|
|
1385
|
+
// response contains error but no specific message field
|
|
1386
|
+
else {
|
|
1387
|
+
const message = objToString(error, ['response', 'data'], 'Unable to get log forwarding');
|
|
1388
|
+
throw new Error(message);
|
|
1389
|
+
}
|
|
1390
|
+
} else {
|
|
1391
|
+
// Something else happened while setting up the request
|
|
1392
|
+
logger.error('Error getting the log forwarding configuration: %s', error.message);
|
|
1393
|
+
throw new Error(
|
|
1394
|
+
`Something went wrong while getting the log forwarding configuration. ${error.message}`,
|
|
1395
|
+
);
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
};
|
|
1399
|
+
|
|
1400
|
+
/**
|
|
1401
|
+
* Deletes the log forwarding configuration for a given mesh.
|
|
1402
|
+
*
|
|
1403
|
+
* @param {string} organizationCode - The IMS org code
|
|
1404
|
+
* @param {string} projectId - The project ID
|
|
1405
|
+
* @param {string} workspaceId - The workspace ID
|
|
1406
|
+
* @param {string} meshId - The mesh ID
|
|
1407
|
+
*/
|
|
1408
|
+
const deleteLogForwarding = async (organizationCode, projectId, workspaceId, meshId) => {
|
|
1409
|
+
const { accessToken } = await getDevConsoleConfig();
|
|
1410
|
+
const config = {
|
|
1411
|
+
method: 'DELETE',
|
|
1412
|
+
url: `${SMS_BASE_URL}/organizations/${organizationCode}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}/log/forwarding`,
|
|
1413
|
+
headers: {
|
|
1414
|
+
'Authorization': `Bearer ${accessToken}`,
|
|
1415
|
+
'x-request-id': global.requestId,
|
|
1416
|
+
'x-api-key': SMS_API_KEY,
|
|
1417
|
+
},
|
|
1418
|
+
};
|
|
1419
|
+
|
|
1420
|
+
logger.info(
|
|
1421
|
+
'Initiating DELETE %s',
|
|
1422
|
+
`${SMS_BASE_URL}/organizations/${organizationCode}/projects/${projectId}/workspaces/${workspaceId}/meshes/${meshId}/log/forwarding`,
|
|
1423
|
+
);
|
|
1424
|
+
|
|
1425
|
+
try {
|
|
1426
|
+
const response = await axios(config);
|
|
1427
|
+
|
|
1428
|
+
logger.info('Response from DELETE %s', response.status);
|
|
1429
|
+
|
|
1430
|
+
if (response && response?.status === 204) {
|
|
1431
|
+
return response;
|
|
1432
|
+
} else {
|
|
1433
|
+
logger.error(
|
|
1434
|
+
`Unable to delete log forwarding config: ${objToString(
|
|
1435
|
+
response,
|
|
1436
|
+
['data'],
|
|
1437
|
+
'Error',
|
|
1438
|
+
)}. Received ${response.status}, expected 204`,
|
|
1439
|
+
);
|
|
1440
|
+
throw new Error(
|
|
1441
|
+
`something went wrong: ${objToString(
|
|
1442
|
+
response,
|
|
1443
|
+
['data'],
|
|
1444
|
+
'Unable to delete log forwarding',
|
|
1445
|
+
)}`,
|
|
1446
|
+
);
|
|
1447
|
+
}
|
|
1448
|
+
} catch (error) {
|
|
1449
|
+
logger.info('Response from DELETE %s', error.response.status);
|
|
1450
|
+
|
|
1451
|
+
if (error.response.status === 404) {
|
|
1452
|
+
// The request was made and the server responded with a 404 status code
|
|
1453
|
+
logger.error('log forwarding details not found');
|
|
1454
|
+
|
|
1455
|
+
throw new Error('log forwarding details not found');
|
|
1456
|
+
} else if (error.response && error.response.data) {
|
|
1457
|
+
// The request was made and the server responded with an unsupported status code
|
|
1458
|
+
logger.error(
|
|
1459
|
+
'Error while deleting log forwarding details. Response: %s',
|
|
1460
|
+
objToString(error, ['response', 'data'], 'Unable to delete log forwarding details'),
|
|
1461
|
+
);
|
|
1462
|
+
|
|
1463
|
+
if (error.response.data.messages) {
|
|
1464
|
+
const message = objToString(
|
|
1465
|
+
error,
|
|
1466
|
+
['response', 'data', 'messages', '0', 'message'],
|
|
1467
|
+
'Unable to delete log forwarding details',
|
|
1468
|
+
);
|
|
1469
|
+
|
|
1470
|
+
throw new Error(message);
|
|
1471
|
+
} else if (error.response.data.message) {
|
|
1472
|
+
const message = objToString(
|
|
1473
|
+
error,
|
|
1474
|
+
['response', 'data', 'message'],
|
|
1475
|
+
'Unable to delete log forwarding details',
|
|
1476
|
+
);
|
|
1477
|
+
|
|
1478
|
+
throw new Error(message);
|
|
1479
|
+
} else {
|
|
1480
|
+
const message = objToString(
|
|
1481
|
+
error,
|
|
1482
|
+
['response', 'data'],
|
|
1483
|
+
'Unable to delete log forwarding details',
|
|
1484
|
+
);
|
|
1485
|
+
|
|
1486
|
+
throw new Error(message);
|
|
1487
|
+
}
|
|
1488
|
+
} else {
|
|
1489
|
+
// The request was made but no response was received
|
|
1490
|
+
logger.error(
|
|
1491
|
+
'Error while deleting log forwarding details. No response received from the server: %s',
|
|
1492
|
+
objToString(error, [], 'Unable to delete log forwarding details'),
|
|
1493
|
+
);
|
|
1494
|
+
|
|
1495
|
+
throw new Error('Unable to delete log forwarding details: %s', error.message);
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
};
|
|
1499
|
+
|
|
1204
1500
|
module.exports = {
|
|
1205
1501
|
getApiKeyCredential,
|
|
1206
1502
|
describeMesh,
|
|
@@ -1222,4 +1518,7 @@ module.exports = {
|
|
|
1222
1518
|
getPresignedUrls,
|
|
1223
1519
|
getLogsByRayId,
|
|
1224
1520
|
cachePurge,
|
|
1521
|
+
setLogForwarding,
|
|
1522
|
+
getLogForwarding,
|
|
1523
|
+
deleteLogForwarding,
|
|
1225
1524
|
};
|