@mitre/inspec-objects 0.0.21 → 0.0.24
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/lib/utilities/update.d.ts +1 -1
- package/lib/utilities/update.js +23 -21
- package/package-lock.json +2 -2
- package/package.json +1 -1
package/lib/utilities/update.js
CHANGED
|
@@ -9,13 +9,15 @@ const profile_1 = tslib_1.__importDefault(require("../objects/profile"));
|
|
|
9
9
|
const xccdf_1 = require("../parsers/xccdf");
|
|
10
10
|
const diff_1 = require("./diff");
|
|
11
11
|
const diffMarkdown_1 = require("./diffMarkdown");
|
|
12
|
-
const knownInSpecKeywords = ['title', 'desc', 'impact', 'ref', 'tag', "
|
|
12
|
+
const knownInSpecKeywords = ['title', 'desc', 'impact', 'ref', 'tag', '"'];
|
|
13
13
|
function projectValuesOntoExistingObj(dst, src, currentPath = '') {
|
|
14
14
|
for (const updatedValue in src) {
|
|
15
15
|
const existingValue = lodash_1.default.get(dst, updatedValue);
|
|
16
16
|
// We have a new value for something that already exists in dst
|
|
17
17
|
if (existingValue !== undefined) {
|
|
18
|
-
if (typeof existingValue === 'object' &&
|
|
18
|
+
if (typeof existingValue === 'object' &&
|
|
19
|
+
existingValue !== null &&
|
|
20
|
+
!Array.isArray(existingValue)) {
|
|
19
21
|
dst[updatedValue] = projectValuesOntoExistingObj(existingValue, src[updatedValue], currentPath + updatedValue + '.');
|
|
20
22
|
}
|
|
21
23
|
else if (typeof src[updatedValue] === 'string') {
|
|
@@ -25,7 +27,9 @@ function projectValuesOntoExistingObj(dst, src, currentPath = '') {
|
|
|
25
27
|
lodash_1.default.set(dst, updatedValue, src[updatedValue]);
|
|
26
28
|
}
|
|
27
29
|
else if (Array.isArray(src[updatedValue])) {
|
|
28
|
-
const uniqueArrayValues = [
|
|
30
|
+
const uniqueArrayValues = [
|
|
31
|
+
...new Set(lodash_1.default.get(dst, updatedValue, []).concat(src[updatedValue]))
|
|
32
|
+
];
|
|
29
33
|
lodash_1.default.set(dst, updatedValue, uniqueArrayValues);
|
|
30
34
|
}
|
|
31
35
|
}
|
|
@@ -39,15 +43,25 @@ function getExistingDescribeFromControl(control) {
|
|
|
39
43
|
let existingDescribeBlock = '';
|
|
40
44
|
let currentQuoteEscape = '';
|
|
41
45
|
let inQuoteBlock = false;
|
|
42
|
-
let
|
|
43
|
-
control.code.split('\n')
|
|
46
|
+
let inMetadataValueOverride = false;
|
|
47
|
+
const splitLines = control.code.split('\n');
|
|
48
|
+
splitLines.forEach((line, lineIndex) => {
|
|
49
|
+
// Special case - Multi-line arrayed metadata value
|
|
50
|
+
if (typeof splitLines[lineIndex - 1] === 'string') {
|
|
51
|
+
if (knownInSpecKeywords.indexOf(splitLines[lineIndex - 1].trim().split(' ')[0]) !== -1 &&
|
|
52
|
+
splitLines[lineIndex - 1].trim().split(' ')[1].startsWith('[')) {
|
|
53
|
+
inMetadataValueOverride = true;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
44
56
|
const wordSplit = line.trim().split(' ');
|
|
45
|
-
if (!inQuoteBlock) {
|
|
57
|
+
if (!inQuoteBlock && !inMetadataValueOverride) {
|
|
46
58
|
// Get the number of spaces at the beggining of the current line
|
|
47
59
|
const spaces = line.substring(0, line.indexOf(wordSplit[0])).length;
|
|
48
60
|
if (spaces >= 2) {
|
|
49
61
|
const firstWord = wordSplit[0];
|
|
50
|
-
if (knownInSpecKeywords.indexOf(firstWord.toLowerCase()) === -1 ||
|
|
62
|
+
if (knownInSpecKeywords.indexOf(firstWord.toLowerCase()) === -1 ||
|
|
63
|
+
(knownInSpecKeywords.indexOf(firstWord.toLowerCase()) !== -1 &&
|
|
64
|
+
spaces > 2)) {
|
|
51
65
|
existingDescribeBlock += line + '\n';
|
|
52
66
|
}
|
|
53
67
|
}
|
|
@@ -73,18 +87,6 @@ function getExistingDescribeFromControl(control) {
|
|
|
73
87
|
}
|
|
74
88
|
});
|
|
75
89
|
});
|
|
76
|
-
// Special casing for arrays split across multiple lines
|
|
77
|
-
if (line.endsWith(']')) {
|
|
78
|
-
if (line.trim().startsWith('"') || line.trim().startsWith("'")) {
|
|
79
|
-
inQuoteBlock = true;
|
|
80
|
-
haveUsedSpecialCasingForArrays = false;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
if (haveUsedSpecialCasingForArrays) {
|
|
85
|
-
inQuoteBlock = false;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
90
|
});
|
|
89
91
|
return existingDescribeBlock;
|
|
90
92
|
}
|
|
@@ -128,7 +130,7 @@ function updateProfile(from, using, logger) {
|
|
|
128
130
|
// Find the diff
|
|
129
131
|
const diff = (0, diff_1.diffProfile)(from, using, logger);
|
|
130
132
|
// Add the new controls
|
|
131
|
-
diff.simplified.addedControlIDs.forEach(id => {
|
|
133
|
+
diff.simplified.addedControlIDs.forEach((id) => {
|
|
132
134
|
const addedControl = diff.simplified.addedControls[id];
|
|
133
135
|
if (addedControl) {
|
|
134
136
|
logger.debug(`New Control: ${addedControl.id} - ${addedControl.title}`);
|
|
@@ -153,7 +155,7 @@ function updateProfile(from, using, logger) {
|
|
|
153
155
|
}
|
|
154
156
|
return {
|
|
155
157
|
profile: to,
|
|
156
|
-
diff
|
|
158
|
+
diff
|
|
157
159
|
};
|
|
158
160
|
}
|
|
159
161
|
exports.updateProfile = updateProfile;
|
package/package-lock.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mitre/inspec-objects",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
4
4
|
"lockfileVersion": 2,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@mitre/inspec-objects",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.24",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@types/flat": "^5.0.2",
|