@ampsec/platform-client 79.4.1 → 79.6.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/build/src/dto/enums/engagementChannelKind.d.ts +2 -1
- package/build/src/dto/enums/engagementChannelKind.js +1 -0
- package/build/src/dto/enums/engagementChannelKind.js.map +1 -1
- package/build/src/services/ContentTemplateService.d.ts +9 -0
- package/build/src/services/ContentTemplateService.js +63 -1
- package/build/src/services/ContentTemplateService.js.map +1 -1
- package/build/src/services/constants.d.ts +30 -0
- package/build/src/services/constants.js +36 -1
- package/build/src/services/constants.js.map +1 -1
- package/package.json +1 -1
- package/src/dto/enums/engagementChannelKind.ts +1 -0
- package/src/services/ContentTemplateService.ts +69 -0
- package/src/services/constants.ts +36 -0
|
@@ -5,5 +5,6 @@ var EngagementChannelKind;
|
|
|
5
5
|
(function (EngagementChannelKind) {
|
|
6
6
|
EngagementChannelKind["SLACK"] = "SLACK";
|
|
7
7
|
EngagementChannelKind["CHROME_EXTENSION"] = "CHROME_EXTENSION";
|
|
8
|
+
EngagementChannelKind["TEAMS"] = "TEAMS";
|
|
8
9
|
})(EngagementChannelKind || (exports.EngagementChannelKind = EngagementChannelKind = {}));
|
|
9
10
|
//# sourceMappingURL=engagementChannelKind.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engagementChannelKind.js","sourceRoot":"","sources":["../../../../src/dto/enums/engagementChannelKind.ts"],"names":[],"mappings":";;;AAAA,IAAY,
|
|
1
|
+
{"version":3,"file":"engagementChannelKind.js","sourceRoot":"","sources":["../../../../src/dto/enums/engagementChannelKind.ts"],"names":[],"mappings":";;;AAAA,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC/B,wCAAe,CAAA;IACf,8DAAqC,CAAA;IACrC,wCAAe,CAAA;AACjB,CAAC,EAJW,qBAAqB,qCAArB,qBAAqB,QAIhC"}
|
|
@@ -1 +1,10 @@
|
|
|
1
|
+
import { FindingDto } from '../dto';
|
|
1
2
|
export declare const fillJsonPathTemplate: (raw: string, meta: unknown) => string;
|
|
3
|
+
/**
|
|
4
|
+
* @param rawTemplateString Template string with placeholders in the format of {{path.to.value}}
|
|
5
|
+
* @param meta object containing the values to replace the placeholders
|
|
6
|
+
* @returns string with placeholders replaced with values from the meta object
|
|
7
|
+
* @note Ensure that meta object does not contain any information that should not be exposed to end users
|
|
8
|
+
*/
|
|
9
|
+
export declare const fillDynamicPropertyTemplate: (rawTemplateString: string, meta: unknown) => string;
|
|
10
|
+
export declare const buildDynamicVariablesContext: (finding: FindingDto) => Map<string, unknown>;
|
|
@@ -3,9 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.fillJsonPathTemplate = void 0;
|
|
6
|
+
exports.buildDynamicVariablesContext = exports.fillDynamicPropertyTemplate = exports.fillJsonPathTemplate = void 0;
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const constants_1 = require("./constants");
|
|
8
9
|
const JSON_PATH_PATTERN = /(\$\.(?:(?:[a-zA-Z0-9_]+)(?:\.[a-zA-Z0-9_]+)*)?)/g;
|
|
10
|
+
const DYNAMIC_PROPERTY_PATTERN = /\{\{([^}]+)\}\}/g;
|
|
11
|
+
// @deprecated : consider using fillDynamicPropertyTemplate
|
|
9
12
|
const fillJsonPathTemplate = (raw, meta) => {
|
|
10
13
|
const jsonPathMatches = raw.match(JSON_PATH_PATTERN);
|
|
11
14
|
let result = raw;
|
|
@@ -22,4 +25,63 @@ const fillJsonPathTemplate = (raw, meta) => {
|
|
|
22
25
|
return result;
|
|
23
26
|
};
|
|
24
27
|
exports.fillJsonPathTemplate = fillJsonPathTemplate;
|
|
28
|
+
/**
|
|
29
|
+
* @param rawTemplateString Template string with placeholders in the format of {{path.to.value}}
|
|
30
|
+
* @param meta object containing the values to replace the placeholders
|
|
31
|
+
* @returns string with placeholders replaced with values from the meta object
|
|
32
|
+
* @note Ensure that meta object does not contain any information that should not be exposed to end users
|
|
33
|
+
*/
|
|
34
|
+
const fillDynamicPropertyTemplate = (rawTemplateString, meta) => {
|
|
35
|
+
let result = rawTemplateString;
|
|
36
|
+
const matches = rawTemplateString.match(DYNAMIC_PROPERTY_PATTERN);
|
|
37
|
+
if (matches) {
|
|
38
|
+
matches.forEach(placeholder => {
|
|
39
|
+
const path = placeholder.slice(2, -2).trim();
|
|
40
|
+
const value = lodash_1.default.get(meta, path, undefined);
|
|
41
|
+
if (lodash_1.default.isString(value) || lodash_1.default.isNumber(value) || lodash_1.default.isBoolean(value)) {
|
|
42
|
+
// primitive value type is replaced as is
|
|
43
|
+
result = result.replace(placeholder, value);
|
|
44
|
+
}
|
|
45
|
+
else if (lodash_1.default.isObject(value) || lodash_1.default.isArray(value)) {
|
|
46
|
+
// object and array values are stringified
|
|
47
|
+
result = result.replace(placeholder, JSON.stringify(value, null, 2));
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
// unknown value type is replaced with a placeholder
|
|
51
|
+
result = result.replace(placeholder, 'UNKNOWN_TEMPLATE_VALUE');
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
};
|
|
57
|
+
exports.fillDynamicPropertyTemplate = fillDynamicPropertyTemplate;
|
|
58
|
+
const populateDynamicVariablesEntityData = (entityProperties, baseObject, fallbackObject = undefined) => {
|
|
59
|
+
const entityData = {};
|
|
60
|
+
for (const key in entityProperties) {
|
|
61
|
+
const findingKeyPath = entityProperties[key];
|
|
62
|
+
entityData[key] = lodash_1.default.get(baseObject, findingKeyPath) || (fallbackObject ? lodash_1.default.get(fallbackObject, findingKeyPath) : undefined);
|
|
63
|
+
}
|
|
64
|
+
return entityData;
|
|
65
|
+
};
|
|
66
|
+
const buildDynamicVariablesContext = (finding) => {
|
|
67
|
+
var _a;
|
|
68
|
+
const entityMap = new Map();
|
|
69
|
+
for (const entityName in constants_1.DYNAMIC_VARIABLES.ALLOWED_ENTITIES) {
|
|
70
|
+
const entityKey = constants_1.DYNAMIC_VARIABLES.ALLOWED_ENTITIES[entityName];
|
|
71
|
+
const entityProperties = constants_1.DYNAMIC_VARIABLES.ALLOWED_ENTITY_KEYS[entityKey];
|
|
72
|
+
let entityData = {};
|
|
73
|
+
if (entityName === 'finding') {
|
|
74
|
+
entityData = populateDynamicVariablesEntityData(entityProperties, finding);
|
|
75
|
+
}
|
|
76
|
+
else if (entityName === 'user' && ((_a = finding.meta) === null || _a === void 0 ? void 0 : _a._user)) {
|
|
77
|
+
entityData = populateDynamicVariablesEntityData(entityProperties, finding);
|
|
78
|
+
}
|
|
79
|
+
else if (entityName === 'asset' && finding.asset) {
|
|
80
|
+
entityData = populateDynamicVariablesEntityData(entityProperties, finding.asset, finding);
|
|
81
|
+
}
|
|
82
|
+
entityMap.set(entityName, entityData);
|
|
83
|
+
}
|
|
84
|
+
return entityMap;
|
|
85
|
+
};
|
|
86
|
+
exports.buildDynamicVariablesContext = buildDynamicVariablesContext;
|
|
25
87
|
//# sourceMappingURL=ContentTemplateService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentTemplateService.js","sourceRoot":"","sources":["../../../src/services/ContentTemplateService.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AACvB,MAAM,iBAAiB,GAAG,mDAAmD,CAAC;
|
|
1
|
+
{"version":3,"file":"ContentTemplateService.js","sourceRoot":"","sources":["../../../src/services/ContentTemplateService.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AACvB,2CAA8C;AAE9C,MAAM,iBAAiB,GAAG,mDAAmD,CAAC;AAC9E,MAAM,wBAAwB,GAAG,kBAAkB,CAAC;AAEpD,2DAA2D;AACpD,MAAM,oBAAoB,GAAG,CAAC,GAAW,EAAE,IAAa,EAAE,EAAE;IACjE,MAAM,e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;IAElD,KAAK,MAAM,UAAU,IAAI,6BAAiB,CAAC,gBAAgB,EAAE,CAAC;QAC5D,MAAM,SAAS,GAAG,6BAAiB,CAAC,gBAAgB,CAAC,UAA6D,CAAC,CAAC;QACpH,MAAM,gBAAgB,GAAG,6BAAiB,CAAC,mBAAmB,CAAC,SAA+D,CAAC,CAAC;QAEhI,IAAI,UAAU,GAA4B,EAAE,CAAC;QAE7C,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC7B,UAAU,GAAG,kCAAkC,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;QAC7E,CAAC;aAAM,IAAI,UAAU,KAAK,MAAM,KAAI,MAAA,OAAO,CAAC,IAAI,0CAAE,KAAK,CAAA,EAAE,CAAC;YACxD,UAAU,GAAG,kCAAkC,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;QAC7E,CAAC;aAAM,IAAI,UAAU,KAAK,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;YACnD,UAAU,GAAG,kCAAkC,CAAC,gBAAgB,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC5F,CAAC;QAED,SAAS,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACxC,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AArBW,QAAA,4BAA4B,gCAqBvC"}
|
|
@@ -58,3 +58,33 @@ export declare const REPORTS: {
|
|
|
58
58
|
SELF_HEALED: string;
|
|
59
59
|
HEALTH_SCORE_TREND: string;
|
|
60
60
|
};
|
|
61
|
+
export declare class DYNAMIC_VARIABLES {
|
|
62
|
+
static readonly ALLOWED_ENTITIES: {
|
|
63
|
+
finding: string;
|
|
64
|
+
user: string;
|
|
65
|
+
asset: string;
|
|
66
|
+
};
|
|
67
|
+
static readonly ALLOWED_ENTITY_KEYS: {
|
|
68
|
+
finding: {
|
|
69
|
+
displayValue: string;
|
|
70
|
+
description: string;
|
|
71
|
+
discoveredAt: string;
|
|
72
|
+
category: string;
|
|
73
|
+
severity: string;
|
|
74
|
+
kind: string;
|
|
75
|
+
};
|
|
76
|
+
user: {
|
|
77
|
+
firstName: string;
|
|
78
|
+
lastName: string;
|
|
79
|
+
organization: string;
|
|
80
|
+
department: string;
|
|
81
|
+
title: string;
|
|
82
|
+
email: string;
|
|
83
|
+
};
|
|
84
|
+
asset: {
|
|
85
|
+
displayValue: string;
|
|
86
|
+
serialNumber: string;
|
|
87
|
+
macAddress: string;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.REPORTS = exports.KIND = exports.TARGET_API_ENGAGE = exports.TARGET_API_AGENT = exports.TARGET_API_PLATFORM = exports.DEFAULT_TREND_WINDOW_MONTHS = void 0;
|
|
3
|
+
exports.DYNAMIC_VARIABLES = exports.REPORTS = exports.KIND = exports.TARGET_API_ENGAGE = exports.TARGET_API_AGENT = exports.TARGET_API_PLATFORM = exports.DEFAULT_TREND_WINDOW_MONTHS = void 0;
|
|
4
4
|
exports.DEFAULT_TREND_WINDOW_MONTHS = 6;
|
|
5
5
|
exports.TARGET_API_PLATFORM = 'platform';
|
|
6
6
|
exports.TARGET_API_AGENT = 'api';
|
|
@@ -58,4 +58,39 @@ exports.REPORTS = {
|
|
|
58
58
|
// trending reports
|
|
59
59
|
HEALTH_SCORE_TREND: 'monthly-health-trend',
|
|
60
60
|
};
|
|
61
|
+
class DYNAMIC_VARIABLES {
|
|
62
|
+
}
|
|
63
|
+
exports.DYNAMIC_VARIABLES = DYNAMIC_VARIABLES;
|
|
64
|
+
DYNAMIC_VARIABLES.ALLOWED_ENTITIES = {
|
|
65
|
+
// Public Keys : Private Keys
|
|
66
|
+
finding: 'finding',
|
|
67
|
+
user: 'user',
|
|
68
|
+
asset: 'asset',
|
|
69
|
+
};
|
|
70
|
+
DYNAMIC_VARIABLES.ALLOWED_ENTITY_KEYS = {
|
|
71
|
+
finding: {
|
|
72
|
+
// Public Keys : Private Keys
|
|
73
|
+
displayValue: 'displayValue',
|
|
74
|
+
description: 'description',
|
|
75
|
+
discoveredAt: 'discoveredAt',
|
|
76
|
+
category: 'category',
|
|
77
|
+
severity: 'severity',
|
|
78
|
+
kind: 'kind',
|
|
79
|
+
},
|
|
80
|
+
user: {
|
|
81
|
+
// Public Keys : Private Keys
|
|
82
|
+
firstName: 'meta._user.firstName',
|
|
83
|
+
lastName: 'meta._user.lastName',
|
|
84
|
+
organization: 'meta._user.organization',
|
|
85
|
+
department: 'meta._user.department',
|
|
86
|
+
title: 'meta._user.title',
|
|
87
|
+
email: 'meta._user.primaryEmail',
|
|
88
|
+
},
|
|
89
|
+
asset: {
|
|
90
|
+
// Public Keys : Private Keys
|
|
91
|
+
displayValue: 'displayValue',
|
|
92
|
+
serialNumber: 'meta._asset.sn',
|
|
93
|
+
macAddress: 'meta._asset.macs',
|
|
94
|
+
},
|
|
95
|
+
};
|
|
61
96
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/services/constants.ts"],"names":[],"mappings":";;;AAIa,QAAA,2BAA2B,GAAG,CAAC,CAAC;AAGhC,QAAA,mBAAmB,GAAc,UAAU,CAAC;AAC5C,QAAA,gBAAgB,GAAc,KAAK,CAAC;AACpC,QAAA,iBAAiB,GAAc,KAAK,CAAC;AAErC,QAAA,IAAI,GAAG;IAClB,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,UAAU,EAAE,YAAY;IACxB,eAAe,EAAE,iBAAiB;IAClC,cAAc,EAAE,gBAAgB;IAChC,oBAAoB,EAAE,sBAAsB;IAC5C,mBAAmB,EAAE,qBAAqB;IAC1C,wBAAwB,EAAE,0BAA0B;IACpD,gBAAgB,EAAE,aAAa;IAC/B,kBAAkB,EAAE,eAAe;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E,mBAAmB;IACtC,qBAAqB,EAAE,uBAAuB;IAC9C,2BAA2B,EAAE,6BAA6B;IAC1D,YAAY,EAAE,0BAA0B;IACxC,qBAAqB,EAAE,uBAAuB;IAC9C,gBAAgB,EAAE,kBAAkB;IACpC,WAAW,EAAE,aAAa;IAC1B,mBAAmB;IACnB,kBAAkB,EAAE,sBAAsB;CAC3C,CAAC;AAEF,MAAa,iBAAiB;;AAA9B,8CAkCC;AAjCiB,kCAAgB,GAAG;IACjC,6BAA6B;IAC7B,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;CACf,CAAC;AAEc,qCAAmB,GAAG;IACpC,OAAO,EAAE;QACP,6BAA6B;QAC7B,YAAY,EAAE,cAAc;QAC5B,WAAW,EAAE,aAAa;QAC1B,YAAY,EAAE,cAAc;QAC5B,QAAQ,EAAE,UAAU;QACpB,QAAQ,EAAE,UAAU;QACpB,IAAI,EAAE,MAAM;KACb;IACD,IAAI,EAAE;QACJ,6BAA6B;QAC7B,SAAS,EAAE,sBAAsB;QACjC,QAAQ,EAAE,qBAAqB;QAC/B,YAAY,EAAE,yBAAyB;QACvC,UAAU,EAAE,uBAAuB;QACnC,KAAK,EAAE,kBAAkB;QACzB,KAAK,EAAE,yBAAyB;KACjC;IACD,KAAK,EAAE;QACL,6BAA6B;QAC7B,YAAY,EAAE,cAAc;QAC5B,YAAY,EAAE,gBAAgB;QAC9B,UAAU,EAAE,kBAAkB;KAC/B;CACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import _ from 'lodash';
|
|
2
|
+
import {DYNAMIC_VARIABLES} from './constants';
|
|
3
|
+
import {FindingDto} from '../dto';
|
|
2
4
|
const JSON_PATH_PATTERN = /(\$\.(?:(?:[a-zA-Z0-9_]+)(?:\.[a-zA-Z0-9_]+)*)?)/g;
|
|
5
|
+
const DYNAMIC_PROPERTY_PATTERN = /\{\{([^}]+)\}\}/g;
|
|
3
6
|
|
|
7
|
+
// @deprecated : consider using fillDynamicPropertyTemplate
|
|
4
8
|
export const fillJsonPathTemplate = (raw: string, meta: unknown) => {
|
|
5
9
|
const jsonPathMatches = raw.match(JSON_PATH_PATTERN);
|
|
6
10
|
let result = raw;
|
|
@@ -16,3 +20,68 @@ export const fillJsonPathTemplate = (raw: string, meta: unknown) => {
|
|
|
16
20
|
}
|
|
17
21
|
return result;
|
|
18
22
|
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @param rawTemplateString Template string with placeholders in the format of {{path.to.value}}
|
|
26
|
+
* @param meta object containing the values to replace the placeholders
|
|
27
|
+
* @returns string with placeholders replaced with values from the meta object
|
|
28
|
+
* @note Ensure that meta object does not contain any information that should not be exposed to end users
|
|
29
|
+
*/
|
|
30
|
+
export const fillDynamicPropertyTemplate = (rawTemplateString: string, meta: unknown) => {
|
|
31
|
+
let result = rawTemplateString;
|
|
32
|
+
const matches = rawTemplateString.match(DYNAMIC_PROPERTY_PATTERN);
|
|
33
|
+
if (matches) {
|
|
34
|
+
matches.forEach(placeholder => {
|
|
35
|
+
const path = placeholder.slice(2, -2).trim();
|
|
36
|
+
const value = _.get(meta, path, undefined);
|
|
37
|
+
if (_.isString(value) || _.isNumber(value) || _.isBoolean(value)) {
|
|
38
|
+
// primitive value type is replaced as is
|
|
39
|
+
result = result.replace(placeholder, value);
|
|
40
|
+
} else if (_.isObject(value) || _.isArray(value)) {
|
|
41
|
+
// object and array values are stringified
|
|
42
|
+
result = result.replace(placeholder, JSON.stringify(value, null, 2));
|
|
43
|
+
} else {
|
|
44
|
+
// unknown value type is replaced with a placeholder
|
|
45
|
+
result = result.replace(placeholder, 'UNKNOWN_TEMPLATE_VALUE');
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const populateDynamicVariablesEntityData = (
|
|
53
|
+
entityProperties: Record<string, string>,
|
|
54
|
+
baseObject: Record<string, unknown> | undefined,
|
|
55
|
+
fallbackObject: Record<string, unknown> | undefined = undefined
|
|
56
|
+
): Record<string, unknown> => {
|
|
57
|
+
const entityData: Record<string, unknown> = {};
|
|
58
|
+
for (const key in entityProperties) {
|
|
59
|
+
const findingKeyPath = entityProperties[key];
|
|
60
|
+
entityData[key] = _.get(baseObject, findingKeyPath) || (fallbackObject ? _.get(fallbackObject, findingKeyPath) : undefined);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return entityData;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const buildDynamicVariablesContext = (finding: FindingDto): Map<string, unknown> => {
|
|
67
|
+
const entityMap: Map<string, unknown> = new Map();
|
|
68
|
+
|
|
69
|
+
for (const entityName in DYNAMIC_VARIABLES.ALLOWED_ENTITIES) {
|
|
70
|
+
const entityKey = DYNAMIC_VARIABLES.ALLOWED_ENTITIES[entityName as keyof typeof DYNAMIC_VARIABLES.ALLOWED_ENTITIES];
|
|
71
|
+
const entityProperties = DYNAMIC_VARIABLES.ALLOWED_ENTITY_KEYS[entityKey as keyof typeof DYNAMIC_VARIABLES.ALLOWED_ENTITY_KEYS];
|
|
72
|
+
|
|
73
|
+
let entityData: Record<string, unknown> = {};
|
|
74
|
+
|
|
75
|
+
if (entityName === 'finding') {
|
|
76
|
+
entityData = populateDynamicVariablesEntityData(entityProperties, finding);
|
|
77
|
+
} else if (entityName === 'user' && finding.meta?._user) {
|
|
78
|
+
entityData = populateDynamicVariablesEntityData(entityProperties, finding);
|
|
79
|
+
} else if (entityName === 'asset' && finding.asset) {
|
|
80
|
+
entityData = populateDynamicVariablesEntityData(entityProperties, finding.asset, finding);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
entityMap.set(entityName, entityData);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return entityMap;
|
|
87
|
+
};
|
|
@@ -63,3 +63,39 @@ export const REPORTS = {
|
|
|
63
63
|
// trending reports
|
|
64
64
|
HEALTH_SCORE_TREND: 'monthly-health-trend',
|
|
65
65
|
};
|
|
66
|
+
|
|
67
|
+
export class DYNAMIC_VARIABLES {
|
|
68
|
+
static readonly ALLOWED_ENTITIES = {
|
|
69
|
+
// Public Keys : Private Keys
|
|
70
|
+
finding: 'finding',
|
|
71
|
+
user: 'user',
|
|
72
|
+
asset: 'asset',
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
static readonly ALLOWED_ENTITY_KEYS = {
|
|
76
|
+
finding: {
|
|
77
|
+
// Public Keys : Private Keys
|
|
78
|
+
displayValue: 'displayValue',
|
|
79
|
+
description: 'description',
|
|
80
|
+
discoveredAt: 'discoveredAt',
|
|
81
|
+
category: 'category',
|
|
82
|
+
severity: 'severity',
|
|
83
|
+
kind: 'kind',
|
|
84
|
+
},
|
|
85
|
+
user: {
|
|
86
|
+
// Public Keys : Private Keys
|
|
87
|
+
firstName: 'meta._user.firstName',
|
|
88
|
+
lastName: 'meta._user.lastName',
|
|
89
|
+
organization: 'meta._user.organization',
|
|
90
|
+
department: 'meta._user.department',
|
|
91
|
+
title: 'meta._user.title',
|
|
92
|
+
email: 'meta._user.primaryEmail',
|
|
93
|
+
},
|
|
94
|
+
asset: {
|
|
95
|
+
// Public Keys : Private Keys
|
|
96
|
+
displayValue: 'displayValue',
|
|
97
|
+
serialNumber: 'meta._asset.sn',
|
|
98
|
+
macAddress: 'meta._asset.macs',
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|