@mitre/inspec-objects 0.0.24 → 0.0.25

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,4 +1,4 @@
1
- import winston from 'winston';
1
+ import winston from "winston";
2
2
  import Control from '../objects/control';
3
3
  import Profile from '../objects/profile';
4
4
  import { ProfileDiff } from '../types/diff';
@@ -9,15 +9,13 @@ 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' &&
19
- existingValue !== null &&
20
- !Array.isArray(existingValue)) {
18
+ if (typeof existingValue === 'object' && existingValue !== null && !Array.isArray(existingValue)) {
21
19
  dst[updatedValue] = projectValuesOntoExistingObj(existingValue, src[updatedValue], currentPath + updatedValue + '.');
22
20
  }
23
21
  else if (typeof src[updatedValue] === 'string') {
@@ -27,9 +25,7 @@ function projectValuesOntoExistingObj(dst, src, currentPath = '') {
27
25
  lodash_1.default.set(dst, updatedValue, src[updatedValue]);
28
26
  }
29
27
  else if (Array.isArray(src[updatedValue])) {
30
- const uniqueArrayValues = [
31
- ...new Set(lodash_1.default.get(dst, updatedValue, []).concat(src[updatedValue]))
32
- ];
28
+ const uniqueArrayValues = [...new Set(lodash_1.default.get(dst, updatedValue, []).concat(src[updatedValue]))];
33
29
  lodash_1.default.set(dst, updatedValue, uniqueArrayValues);
34
30
  }
35
31
  }
@@ -44,24 +40,23 @@ function getExistingDescribeFromControl(control) {
44
40
  let currentQuoteEscape = '';
45
41
  let inQuoteBlock = false;
46
42
  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
- }
43
+ let indentedMetadataOverride = false;
44
+ let mostSpacesSeen = 0;
45
+ control.code.split('\n').forEach((line) => {
56
46
  const wordSplit = line.trim().split(' ');
57
- if (!inQuoteBlock && !inMetadataValueOverride) {
47
+ const spaces = line.substring(0, line.indexOf(wordSplit[0])).length;
48
+ if (spaces - mostSpacesSeen > 10) {
49
+ indentedMetadataOverride = true;
50
+ }
51
+ else {
52
+ mostSpacesSeen = spaces;
53
+ indentedMetadataOverride = false;
54
+ }
55
+ if (!inQuoteBlock && !inMetadataValueOverride && !indentedMetadataOverride) {
58
56
  // Get the number of spaces at the beggining of the current line
59
- const spaces = line.substring(0, line.indexOf(wordSplit[0])).length;
60
57
  if (spaces >= 2) {
61
58
  const firstWord = wordSplit[0];
62
- if (knownInSpecKeywords.indexOf(firstWord.toLowerCase()) === -1 ||
63
- (knownInSpecKeywords.indexOf(firstWord.toLowerCase()) !== -1 &&
64
- spaces > 2)) {
59
+ if (knownInSpecKeywords.indexOf(firstWord.toLowerCase()) === -1 || (knownInSpecKeywords.indexOf(firstWord.toLowerCase()) !== -1 && spaces > 2)) {
65
60
  existingDescribeBlock += line + '\n';
66
61
  }
67
62
  }
@@ -130,7 +125,7 @@ function updateProfile(from, using, logger) {
130
125
  // Find the diff
131
126
  const diff = (0, diff_1.diffProfile)(from, using, logger);
132
127
  // Add the new controls
133
- diff.simplified.addedControlIDs.forEach((id) => {
128
+ diff.simplified.addedControlIDs.forEach(id => {
134
129
  const addedControl = diff.simplified.addedControls[id];
135
130
  if (addedControl) {
136
131
  logger.debug(`New Control: ${addedControl.id} - ${addedControl.title}`);
@@ -155,7 +150,7 @@ function updateProfile(from, using, logger) {
155
150
  }
156
151
  return {
157
152
  profile: to,
158
- diff
153
+ diff,
159
154
  };
160
155
  }
161
156
  exports.updateProfile = updateProfile;
package/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@mitre/inspec-objects",
3
- "version": "0.0.24",
3
+ "version": "0.0.25",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@mitre/inspec-objects",
9
- "version": "0.0.24",
9
+ "version": "0.0.25",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "@types/flat": "^5.0.2",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mitre/inspec-objects",
3
- "version": "0.0.24",
3
+ "version": "0.0.25",
4
4
  "description": "Typescript objects for normalizing between InSpec profiles and XCCDF benchmarks",
5
5
  "main": "lib/index.js",
6
6
  "publishConfig": {