@mitre/inspec-objects 0.0.4 → 0.0.5

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.
@@ -28,13 +28,13 @@ class Control {
28
28
  let result = "# encoding: UTF-8\n\n";
29
29
  result += `control "${this.id}" do\n`;
30
30
  if (this.title) {
31
- result += ` title "${(0, global_1.wrapAndEscapeQuotes)(this.title, lineLength)}"\n`;
31
+ result += ` title "${(0, global_1.wrapAndEscapeQuotes)((0, global_1.removeNewlinePlaceholders)(this.title), lineLength)}"\n`;
32
32
  }
33
33
  else {
34
34
  console.error(`${this.id} does not have a title`);
35
35
  }
36
36
  if (this.desc) {
37
- result += ` desc "${(0, global_1.wrapAndEscapeQuotes)(this.desc, lineLength)}"\n`;
37
+ result += ` desc "${(0, global_1.wrapAndEscapeQuotes)((0, global_1.removeNewlinePlaceholders)(this.desc), lineLength)}"\n`;
38
38
  }
39
39
  else {
40
40
  console.error(`${this.id} does not have a desc`);
@@ -42,7 +42,7 @@ class Control {
42
42
  if (this.descs) {
43
43
  Object.entries(this.descs).forEach(([key, desc]) => {
44
44
  if (desc) {
45
- result += ` desc "${key}", "${(0, global_1.wrapAndEscapeQuotes)(desc, lineLength)}"\n`;
45
+ result += ` desc "${key}", "${(0, global_1.wrapAndEscapeQuotes)((0, global_1.removeNewlinePlaceholders)(desc), lineLength)}"\n`;
46
46
  }
47
47
  else {
48
48
  console.error(`${this.id} does not have a desc for the value ${key}`);
@@ -58,10 +58,10 @@ class Control {
58
58
  if (this.refs) {
59
59
  this.refs.forEach((ref) => {
60
60
  if (typeof ref === 'string') {
61
- result += ` ref '${(0, global_1.escapeQuotes)(ref)}'\n`;
61
+ result += ` ref '${(0, global_1.escapeQuotes)((0, global_1.removeNewlinePlaceholders)(ref))}'\n`;
62
62
  }
63
63
  else {
64
- result += ` ref '${(0, global_1.escapeQuotes)(ref.ref || '')}', url: '${(0, global_1.escapeQuotes)(ref.url || '')}'`;
64
+ result += ` ref '${(0, global_1.escapeQuotes)((0, global_1.removeNewlinePlaceholders)(ref.ref || ''))}', url: '${(0, global_1.escapeQuotes)((0, global_1.removeNewlinePlaceholders)(ref.url || ''))}'`;
65
65
  }
66
66
  });
67
67
  }
@@ -84,7 +84,7 @@ class Control {
84
84
  }
85
85
  }
86
86
  else if (typeof value === "string") {
87
- result += ` tag ${tag}: "${(0, global_1.wrapAndEscapeQuotes)(value, lineLength)}"\n`;
87
+ result += ` tag ${tag}: "${(0, global_1.wrapAndEscapeQuotes)((0, global_1.removeNewlinePlaceholders)(value), lineLength)}"\n`;
88
88
  }
89
89
  }
90
90
  });
@@ -5,4 +5,4 @@ export declare type GroupContextualizedRule = BenchmarkRule & {
5
5
  group: Omit<BenchmarkGroup, 'Rule' | 'Group'>;
6
6
  };
7
7
  export declare function extractAllRules(groups: BenchmarkGroup[]): GroupContextualizedRule[];
8
- export declare function processXCCDF(xml: string, removeNewlines?: boolean, ovalDefinitions?: Record<string, OvalDefinitionValue>): Profile;
8
+ export declare function processXCCDF(xml: string, removeNewlines: boolean | undefined, useRuleId: 'group' | 'rule' | 'version', ovalDefinitions?: Record<string, OvalDefinitionValue>): Profile;
@@ -25,7 +25,7 @@ function extractAllRules(groups) {
25
25
  return rules;
26
26
  }
27
27
  exports.extractAllRules = extractAllRules;
28
- function processXCCDF(xml, removeNewlines = false, ovalDefinitions) {
28
+ function processXCCDF(xml, removeNewlines = false, useRuleId, ovalDefinitions) {
29
29
  const parsedXML = (0, xccdf_1.convertEncodedXmlIntoJson)(xml);
30
30
  const rules = extractAllRules(parsedXML.Benchmark[0].Group);
31
31
  const profile = new profile_1.default({
@@ -44,6 +44,19 @@ function processXCCDF(xml, removeNewlines = false, ovalDefinitions) {
44
44
  }
45
45
  const control = new control_1.default();
46
46
  control.id = rule['@_id'];
47
+ switch (useRuleId) {
48
+ case 'group':
49
+ control.id = rule.group['@_id'];
50
+ break;
51
+ case 'rule':
52
+ control.id = rule['@_id'];
53
+ break;
54
+ case 'version':
55
+ control.id = rule.version;
56
+ break;
57
+ default:
58
+ throw new Error('useRuleId must be one of "group", "rule", or "version"');
59
+ }
47
60
  if (removeNewlines) {
48
61
  const title = (0, xccdf_1.removeXMLSpecialCharacters)(rule['@_severity'] ? rule.title : `[[[MISSING SEVERITY FROM STIG]]] ${rule.title}`);
49
62
  control.title = title.replace(/\n/g, '{{{{newlineHERE}}}}');