@mitre/inspec-objects 0.0.30 → 0.0.32
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/.eslintignore +2 -0
- package/.eslintrc +41 -0
- package/.github/workflows/e2e-test.yml +6 -19
- package/.github/workflows/linter.yml +27 -0
- package/.github/workflows/push-to-gpr.yml +36 -0
- package/.github/workflows/push-to-npm.yml +34 -0
- package/README.md +48 -0
- package/images/Delta_Process.jpg +0 -0
- package/images/ts-inspec-objects.jpg +0 -0
- package/lib/index.d.ts +7 -7
- package/lib/objects/control.d.ts +2 -2
- package/lib/objects/control.js +40 -21
- package/lib/objects/profile.d.ts +6 -6
- package/lib/objects/profile.js +1 -1
- package/lib/parsers/json.d.ts +3 -3
- package/lib/parsers/json.js +18 -14
- package/lib/parsers/oval.js +20 -19
- package/lib/parsers/xccdf.d.ts +1 -1
- package/lib/parsers/xccdf.js +9 -5
- package/lib/utilities/diff.d.ts +6 -6
- package/lib/utilities/diff.js +52 -30
- package/lib/utilities/diffMarkdown.d.ts +3 -3
- package/lib/utilities/diffMarkdown.js +17 -21
- package/lib/utilities/global.d.ts +2 -4
- package/lib/utilities/global.js +29 -13
- package/lib/utilities/logging.d.ts +1 -1
- package/lib/utilities/update.d.ts +4 -3
- package/lib/utilities/update.js +57 -54
- package/lib/utilities/xccdf.js +0 -1
- package/package.json +7 -4
- package/tsconfig.json +20 -21
- package/lib/utilities/CciNistMappingData.d.ts +0 -5100
- package/lib/utilities/CciNistMappingData.js +0 -5103
- package/package-lock.json +0 -8881
package/.eslintignore
ADDED
package/.eslintrc
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"rules": {
|
|
3
|
+
"@typescript-eslint/no-unused-vars": "warn",
|
|
4
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
5
|
+
"unicorn/filename-case": "off",
|
|
6
|
+
"unicorn/prefer-node-protocol": "off",
|
|
7
|
+
"unicorn/numeric-separators-style": "off",
|
|
8
|
+
"unicorn/no-hex-escape": "off",
|
|
9
|
+
"unicorn/better-regex": "off",
|
|
10
|
+
"unicorn/no-zero-fractions": "off",
|
|
11
|
+
"unicorn/no-array-for-each": "off",
|
|
12
|
+
"unicorn/explicit-length-check": "off",
|
|
13
|
+
"unicorn/no-process-exit": "off",
|
|
14
|
+
"no-process-exit": "off",
|
|
15
|
+
"no-await-in-loop": "off",
|
|
16
|
+
"no-control-regex": "off",
|
|
17
|
+
"max-nested-callbacks": "off",
|
|
18
|
+
"unicorn/prefer-json-parse-buffer": "off",
|
|
19
|
+
"camelcase": "off", // Camel case fields are used in CKL
|
|
20
|
+
"no-console": "off",
|
|
21
|
+
"node/no-missing-import": "off",
|
|
22
|
+
"complexity": "off",
|
|
23
|
+
"no-constant-condition": "off",
|
|
24
|
+
"keyword-spacing": 2,
|
|
25
|
+
"space-before-blocks":"warn",
|
|
26
|
+
"space-in-parens": 2,
|
|
27
|
+
"indent": ["error", 2, { "SwitchCase": 1 }],
|
|
28
|
+
"quotes": [2, "single", { "avoidEscape": true }],
|
|
29
|
+
"object-curly-spacing": [2, "never"]
|
|
30
|
+
},
|
|
31
|
+
"root": true,
|
|
32
|
+
"parser": "@typescript-eslint/parser",
|
|
33
|
+
"plugins": [
|
|
34
|
+
"@typescript-eslint"
|
|
35
|
+
],
|
|
36
|
+
"extends": [
|
|
37
|
+
"eslint:recommended",
|
|
38
|
+
"plugin:@typescript-eslint/eslint-recommended",
|
|
39
|
+
"plugin:@typescript-eslint/recommended"
|
|
40
|
+
]
|
|
41
|
+
}
|
|
@@ -4,35 +4,22 @@ on:
|
|
|
4
4
|
push:
|
|
5
5
|
branches: [ main ]
|
|
6
6
|
pull_request:
|
|
7
|
-
branches: [ main ]
|
|
8
7
|
|
|
9
8
|
jobs:
|
|
10
9
|
build:
|
|
11
10
|
runs-on: ubuntu-20.04
|
|
12
11
|
|
|
13
12
|
steps:
|
|
14
|
-
- uses: actions/checkout@
|
|
15
|
-
|
|
16
|
-
- name: Cache node modules
|
|
17
|
-
uses: actions/cache@v2
|
|
18
|
-
env:
|
|
19
|
-
cache-name: cache-node-modules
|
|
20
|
-
with:
|
|
21
|
-
# npm cache files are stored in `~/.npm` on Linux/macOS
|
|
22
|
-
path: ~/.npm
|
|
23
|
-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
|
|
24
|
-
restore-keys: |
|
|
25
|
-
${{ runner.os }}-build-${{ env.cache-name }}-
|
|
26
|
-
${{ runner.os }}-build-
|
|
27
|
-
${{ runner.os }}-
|
|
13
|
+
- uses: actions/checkout@v3
|
|
28
14
|
|
|
29
15
|
- name: Setup Node.js
|
|
30
|
-
uses: actions/setup-node@
|
|
16
|
+
uses: actions/setup-node@v3
|
|
31
17
|
with:
|
|
32
|
-
node-version:
|
|
18
|
+
node-version: 18
|
|
19
|
+
cache: 'npm'
|
|
33
20
|
|
|
34
21
|
- name: Install dependencies
|
|
35
|
-
run: npm
|
|
22
|
+
run: npm ci
|
|
36
23
|
|
|
37
24
|
- name: Run e2e tests
|
|
38
|
-
run:
|
|
25
|
+
run: npm test
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
name: Lint TS-InSpec-Objects
|
|
3
|
+
|
|
4
|
+
on:
|
|
5
|
+
push:
|
|
6
|
+
branches: [ main ]
|
|
7
|
+
pull_request:
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
runs-on: ubuntu-20.04
|
|
12
|
+
|
|
13
|
+
steps:
|
|
14
|
+
- name: Checkout code
|
|
15
|
+
uses: actions/checkout@v3
|
|
16
|
+
|
|
17
|
+
- name: Setup Node.js
|
|
18
|
+
uses: actions/setup-node@v3
|
|
19
|
+
with:
|
|
20
|
+
node-version: 18
|
|
21
|
+
cache: 'npm'
|
|
22
|
+
|
|
23
|
+
- name: Install project dependencies
|
|
24
|
+
run: npm ci
|
|
25
|
+
|
|
26
|
+
- name: Run lint
|
|
27
|
+
run: npm run lint:ci
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: Build and Release NPM to GPR (GitHub Package Registry)
|
|
2
|
+
on:
|
|
3
|
+
release:
|
|
4
|
+
types: [published]
|
|
5
|
+
workflow_dispatch:
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
build-deploy:
|
|
9
|
+
runs-on: ubuntu-20.04
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v3
|
|
12
|
+
|
|
13
|
+
- name: Setup node
|
|
14
|
+
uses: actions/setup-node@v3
|
|
15
|
+
with:
|
|
16
|
+
node-version: 18
|
|
17
|
+
registry-url: https://npm.pkg.github.com/
|
|
18
|
+
scope: '@mitre'
|
|
19
|
+
|
|
20
|
+
- name: Build the NPM Package
|
|
21
|
+
run: |
|
|
22
|
+
npm install
|
|
23
|
+
npm run build
|
|
24
|
+
- name: Pack all items that are published
|
|
25
|
+
run: npm pack
|
|
26
|
+
# Setup .npmrc file to publish to GitHub Package Registry
|
|
27
|
+
- uses: actions/setup-node@v1
|
|
28
|
+
with:
|
|
29
|
+
registry-url: 'https://npm.pkg.github.com'
|
|
30
|
+
scope: '@mitre'
|
|
31
|
+
|
|
32
|
+
# Publish inspec-objects to GitHub Package Registry
|
|
33
|
+
- name: Publish inspec-objects to GPR
|
|
34
|
+
run: npm publish mitre-inspec-objects-*.tgz
|
|
35
|
+
env:
|
|
36
|
+
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
name: Push @mitre/inspec-objects to NPM
|
|
2
|
+
on:
|
|
3
|
+
release:
|
|
4
|
+
types: [published]
|
|
5
|
+
workflow_dispatch:
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
build-deploy:
|
|
9
|
+
runs-on: ubuntu-20.04
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v3
|
|
12
|
+
|
|
13
|
+
- name: setup node
|
|
14
|
+
uses: actions/setup-node@v3
|
|
15
|
+
with:
|
|
16
|
+
node-version: 18
|
|
17
|
+
registry-url: 'https://registry.npmjs.org'
|
|
18
|
+
|
|
19
|
+
- name: Install project dependencies
|
|
20
|
+
run: npm ci
|
|
21
|
+
|
|
22
|
+
- name: Remove testing resources
|
|
23
|
+
run: rm -rf test
|
|
24
|
+
|
|
25
|
+
- name: Build
|
|
26
|
+
run: npm run build
|
|
27
|
+
|
|
28
|
+
- name: Pack all items that are published as packages
|
|
29
|
+
run: npm pack
|
|
30
|
+
|
|
31
|
+
- name: Publish inspec-objects to NPM
|
|
32
|
+
run: npm publish --access public mitre-inspec-objects-*.tgz
|
|
33
|
+
env:
|
|
34
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/README.md
CHANGED
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
# ts-inspec-objects
|
|
2
2
|
Typescript objects for InSpec profiles
|
|
3
3
|
|
|
4
|
+
This repository contains the source code that facilitates the writing of InSpec profiles (for use in things like stub generation and delta comparisons) more consistent with `Chef Cookstyle` formatting for ease of use when comparing with new changes from delta and when generating InSpec stubs that match a standard format.
|
|
5
|
+
|
|
6
|
+
For more information about Chef Cookstyle see:
|
|
7
|
+
- [chef/cookstyle on GitHub](https://github.com/chef/cookstyle)
|
|
8
|
+
- [Chef Cookstyle on Chef documents page](https://docs.chef.io/workstation/cookstyle/)
|
|
9
|
+
|
|
10
|
+
## How to Use
|
|
11
|
+
The process code maintained in this repository generates a `npm` executable that is published to the `npm registry` as [mitre-inspec-objects](https://www.npmjs.com/package/@mitre/inspec-objects).
|
|
12
|
+
|
|
13
|
+
To use the `mitre-inspec-objects` npm package, simply add the package as a dependency to your project application using the npm install command:
|
|
14
|
+
```
|
|
15
|
+
npm install mitre-inspec-objects
|
|
16
|
+
```
|
|
17
|
+
The package is a CommonJS-based npm written in TypeScript
|
|
18
|
+
|
|
19
|
+
## Parsing Process
|
|
20
|
+
|
|
21
|
+
When using this library to parse `InSpec profiles` or `xccdf files` for the purposes of generating InSpec profiles, the general workflow is as follows:
|
|
22
|
+
```
|
|
23
|
+
- The input is processed, read into a typescript object
|
|
24
|
+
- Operated on with any required action / logic
|
|
25
|
+
- Then written into an InSpec profile as output.
|
|
26
|
+
```
|
|
27
|
+
This means that we can not simply write out in the same format we got in. Instead, we have to make choices about formatting for how to write out content.
|
|
28
|
+
|
|
29
|
+
Here are some formatting choices that are being made.
|
|
30
|
+
|
|
31
|
+
1. String quotation
|
|
32
|
+
|
|
33
|
+
| The string contains | Use |
|
|
34
|
+
|-------- |-------------------- |
|
|
35
|
+
| single (') and double (") quotes| percent string syntax - %q() |
|
|
36
|
+
| single (') quotes | double (") quotes |
|
|
37
|
+
| other | single (') quotes |
|
|
38
|
+
|
|
39
|
+
2. Tag keywords are not quoted (ex: tag severity: 'medium')
|
|
40
|
+
3. Each control file ends with a newline
|
|
41
|
+
|
|
42
|
+
### Workflow graphical representation
|
|
43
|
+
<div align="center">
|
|
44
|
+
<img src="images/ts-inspec-objects.jpg" alt="Typescript Objects Generation Process" title="Typescript Objects Generation Process">
|
|
45
|
+
</div>
|
|
46
|
+
|
|
47
|
+
### Delta and Stub Process
|
|
48
|
+
<div align="center">
|
|
49
|
+
<img src="images/Delta_Process.jpg" alt="Delta and Stub Generation Process" title="Delta and Stub Generation Process">
|
|
50
|
+
</div>
|
|
51
|
+
|
|
4
52
|
### NOTICE
|
|
5
53
|
|
|
6
54
|
© 2018-2022 The MITRE Corporation.
|
|
Binary file
|
|
Binary file
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
1
|
+
export * from './objects/control';
|
|
2
|
+
export * from './objects/profile';
|
|
3
|
+
export * from './parsers/json';
|
|
4
|
+
export * from './parsers/oval';
|
|
5
|
+
export * from './parsers/xccdf';
|
|
6
|
+
export * from './utilities/diff';
|
|
7
|
+
export * from './utilities/update';
|
package/lib/objects/control.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExecJSON } from
|
|
1
|
+
import { ExecJSON } from 'inspecjs';
|
|
2
2
|
export declare function objectifyDescriptions(descs: ExecJSON.ControlDescription[] | {
|
|
3
3
|
[key: string]: string | undefined;
|
|
4
4
|
} | null | undefined): {
|
|
@@ -49,5 +49,5 @@ export default class Control {
|
|
|
49
49
|
};
|
|
50
50
|
constructor(data?: Partial<Control>);
|
|
51
51
|
toUnformattedObject(): Control;
|
|
52
|
-
toRuby(
|
|
52
|
+
toRuby(): string;
|
|
53
53
|
}
|
package/lib/objects/control.js
CHANGED
|
@@ -36,25 +36,36 @@ class Control {
|
|
|
36
36
|
});
|
|
37
37
|
return new Control((0, flat_1.unflatten)(flattened));
|
|
38
38
|
}
|
|
39
|
-
toRuby(
|
|
40
|
-
let result =
|
|
41
|
-
result += `control
|
|
39
|
+
toRuby() {
|
|
40
|
+
let result = '';
|
|
41
|
+
result += `control '${this.id}' do\n`;
|
|
42
42
|
if (this.title) {
|
|
43
|
-
result += ` title
|
|
43
|
+
result += ` title ${(0, global_1.escapeQuotes)(this.title)}\n`;
|
|
44
44
|
}
|
|
45
45
|
else {
|
|
46
46
|
console.error(`${this.id} does not have a title`);
|
|
47
47
|
}
|
|
48
|
+
// This is the known 'default' description - on previous version this content was repeated on descriptions processed by "descs"
|
|
48
49
|
if (this.desc) {
|
|
49
|
-
result += ` desc
|
|
50
|
+
result += ` desc ${(0, global_1.escapeQuotes)(this.desc)}\n`;
|
|
50
51
|
}
|
|
51
52
|
else {
|
|
52
53
|
console.error(`${this.id} does not have a desc`);
|
|
53
54
|
}
|
|
54
55
|
if (this.descs) {
|
|
55
|
-
Object.entries(this.descs).forEach(([key,
|
|
56
|
-
if (
|
|
57
|
-
|
|
56
|
+
Object.entries(this.descs).forEach(([key, subDesc]) => {
|
|
57
|
+
if (subDesc) {
|
|
58
|
+
if (key.match('default') && this.desc) {
|
|
59
|
+
if (subDesc != this.desc) {
|
|
60
|
+
// The "default" keyword may have the same content as the desc content for backward compatibility with different historical InSpec versions.
|
|
61
|
+
// In that case, we can ignore writing the "default" subdescription field.
|
|
62
|
+
// If they are different, however, someone may be trying to use the keyword "default" for a unique subdescription, which should not be done.
|
|
63
|
+
console.error(`${this.id} has a subdescription called "default" with contents that do not match the main description. "Default" should not be used as a keyword for unique sub-descriptions.`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
result += ` desc '${key}', ${(0, global_1.escapeQuotes)(subDesc)}\n`;
|
|
68
|
+
}
|
|
58
69
|
}
|
|
59
70
|
else {
|
|
60
71
|
console.error(`${this.id} does not have a desc for the value ${key}`);
|
|
@@ -69,34 +80,39 @@ class Control {
|
|
|
69
80
|
}
|
|
70
81
|
if (this.refs) {
|
|
71
82
|
this.refs.forEach((ref) => {
|
|
83
|
+
var _a;
|
|
72
84
|
if (typeof ref === 'string') {
|
|
73
|
-
result += ` ref
|
|
85
|
+
result += ` ref ${(0, global_1.escapeQuotes)(ref)}\n`;
|
|
74
86
|
}
|
|
75
87
|
else {
|
|
76
|
-
result += ` ref
|
|
88
|
+
result += ` ref ${(0, global_1.escapeQuotes)(((_a = ref.ref) === null || _a === void 0 ? void 0 : _a.toString()) || '')}, url: ${(0, global_1.escapeQuotes)(ref.url || '')}`;
|
|
77
89
|
}
|
|
78
90
|
});
|
|
79
91
|
}
|
|
80
92
|
Object.entries(this.tags).forEach(([tag, value]) => {
|
|
81
93
|
if (value) {
|
|
82
|
-
if (typeof value ===
|
|
83
|
-
if (Array.isArray(value) && typeof value[0] ===
|
|
84
|
-
|
|
94
|
+
if (typeof value === 'object') {
|
|
95
|
+
if (Array.isArray(value) && typeof value[0] === 'string') {
|
|
96
|
+
// The goal is to keep the style similar to cookstyle formatting
|
|
97
|
+
result += ` tag ${tag}: ${JSON.stringify(value)
|
|
98
|
+
.replace(/"/g, "'") // replace the double quotes with single quotes, ex: ["V-72029","SV-86653"] -> ['V-72029','SV-86653']
|
|
99
|
+
.split("','") // split the items in the string
|
|
100
|
+
.join("', '")}\n`; // join them together using single quote and a space, ex: ['V-72029','SV-86653'] -> ['V-72029', 'SV-86653']
|
|
85
101
|
}
|
|
86
102
|
else {
|
|
87
103
|
// Convert JSON Object to Ruby Hash
|
|
88
104
|
const stringifiedObject = JSON.stringify(value, null, 2)
|
|
89
|
-
.replace(/\n/g,
|
|
90
|
-
.replace(/\{\n {6}/g,
|
|
91
|
-
.replace(/\[\n {8}/g,
|
|
92
|
-
.replace(/\n {6}\]/g,
|
|
93
|
-
.replace(/\n {4}\}/g,
|
|
105
|
+
.replace(/\n/g, '\n ')
|
|
106
|
+
.replace(/\{\n {6}/g, '{')
|
|
107
|
+
.replace(/\[\n {8}/g, '[')
|
|
108
|
+
.replace(/\n {6}\]/g, ']')
|
|
109
|
+
.replace(/\n {4}\}/g, '}')
|
|
94
110
|
.replace(/": \[/g, '" => [');
|
|
95
111
|
result += ` tag ${tag}: ${stringifiedObject}\n`;
|
|
96
112
|
}
|
|
97
113
|
}
|
|
98
|
-
else if (typeof value ===
|
|
99
|
-
result += ` tag ${tag}:
|
|
114
|
+
else if (typeof value === 'string') {
|
|
115
|
+
result += ` tag ${tag}: ${(0, global_1.escapeQuotes)(value)}\n`;
|
|
100
116
|
}
|
|
101
117
|
}
|
|
102
118
|
});
|
|
@@ -104,7 +120,10 @@ class Control {
|
|
|
104
120
|
result += '\n';
|
|
105
121
|
result += this.describe;
|
|
106
122
|
}
|
|
107
|
-
result
|
|
123
|
+
if (!result.slice(-1).match('\n')) {
|
|
124
|
+
result += '\n';
|
|
125
|
+
}
|
|
126
|
+
result += 'end\n';
|
|
108
127
|
return result;
|
|
109
128
|
}
|
|
110
129
|
}
|
package/lib/objects/profile.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Control from
|
|
1
|
+
import Control from './control';
|
|
2
2
|
export default class Profile {
|
|
3
3
|
name?: string | null;
|
|
4
4
|
title?: string | null;
|
|
@@ -11,10 +11,10 @@ export default class Profile {
|
|
|
11
11
|
version?: string | null;
|
|
12
12
|
inspec_version?: string | null;
|
|
13
13
|
supports: {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
'platform-family'?: string;
|
|
15
|
+
'platform-name'?: string;
|
|
16
|
+
'os-name'?: string;
|
|
17
|
+
'os-family'?: string;
|
|
18
18
|
release?: string;
|
|
19
19
|
platform?: string;
|
|
20
20
|
}[];
|
|
@@ -44,7 +44,7 @@ export default class Profile {
|
|
|
44
44
|
readme?: string | null;
|
|
45
45
|
files: string[];
|
|
46
46
|
controls: Control[];
|
|
47
|
-
constructor(data?: Omit<Partial<Profile>,
|
|
47
|
+
constructor(data?: Omit<Partial<Profile>, 'controls'>);
|
|
48
48
|
createInspecYaml(): string;
|
|
49
49
|
toUnformattedObject(): Profile;
|
|
50
50
|
}
|
package/lib/objects/profile.js
CHANGED
|
@@ -37,7 +37,7 @@ class Profile {
|
|
|
37
37
|
toUnformattedObject() {
|
|
38
38
|
const unformattedProfile = new Profile(this);
|
|
39
39
|
Object.entries(this).forEach(([key, value]) => {
|
|
40
|
-
if (typeof value ===
|
|
40
|
+
if (typeof value === 'string') {
|
|
41
41
|
lodash_1.default.set(unformattedProfile, key, (0, global_1.unformatText)(value));
|
|
42
42
|
}
|
|
43
43
|
});
|
package/lib/parsers/json.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ContextualizedEvaluation, ContextualizedProfile, ExecJSON } from
|
|
2
|
-
import Profile from
|
|
1
|
+
import { ContextualizedEvaluation, ContextualizedProfile, ExecJSON } from 'inspecjs';
|
|
2
|
+
import Profile from '../objects/profile';
|
|
3
3
|
export declare function processEvaluation(evaluationInput: ContextualizedEvaluation): Profile;
|
|
4
4
|
export declare function processProfileJSON(profileInput: ContextualizedProfile): Profile;
|
|
5
5
|
export declare function processExecJSON(execJSON: ExecJSON.Execution): Profile;
|
|
6
|
-
export declare function
|
|
6
|
+
export declare function processInSpecProfile(json: string): Profile;
|
package/lib/parsers/json.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.processInSpecProfile = exports.processExecJSON = exports.processProfileJSON = exports.processEvaluation = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const inspecjs_1 = require("inspecjs");
|
|
6
6
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
7
7
|
const control_1 = tslib_1.__importStar(require("../objects/control"));
|
|
8
8
|
const profile_1 = tslib_1.__importDefault(require("../objects/profile"));
|
|
9
|
+
const update_1 = require("../utilities/update");
|
|
9
10
|
function processEvaluation(evaluationInput) {
|
|
10
11
|
const topLevelProfile = evaluationInput.contains[0];
|
|
11
12
|
const profile = new profile_1.default({
|
|
@@ -14,9 +15,9 @@ function processEvaluation(evaluationInput) {
|
|
|
14
15
|
maintainer: topLevelProfile.data.maintainer,
|
|
15
16
|
copyright: topLevelProfile.data.copyright,
|
|
16
17
|
copyright_email: topLevelProfile.data.copyright_email,
|
|
17
|
-
license: lodash_1.default.get(topLevelProfile.data,
|
|
18
|
-
summary: lodash_1.default.get(topLevelProfile.data,
|
|
19
|
-
description: lodash_1.default.get(topLevelProfile.data,
|
|
18
|
+
license: lodash_1.default.get(topLevelProfile.data, 'license'),
|
|
19
|
+
summary: lodash_1.default.get(topLevelProfile.data, 'summary'),
|
|
20
|
+
description: lodash_1.default.get(topLevelProfile.data, 'description'),
|
|
20
21
|
version: topLevelProfile.data.version,
|
|
21
22
|
});
|
|
22
23
|
topLevelProfile.contains.forEach((control) => {
|
|
@@ -39,9 +40,9 @@ function processProfileJSON(profileInput) {
|
|
|
39
40
|
maintainer: profileInput.data.maintainer,
|
|
40
41
|
copyright: profileInput.data.copyright,
|
|
41
42
|
copyright_email: profileInput.data.copyright_email,
|
|
42
|
-
license: lodash_1.default.get(profileInput.data,
|
|
43
|
-
summary: lodash_1.default.get(profileInput.data,
|
|
44
|
-
description: lodash_1.default.get(profileInput.data,
|
|
43
|
+
license: lodash_1.default.get(profileInput.data, 'license'),
|
|
44
|
+
summary: lodash_1.default.get(profileInput.data, 'summary'),
|
|
45
|
+
description: lodash_1.default.get(profileInput.data, 'description'),
|
|
45
46
|
version: profileInput.data.version,
|
|
46
47
|
});
|
|
47
48
|
profileInput.data.controls.forEach((control) => {
|
|
@@ -54,12 +55,15 @@ function processProfileJSON(profileInput) {
|
|
|
54
55
|
tags: control.tags,
|
|
55
56
|
descs: (0, control_1.objectifyDescriptions)(control.descriptions),
|
|
56
57
|
});
|
|
58
|
+
newControl.describe = (0, update_1.getExistingDescribeFromControl)(newControl);
|
|
57
59
|
// Migrate check and fix text from tags to descriptions
|
|
58
60
|
if (newControl.tags.check && !newControl.descs.check) {
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
59
62
|
lodash_1.default.set(newControl.descs, 'check', control.tags.check);
|
|
60
63
|
lodash_1.default.set(newControl.tags, 'check', undefined);
|
|
61
64
|
}
|
|
62
65
|
if (newControl.tags.fix && !newControl.descs.fix) {
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
63
67
|
lodash_1.default.set(newControl.descs, 'fix', control.tags.fix);
|
|
64
68
|
lodash_1.default.set(newControl.tags, 'fix', undefined);
|
|
65
69
|
}
|
|
@@ -72,19 +76,19 @@ function processExecJSON(execJSON) {
|
|
|
72
76
|
return processEvaluation((0, inspecjs_1.contextualizeEvaluation)(execJSON));
|
|
73
77
|
}
|
|
74
78
|
exports.processExecJSON = processExecJSON;
|
|
75
|
-
function
|
|
79
|
+
function processInSpecProfile(json) {
|
|
76
80
|
const convertedFile = (0, inspecjs_1.convertFile)(json, true);
|
|
77
81
|
let profile = new profile_1.default();
|
|
78
|
-
if (convertedFile[
|
|
79
|
-
profile = processEvaluation((0, inspecjs_1.contextualizeEvaluation)(convertedFile[
|
|
82
|
+
if (convertedFile['1_0_ExecJson']) {
|
|
83
|
+
profile = processEvaluation((0, inspecjs_1.contextualizeEvaluation)(convertedFile['1_0_ExecJson'])).toUnformattedObject();
|
|
80
84
|
}
|
|
81
|
-
else if (convertedFile[
|
|
85
|
+
else if (convertedFile['1_0_ProfileJson']) {
|
|
82
86
|
profile = processProfileJSON((0, inspecjs_1.contextualizeProfile)(JSON.parse(json))).toUnformattedObject();
|
|
83
87
|
}
|
|
84
88
|
else {
|
|
85
|
-
throw new Error(
|
|
89
|
+
throw new Error('Unknown file type passed');
|
|
86
90
|
}
|
|
87
|
-
profile.controls = lodash_1.default.sortBy(profile.controls,
|
|
91
|
+
profile.controls = lodash_1.default.sortBy(profile.controls, 'id');
|
|
88
92
|
return profile;
|
|
89
93
|
}
|
|
90
|
-
exports.
|
|
94
|
+
exports.processInSpecProfile = processInSpecProfile;
|
package/lib/parsers/oval.js
CHANGED
|
@@ -4,10 +4,10 @@ exports.processOVAL = exports.extractAllCriteriaRefs = void 0;
|
|
|
4
4
|
const xccdf_1 = require("../utilities/xccdf");
|
|
5
5
|
// https://stackoverflow.com/questions/9133500/how-to-find-a-node-in-a-tree-with-javascript
|
|
6
6
|
function searchTree(aTree, fCompair, bGreedy) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// 1. loop through all root nodes so we don't touch the tree structure
|
|
7
|
+
let oNode; // always the current node
|
|
8
|
+
const aInnerTree = []; // will contain the inner children
|
|
9
|
+
const aReturnNodes = []; // the nodes array which will returned
|
|
10
|
+
// 1. loop through all root nodes, store tree content locally so we don't touch the tree structure
|
|
11
11
|
for (const keysTree in aTree) {
|
|
12
12
|
aInnerTree.push(aTree[keysTree]);
|
|
13
13
|
}
|
|
@@ -26,7 +26,7 @@ function searchTree(aTree, fCompair, bGreedy) {
|
|
|
26
26
|
// true if the property is an array
|
|
27
27
|
if (oNode[keysNode] instanceof Array) {
|
|
28
28
|
// 2. push all array object to aInnerTree to search in those later
|
|
29
|
-
for (
|
|
29
|
+
for (let i = 0; i < oNode[keysNode].length; i++) {
|
|
30
30
|
aInnerTree.push(oNode[keysNode][i]);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -40,8 +40,8 @@ function extractAllCriteriaRefs(initialCriteria) {
|
|
|
40
40
|
initialCriteria.forEach(criteria => {
|
|
41
41
|
var _a;
|
|
42
42
|
(_a = criteria.criterion) === null || _a === void 0 ? void 0 : _a.forEach((criterion) => {
|
|
43
|
-
if (criterion[
|
|
44
|
-
criteriaRefs.push(criterion[
|
|
43
|
+
if (criterion['@_test_ref']) {
|
|
44
|
+
criteriaRefs.push(criterion['@_test_ref']);
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
47
|
if (criteria.criteria) {
|
|
@@ -61,22 +61,23 @@ function processOVAL(oval) {
|
|
|
61
61
|
for (const ovalDefinitions of parsed.oval_definitions) {
|
|
62
62
|
for (const definitionList of ovalDefinitions.definitions) {
|
|
63
63
|
for (const definition of definitionList.definition) {
|
|
64
|
-
extractedDefinitions[definition[
|
|
65
|
-
extractedDefinitions[definition[
|
|
66
|
-
extractedDefinitions[definition[
|
|
64
|
+
extractedDefinitions[definition['@_id']] = definition;
|
|
65
|
+
extractedDefinitions[definition['@_id']].criteriaRefs = extractAllCriteriaRefs(definition.criteria);
|
|
66
|
+
extractedDefinitions[definition['@_id']].resolvedValues = (_a = extractedDefinitions[definition['@_id']].criteriaRefs) === null || _a === void 0 ? void 0 : _a.map((criteriaRef) => {
|
|
67
67
|
// Extract the original criteria from the oval file
|
|
68
|
-
const foundCriteriaRefererence = searchTree(parsed.oval_definitions[0].tests, (oNode) => oNode[
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
const foundCriteriaRefererence = searchTree(parsed.oval_definitions[0].tests, (oNode) => oNode['@_id'] === criteriaRef, false)[0];
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
70
|
+
const foundObjects = [];
|
|
71
|
+
const foundStates = [];
|
|
71
72
|
if (foundCriteriaRefererence) {
|
|
72
73
|
if (foundCriteriaRefererence.object) {
|
|
73
74
|
foundCriteriaRefererence.object.forEach((object) => {
|
|
74
|
-
if (!object[
|
|
75
|
+
if (!object['@_object_ref']) {
|
|
75
76
|
console.warn(`Found object without object_ref in test ${criteriaRef}`);
|
|
76
77
|
}
|
|
77
78
|
else {
|
|
78
|
-
const objectRef = object[
|
|
79
|
-
const foundObjectReference = searchTree(parsed.oval_definitions[0].objects, (oNode) => oNode[
|
|
79
|
+
const objectRef = object['@_object_ref'];
|
|
80
|
+
const foundObjectReference = searchTree(parsed.oval_definitions[0].objects, (oNode) => oNode['@_id'] === objectRef, false)[0];
|
|
80
81
|
if (foundObjectReference) {
|
|
81
82
|
foundObjects.push(foundObjectReference);
|
|
82
83
|
}
|
|
@@ -88,12 +89,12 @@ function processOVAL(oval) {
|
|
|
88
89
|
}
|
|
89
90
|
if (foundCriteriaRefererence.state) {
|
|
90
91
|
foundCriteriaRefererence.state.forEach((state) => {
|
|
91
|
-
if (!state[
|
|
92
|
+
if (!state['@_state_ref']) {
|
|
92
93
|
console.warn(`Found state without state_ref in test ${criteriaRef}`);
|
|
93
94
|
}
|
|
94
95
|
else {
|
|
95
|
-
const stateRef = state[
|
|
96
|
-
const foundStateReference = searchTree(parsed.oval_definitions[0].states, (oNode) => oNode[
|
|
96
|
+
const stateRef = state['@_state_ref'];
|
|
97
|
+
const foundStateReference = searchTree(parsed.oval_definitions[0].states, (oNode) => oNode['@_id'] === stateRef, false)[0];
|
|
97
98
|
if (foundStateReference) {
|
|
98
99
|
foundStates.push(foundStateReference);
|
|
99
100
|
}
|
package/lib/parsers/xccdf.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare type GroupContextualizedRule = BenchmarkRule & {
|
|
|
6
6
|
};
|
|
7
7
|
export declare function extractAllRules(groups: BenchmarkGroup[]): GroupContextualizedRule[];
|
|
8
8
|
export declare function extractAllComplexChecks(complexCheck: RuleComplexCheck): Omit<RuleComplexCheck, 'complex-check'>[];
|
|
9
|
-
export declare function processXCCDF(xml: string, removeNewlines:
|
|
9
|
+
export declare function processXCCDF(xml: string, removeNewlines: false, useRuleId: 'group' | 'rule' | 'version' | 'cis', ovalDefinitions?: Record<string, OvalDefinitionValue & {
|
|
10
10
|
criteriaRefs?: string[];
|
|
11
11
|
resolvedValues?: any;
|
|
12
12
|
}>): Profile;
|