@mitre/inspec-objects 1.0.1 → 2.0.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/.github/dependabot.yml +11 -0
- package/.github/workflows/auto-approve-and-merge.yml +22 -0
- package/.github/workflows/e2e-test.yml +1 -1
- package/.github/workflows/linter.yml +1 -2
- package/README.md +45 -4
- package/lib/index.d.ts +4 -2
- package/lib/index.js +5 -2
- package/lib/objects/control.d.ts +78 -0
- package/lib/objects/control.js +101 -18
- package/lib/objects/profile.d.ts +58 -0
- package/lib/objects/profile.js +60 -1
- package/lib/parsers/json.d.ts +32 -0
- package/lib/parsers/json.js +36 -5
- package/lib/parsers/oval.d.ts +28 -0
- package/lib/parsers/oval.js +45 -5
- package/lib/parsers/xccdf.d.ts +32 -1
- package/lib/parsers/xccdf.js +84 -38
- package/lib/utilities/diff.d.ts +42 -0
- package/lib/utilities/diff.js +51 -12
- package/lib/utilities/diffMarkdown.d.ts +13 -0
- package/lib/utilities/diffMarkdown.js +24 -12
- package/lib/utilities/global.d.ts +53 -0
- package/lib/utilities/global.js +92 -13
- package/lib/utilities/logging.d.ts +1 -1
- package/lib/utilities/logging.js +8 -5
- package/lib/utilities/update.d.ts +60 -1
- package/lib/utilities/update.js +132 -42
- package/lib/utilities/xccdf.d.ts +82 -1
- package/lib/utilities/xccdf.js +113 -22
- package/package.json +17 -17
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: Auto approve and Merge Dependabot PRs
|
|
2
|
+
on:
|
|
3
|
+
pull_request_target:
|
|
4
|
+
types: [labeled]
|
|
5
|
+
permissions:
|
|
6
|
+
pull-requests: write
|
|
7
|
+
contents: write
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
approve:
|
|
11
|
+
name: Auto-approve dependabot PRs
|
|
12
|
+
if: github.event.pull_request.user.login == 'dependabot[bot]' && contains(github.event.pull_request.labels.*.name, 'dependencies')
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- uses: hmarr/auto-approve-action@v3
|
|
16
|
+
with:
|
|
17
|
+
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
|
18
|
+
- name: Enable auto-merge for Dependabot PRs
|
|
19
|
+
run: gh pr merge --auto --merge "$PR_URL"
|
|
20
|
+
env:
|
|
21
|
+
PR_URL: ${{github.event.pull_request.html_url}}
|
|
22
|
+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
package/README.md
CHANGED
|
@@ -49,17 +49,58 @@ Here are some formatting choices that are being made.
|
|
|
49
49
|
<img src="images/Delta_Process.jpg" alt="Delta and Stub Generation Process" title="Delta and Stub Generation Process">
|
|
50
50
|
</div>
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
## Development Environment Configuration
|
|
53
|
+
### Installation
|
|
54
|
+
To install the project, clone the repository and install the dependencies:
|
|
55
|
+
```bash
|
|
56
|
+
# SSH
|
|
57
|
+
git clone git@github.com:mitre/ts-inspec-objects.git
|
|
58
|
+
# HTTPS
|
|
59
|
+
git clone https://github.com/mitre/ts-inspec-objects.git
|
|
60
|
+
|
|
61
|
+
cd project
|
|
62
|
+
npm install
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Compile the project
|
|
66
|
+
Use the `build` script command to generate the executable libraries:
|
|
67
|
+
```bash
|
|
68
|
+
npm run build
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Linting the code
|
|
72
|
+
Use either the `lint` or `lint:ci` command to invoke the linter:
|
|
73
|
+
```bash
|
|
74
|
+
# Auto fix
|
|
75
|
+
npm run lint
|
|
76
|
+
|
|
77
|
+
# Display linting findings
|
|
78
|
+
npm run lint:ci
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Run the Test Suite
|
|
82
|
+
Use the `test` script command to run all tests contained in the tests directory:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
npm run test
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Run a Specific Test
|
|
89
|
+
To run a specific test use the `npx jest --findRelatedTests` command:
|
|
90
|
+
```bash
|
|
91
|
+
npx jest --findRelatedTests <test\testName.ts>
|
|
92
|
+
```
|
|
93
|
+
## NOTICE
|
|
53
94
|
|
|
54
|
-
© 2018-
|
|
95
|
+
© 2018-2025 The MITRE Corporation.
|
|
55
96
|
|
|
56
97
|
Approved for Public Release; Distribution Unlimited. Case Number 18-3678.
|
|
57
98
|
|
|
58
|
-
|
|
99
|
+
## NOTICE
|
|
59
100
|
|
|
60
101
|
MITRE hereby grants express written permission to use, reproduce, distribute, modify, and otherwise leverage this software to the extent permitted by the licensed terms provided in the LICENSE.md file included with this project.
|
|
61
102
|
|
|
62
|
-
|
|
103
|
+
## NOTICE
|
|
63
104
|
|
|
64
105
|
This software was produced for the U. S. Government under Contract Number HHSM-500-2012-00008I, and is subject to Federal Acquisition Regulation Clause 52.227-14, Rights in Data-General.
|
|
65
106
|
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export * from './objects/control';
|
|
2
|
-
export * from './objects/profile';
|
|
3
1
|
export * from './parsers/json';
|
|
4
2
|
export * from './parsers/oval';
|
|
5
3
|
export * from './parsers/xccdf';
|
|
6
4
|
export * from './utilities/diff';
|
|
7
5
|
export * from './utilities/update';
|
|
6
|
+
import Control from './objects/control';
|
|
7
|
+
import Profile from './objects/profile';
|
|
8
|
+
export { Control };
|
|
9
|
+
export { Profile };
|
package/lib/index.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Profile = exports.Control = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./objects/control"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./objects/profile"), exports);
|
|
6
5
|
tslib_1.__exportStar(require("./parsers/json"), exports);
|
|
7
6
|
tslib_1.__exportStar(require("./parsers/oval"), exports);
|
|
8
7
|
tslib_1.__exportStar(require("./parsers/xccdf"), exports);
|
|
9
8
|
tslib_1.__exportStar(require("./utilities/diff"), exports);
|
|
10
9
|
tslib_1.__exportStar(require("./utilities/update"), exports);
|
|
10
|
+
const control_1 = tslib_1.__importDefault(require("./objects/control"));
|
|
11
|
+
exports.Control = control_1.default;
|
|
12
|
+
const profile_1 = tslib_1.__importDefault(require("./objects/profile"));
|
|
13
|
+
exports.Profile = profile_1.default;
|
package/lib/objects/control.d.ts
CHANGED
|
@@ -1,9 +1,40 @@
|
|
|
1
1
|
import { ExecJSON } from 'inspecjs';
|
|
2
|
+
/**
|
|
3
|
+
* Converts an array of ExecJSON.ControlDescription objects or a dictionary of descriptions
|
|
4
|
+
* into a standardized dictionary format.
|
|
5
|
+
*
|
|
6
|
+
* @param descs - An array of ExecJSON.ControlDescription objects, a dictionary of descriptions,
|
|
7
|
+
* or null/undefined.
|
|
8
|
+
* @returns A dictionary where the keys are description labels and the values are description data.
|
|
9
|
+
* If the input is null or undefined, an empty dictionary is returned.
|
|
10
|
+
*/
|
|
2
11
|
export declare function objectifyDescriptions(descs: ExecJSON.ControlDescription[] | {
|
|
3
12
|
[key: string]: string | undefined;
|
|
4
13
|
} | null | undefined): {
|
|
5
14
|
[key: string]: string | undefined;
|
|
6
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* Represents a Control object with various properties and methods to manipulate and convert it.
|
|
18
|
+
*
|
|
19
|
+
* @class Control
|
|
20
|
+
* @property {string} id - The unique identifier for the control.
|
|
21
|
+
* @property {string | null} [title] - The title of the control.
|
|
22
|
+
* @property {string | null} [code] - The code associated with the control.
|
|
23
|
+
* @property {string | null} [describe] - Additional description content for the control.
|
|
24
|
+
* @property {string | null} [desc] - The default description of the control.
|
|
25
|
+
* @property {Object.<string, string | undefined>} descs - Additional descriptions for the control.
|
|
26
|
+
* @property {number} [impact] - The impact value of the control.
|
|
27
|
+
* @property {string} [ref] - A reference string for the control.
|
|
28
|
+
* @property {(string | { ref?: string; url?: string; uri?: string; })[]} [refs] - An array of references for the control.
|
|
29
|
+
* @property {Object.<string, string | string[] | Record<string, string[]>[] | boolean | undefined | null>} tags - Tags associated with the control.
|
|
30
|
+
*
|
|
31
|
+
* @constructor
|
|
32
|
+
* @param {Partial<Control>} [data] - An optional partial object of type Control to initialize the instance with.
|
|
33
|
+
*
|
|
34
|
+
* @method toUnformattedObject
|
|
35
|
+
* @method toString
|
|
36
|
+
* @method toRuby
|
|
37
|
+
*/
|
|
7
38
|
export default class Control {
|
|
8
39
|
id: string;
|
|
9
40
|
title?: string | null;
|
|
@@ -47,8 +78,55 @@ export default class Control {
|
|
|
47
78
|
ia_controls?: string;
|
|
48
79
|
[key: string]: string | string[] | Record<string, string[]>[] | boolean | undefined | null;
|
|
49
80
|
};
|
|
81
|
+
/**
|
|
82
|
+
* Constructs a new instance of the Control class.
|
|
83
|
+
*
|
|
84
|
+
* @param data - An optional partial object of type Control to initialize the instance with.
|
|
85
|
+
* If provided, the properties of the data object will be assigned to the instance.
|
|
86
|
+
*/
|
|
50
87
|
constructor(data?: Partial<Control>);
|
|
88
|
+
/**
|
|
89
|
+
* Converts the current Control object into an unformatted object.
|
|
90
|
+
* The method flattens the object, processes its string properties,
|
|
91
|
+
* and then unflattens it back into a Control object.
|
|
92
|
+
*
|
|
93
|
+
* @returns {Control} A new Control object created from the unformatted data.
|
|
94
|
+
*/
|
|
51
95
|
toUnformattedObject(): Control;
|
|
96
|
+
/**
|
|
97
|
+
* Converts the control object to a string representation in a specific format.
|
|
98
|
+
* Provides the ability to get the control in its raw form
|
|
99
|
+
*
|
|
100
|
+
* The resulting string includes:
|
|
101
|
+
* - The control ID.
|
|
102
|
+
* - The title, if present.
|
|
103
|
+
* - The default description, if present.
|
|
104
|
+
* - Additional descriptions, if present.
|
|
105
|
+
* - The impact value, if present.
|
|
106
|
+
* - References, if present.
|
|
107
|
+
* - Tags, if present.
|
|
108
|
+
* - Additional describe content, if present.
|
|
109
|
+
*
|
|
110
|
+
* @returns {string} The string representation of the control object.
|
|
111
|
+
*/
|
|
52
112
|
toString(): string;
|
|
113
|
+
/**
|
|
114
|
+
* Converts the control object to a Ruby string representation.
|
|
115
|
+
*
|
|
116
|
+
* @param {boolean} [verbose=false] - If true, logs detailed error and warning messages.
|
|
117
|
+
* @returns {string} The Ruby string representation of the control object.
|
|
118
|
+
*
|
|
119
|
+
* The generated Ruby string includes:
|
|
120
|
+
* - `control` block with the control ID.
|
|
121
|
+
* - `title` if available, otherwise logs an error if verbose is true.
|
|
122
|
+
* - `desc` if available, otherwise logs an error if verbose is true.
|
|
123
|
+
* - Additional descriptions (`descs`) if available, with special handling for the 'default' keyword.
|
|
124
|
+
* - `impact` if defined, otherwise logs an error if verbose is true.
|
|
125
|
+
* - `refs` if available, with support for both string and object references.
|
|
126
|
+
* - `tags` if available, with special formatting for arrays and objects, and handling for nil values for specific tags.
|
|
127
|
+
* - `describe` if available, appended at the end of the control block.
|
|
128
|
+
*
|
|
129
|
+
* The function ensures proper formatting and escaping of quotes for Ruby syntax.
|
|
130
|
+
*/
|
|
53
131
|
toRuby(verbose?: boolean): string;
|
|
54
132
|
}
|
package/lib/objects/control.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.objectifyDescriptions =
|
|
3
|
+
exports.objectifyDescriptions = objectifyDescriptions;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
6
6
|
const flat_1 = require("flat");
|
|
7
|
+
const flat_2 = require("flat");
|
|
7
8
|
const global_1 = require("../utilities/global");
|
|
8
9
|
const logging_1 = require("../utilities/logging");
|
|
10
|
+
/**
|
|
11
|
+
* Converts an array of ExecJSON.ControlDescription objects or a dictionary of descriptions
|
|
12
|
+
* into a standardized dictionary format.
|
|
13
|
+
*
|
|
14
|
+
* @param descs - An array of ExecJSON.ControlDescription objects, a dictionary of descriptions,
|
|
15
|
+
* or null/undefined.
|
|
16
|
+
* @returns A dictionary where the keys are description labels and the values are description data.
|
|
17
|
+
* If the input is null or undefined, an empty dictionary is returned.
|
|
18
|
+
*/
|
|
9
19
|
function objectifyDescriptions(descs) {
|
|
10
20
|
if (Array.isArray(descs)) {
|
|
11
21
|
const descriptions = {};
|
|
@@ -16,8 +26,35 @@ function objectifyDescriptions(descs) {
|
|
|
16
26
|
}
|
|
17
27
|
return descs || {};
|
|
18
28
|
}
|
|
19
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Represents a Control object with various properties and methods to manipulate and convert it.
|
|
31
|
+
*
|
|
32
|
+
* @class Control
|
|
33
|
+
* @property {string} id - The unique identifier for the control.
|
|
34
|
+
* @property {string | null} [title] - The title of the control.
|
|
35
|
+
* @property {string | null} [code] - The code associated with the control.
|
|
36
|
+
* @property {string | null} [describe] - Additional description content for the control.
|
|
37
|
+
* @property {string | null} [desc] - The default description of the control.
|
|
38
|
+
* @property {Object.<string, string | undefined>} descs - Additional descriptions for the control.
|
|
39
|
+
* @property {number} [impact] - The impact value of the control.
|
|
40
|
+
* @property {string} [ref] - A reference string for the control.
|
|
41
|
+
* @property {(string | { ref?: string; url?: string; uri?: string; })[]} [refs] - An array of references for the control.
|
|
42
|
+
* @property {Object.<string, string | string[] | Record<string, string[]>[] | boolean | undefined | null>} tags - Tags associated with the control.
|
|
43
|
+
*
|
|
44
|
+
* @constructor
|
|
45
|
+
* @param {Partial<Control>} [data] - An optional partial object of type Control to initialize the instance with.
|
|
46
|
+
*
|
|
47
|
+
* @method toUnformattedObject
|
|
48
|
+
* @method toString
|
|
49
|
+
* @method toRuby
|
|
50
|
+
*/
|
|
20
51
|
class Control {
|
|
52
|
+
/**
|
|
53
|
+
* Constructs a new instance of the Control class.
|
|
54
|
+
*
|
|
55
|
+
* @param data - An optional partial object of type Control to initialize the instance with.
|
|
56
|
+
* If provided, the properties of the data object will be assigned to the instance.
|
|
57
|
+
*/
|
|
21
58
|
constructor(data) {
|
|
22
59
|
this.tags = {};
|
|
23
60
|
this.refs = [];
|
|
@@ -28,6 +65,13 @@ class Control {
|
|
|
28
65
|
});
|
|
29
66
|
}
|
|
30
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Converts the current Control object into an unformatted object.
|
|
70
|
+
* The method flattens the object, processes its string properties,
|
|
71
|
+
* and then unflattens it back into a Control object.
|
|
72
|
+
*
|
|
73
|
+
* @returns {Control} A new Control object created from the unformatted data.
|
|
74
|
+
*/
|
|
31
75
|
toUnformattedObject() {
|
|
32
76
|
const flattened = (0, flat_1.flatten)(this);
|
|
33
77
|
Object.entries(flattened).forEach(([key, value]) => {
|
|
@@ -35,9 +79,24 @@ class Control {
|
|
|
35
79
|
lodash_1.default.set(flattened, key, value);
|
|
36
80
|
}
|
|
37
81
|
});
|
|
38
|
-
return new Control((0,
|
|
82
|
+
return new Control((0, flat_2.unflatten)(flattened));
|
|
39
83
|
}
|
|
40
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Converts the control object to a string representation in a specific format.
|
|
86
|
+
* Provides the ability to get the control in its raw form
|
|
87
|
+
*
|
|
88
|
+
* The resulting string includes:
|
|
89
|
+
* - The control ID.
|
|
90
|
+
* - The title, if present.
|
|
91
|
+
* - The default description, if present.
|
|
92
|
+
* - Additional descriptions, if present.
|
|
93
|
+
* - The impact value, if present.
|
|
94
|
+
* - References, if present.
|
|
95
|
+
* - Tags, if present.
|
|
96
|
+
* - Additional describe content, if present.
|
|
97
|
+
*
|
|
98
|
+
* @returns {string} The string representation of the control object.
|
|
99
|
+
*/
|
|
41
100
|
toString() {
|
|
42
101
|
let result = '';
|
|
43
102
|
result += `control '${this.id}' do\n`;
|
|
@@ -58,6 +117,9 @@ class Control {
|
|
|
58
117
|
if (this.impact) {
|
|
59
118
|
result += ` impact ${this.impact}\n`;
|
|
60
119
|
}
|
|
120
|
+
else if (this.impact === 0) {
|
|
121
|
+
result += ` impact ${this.impact.toFixed(1)}\n`;
|
|
122
|
+
}
|
|
61
123
|
if (this.refs) {
|
|
62
124
|
this.refs.forEach((ref) => {
|
|
63
125
|
var _a;
|
|
@@ -97,8 +159,26 @@ class Control {
|
|
|
97
159
|
result += 'end\n';
|
|
98
160
|
return result;
|
|
99
161
|
}
|
|
100
|
-
|
|
101
|
-
|
|
162
|
+
/**
|
|
163
|
+
* Converts the control object to a Ruby string representation.
|
|
164
|
+
*
|
|
165
|
+
* @param {boolean} [verbose=false] - If true, logs detailed error and warning messages.
|
|
166
|
+
* @returns {string} The Ruby string representation of the control object.
|
|
167
|
+
*
|
|
168
|
+
* The generated Ruby string includes:
|
|
169
|
+
* - `control` block with the control ID.
|
|
170
|
+
* - `title` if available, otherwise logs an error if verbose is true.
|
|
171
|
+
* - `desc` if available, otherwise logs an error if verbose is true.
|
|
172
|
+
* - Additional descriptions (`descs`) if available, with special handling for the 'default' keyword.
|
|
173
|
+
* - `impact` if defined, otherwise logs an error if verbose is true.
|
|
174
|
+
* - `refs` if available, with support for both string and object references.
|
|
175
|
+
* - `tags` if available, with special formatting for arrays and objects, and handling for nil values for specific tags.
|
|
176
|
+
* - `describe` if available, appended at the end of the control block.
|
|
177
|
+
*
|
|
178
|
+
* The function ensures proper formatting and escaping of quotes for Ruby syntax.
|
|
179
|
+
*/
|
|
180
|
+
toRuby(verbose = false) {
|
|
181
|
+
const logger = (0, logging_1.createWinstonLogger)('ts-inspec-objects');
|
|
102
182
|
let result = '';
|
|
103
183
|
result += `control '${this.id}' do\n`;
|
|
104
184
|
if (this.title) {
|
|
@@ -137,7 +217,7 @@ class Control {
|
|
|
137
217
|
}
|
|
138
218
|
else {
|
|
139
219
|
if (verbose) {
|
|
140
|
-
logger.
|
|
220
|
+
logger.warn(`${this.id} does not have a desc for the value ${key}`);
|
|
141
221
|
}
|
|
142
222
|
}
|
|
143
223
|
});
|
|
@@ -150,17 +230,20 @@ class Control {
|
|
|
150
230
|
logger.error(`${this.id} does not have an impact`);
|
|
151
231
|
}
|
|
152
232
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
233
|
+
//-------------------------------------------------------------------------
|
|
234
|
+
// This may not be necessary, leaving commented code for posterity. Once we
|
|
235
|
+
// have implemented the process and determined that there isn't any side
|
|
236
|
+
// effects we can remove the commented code
|
|
237
|
+
//-------------------------------------------------------------------------
|
|
238
|
+
// if (this.refs) {
|
|
239
|
+
// this.refs.forEach((ref) => {
|
|
240
|
+
// if (typeof ref === 'string') {
|
|
241
|
+
// result += ` ref ${escapeQuotes(ref)}\n`;
|
|
242
|
+
// } else {
|
|
243
|
+
// result += ` ref ${escapeQuotes(ref.ref?.toString() || '')}, url: ${escapeQuotes(ref.url || '')}`
|
|
244
|
+
// }
|
|
245
|
+
// });
|
|
246
|
+
// }
|
|
164
247
|
Object.entries(this.tags).forEach(([tag, value]) => {
|
|
165
248
|
if (value) {
|
|
166
249
|
if (typeof value === 'object') {
|
package/lib/objects/profile.d.ts
CHANGED
|
@@ -1,4 +1,38 @@
|
|
|
1
1
|
import Control from './control';
|
|
2
|
+
/**
|
|
3
|
+
* Represents an InSpec profile with various metadata and dependencies.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* This class is used to model an InSpec profile, which includes metadata such as
|
|
7
|
+
* name, title, maintainer, copyright, license, and version. It also includes
|
|
8
|
+
* dependencies, supported platforms, inputs, gem dependencies, libraries, readme,
|
|
9
|
+
* files, and controls.
|
|
10
|
+
*
|
|
11
|
+
* It provides methods to generate a YAML representation of the profile and to convert
|
|
12
|
+
* the profile to an unformatted version.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const profileData = {
|
|
17
|
+
* name: "example-profile",
|
|
18
|
+
* title: "Example Profile",
|
|
19
|
+
* maintainer: "John Doe",
|
|
20
|
+
* version: "1.0.0",
|
|
21
|
+
* supports: [{ 'platform-name': 'ubuntu' }],
|
|
22
|
+
* depends: [{ name: "dependency-profile", url: "http://example.com/dependency.tar.gz" }],
|
|
23
|
+
* inputs: [{ key: "value" }],
|
|
24
|
+
* libraries: ["lib/example.rb"],
|
|
25
|
+
* files: ["controls/example.rb"],
|
|
26
|
+
* readme: "This is an example profile.",
|
|
27
|
+
* };
|
|
28
|
+
*
|
|
29
|
+
* const profile = new Profile(profileData);
|
|
30
|
+
* const yamlString = profile.createInspecYaml();
|
|
31
|
+
* console.log(yamlString);
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
2
36
|
export default class Profile {
|
|
3
37
|
name?: string | null;
|
|
4
38
|
title?: string | null;
|
|
@@ -44,7 +78,31 @@ export default class Profile {
|
|
|
44
78
|
readme?: string | null;
|
|
45
79
|
files: string[];
|
|
46
80
|
controls: Control[];
|
|
81
|
+
/**
|
|
82
|
+
* Constructs a new instance of the Profile class.
|
|
83
|
+
*
|
|
84
|
+
* @param data - An optional object containing partial profile data, excluding the 'controls' property.
|
|
85
|
+
* The provided data will be used to set the corresponding properties on the instance.
|
|
86
|
+
*/
|
|
47
87
|
constructor(data?: Omit<Partial<Profile>, 'controls'>);
|
|
88
|
+
/**
|
|
89
|
+
* Generates an InSpec YAML string representation of the profile object.
|
|
90
|
+
* Note: Per Chef documentation the inspec_version should be a string
|
|
91
|
+
* in the format of "x.y.z" or "x.y.z-alpha" or "x.y.z-beta",
|
|
92
|
+
* it must be double quoted, most often the format is "~>#.#"
|
|
93
|
+
*
|
|
94
|
+
* @returns {string} The YAML string representation of the profile.
|
|
95
|
+
*/
|
|
48
96
|
createInspecYaml(): string;
|
|
97
|
+
/**
|
|
98
|
+
* Converts the current Profile object to an unformatted version.
|
|
99
|
+
*
|
|
100
|
+
* This method creates a new Profile instance and iterates over the properties
|
|
101
|
+
* of the current Profile object. If a property value is a string, it applies
|
|
102
|
+
* the `unformatText` function to the value and sets it on the new Profile instance.
|
|
103
|
+
* It also recursively converts the controls of the Profile to their unformatted versions.
|
|
104
|
+
*
|
|
105
|
+
* @returns {Profile} The unformatted Profile object.
|
|
106
|
+
*/
|
|
49
107
|
toUnformattedObject(): Profile;
|
|
50
108
|
}
|
package/lib/objects/profile.js
CHANGED
|
@@ -4,7 +4,47 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
const yaml_1 = tslib_1.__importDefault(require("yaml"));
|
|
5
5
|
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
6
6
|
const global_1 = require("../utilities/global");
|
|
7
|
+
/**
|
|
8
|
+
* Represents an InSpec profile with various metadata and dependencies.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* This class is used to model an InSpec profile, which includes metadata such as
|
|
12
|
+
* name, title, maintainer, copyright, license, and version. It also includes
|
|
13
|
+
* dependencies, supported platforms, inputs, gem dependencies, libraries, readme,
|
|
14
|
+
* files, and controls.
|
|
15
|
+
*
|
|
16
|
+
* It provides methods to generate a YAML representation of the profile and to convert
|
|
17
|
+
* the profile to an unformatted version.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const profileData = {
|
|
22
|
+
* name: "example-profile",
|
|
23
|
+
* title: "Example Profile",
|
|
24
|
+
* maintainer: "John Doe",
|
|
25
|
+
* version: "1.0.0",
|
|
26
|
+
* supports: [{ 'platform-name': 'ubuntu' }],
|
|
27
|
+
* depends: [{ name: "dependency-profile", url: "http://example.com/dependency.tar.gz" }],
|
|
28
|
+
* inputs: [{ key: "value" }],
|
|
29
|
+
* libraries: ["lib/example.rb"],
|
|
30
|
+
* files: ["controls/example.rb"],
|
|
31
|
+
* readme: "This is an example profile.",
|
|
32
|
+
* };
|
|
33
|
+
*
|
|
34
|
+
* const profile = new Profile(profileData);
|
|
35
|
+
* const yamlString = profile.createInspecYaml();
|
|
36
|
+
* console.log(yamlString);
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
7
41
|
class Profile {
|
|
42
|
+
/**
|
|
43
|
+
* Constructs a new instance of the Profile class.
|
|
44
|
+
*
|
|
45
|
+
* @param data - An optional object containing partial profile data, excluding the 'controls' property.
|
|
46
|
+
* The provided data will be used to set the corresponding properties on the instance.
|
|
47
|
+
*/
|
|
8
48
|
constructor(data) {
|
|
9
49
|
this.supports = [];
|
|
10
50
|
this.depends = [];
|
|
@@ -18,6 +58,14 @@ class Profile {
|
|
|
18
58
|
});
|
|
19
59
|
}
|
|
20
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Generates an InSpec YAML string representation of the profile object.
|
|
63
|
+
* Note: Per Chef documentation the inspec_version should be a string
|
|
64
|
+
* in the format of "x.y.z" or "x.y.z-alpha" or "x.y.z-beta",
|
|
65
|
+
* it must be double quoted, most often the format is "~>#.#"
|
|
66
|
+
*
|
|
67
|
+
* @returns {string} The YAML string representation of the profile.
|
|
68
|
+
*/
|
|
21
69
|
createInspecYaml() {
|
|
22
70
|
return yaml_1.default.stringify({
|
|
23
71
|
name: this.name,
|
|
@@ -31,9 +79,20 @@ class Profile {
|
|
|
31
79
|
version: this.version,
|
|
32
80
|
supports: this.supports,
|
|
33
81
|
depends: this.depends,
|
|
34
|
-
inspec_version: this.inspec_version,
|
|
82
|
+
//inspec_version: this.inspec_version,
|
|
83
|
+
inspec_version: yaml_1.default.stringify(`${this.inspec_version}`, { defaultStringType: 'QUOTE_DOUBLE' }),
|
|
35
84
|
});
|
|
36
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Converts the current Profile object to an unformatted version.
|
|
88
|
+
*
|
|
89
|
+
* This method creates a new Profile instance and iterates over the properties
|
|
90
|
+
* of the current Profile object. If a property value is a string, it applies
|
|
91
|
+
* the `unformatText` function to the value and sets it on the new Profile instance.
|
|
92
|
+
* It also recursively converts the controls of the Profile to their unformatted versions.
|
|
93
|
+
*
|
|
94
|
+
* @returns {Profile} The unformatted Profile object.
|
|
95
|
+
*/
|
|
37
96
|
toUnformattedObject() {
|
|
38
97
|
const unformattedProfile = new Profile(this);
|
|
39
98
|
Object.entries(this).forEach(([key, value]) => {
|
package/lib/parsers/json.d.ts
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
import { ContextualizedEvaluation, ContextualizedProfile, ExecJSON } from 'inspecjs';
|
|
2
2
|
import Profile from '../objects/profile';
|
|
3
|
+
/**
|
|
4
|
+
* Processes a contextualized evaluation input and converts it into a Profile object.
|
|
5
|
+
*
|
|
6
|
+
* @param evaluationInput - The contextualized evaluation input containing profile and control data.
|
|
7
|
+
* @returns A Profile object populated with the data from the evaluation input.
|
|
8
|
+
*/
|
|
3
9
|
export declare function processEvaluation(evaluationInput: ContextualizedEvaluation): Profile;
|
|
10
|
+
/**
|
|
11
|
+
* Processes a contextualized profile JSON object and converts it into a Profile instance.
|
|
12
|
+
*
|
|
13
|
+
* @param profileInput - The contextualized profile input containing profile data and controls.
|
|
14
|
+
* @returns A Profile instance populated with the data from the input.
|
|
15
|
+
*/
|
|
4
16
|
export declare function processProfileJSON(profileInput: ContextualizedProfile): Profile;
|
|
17
|
+
/**
|
|
18
|
+
* Processes the given ExecJSON execution object and returns a Profile.
|
|
19
|
+
*
|
|
20
|
+
* This function takes an ExecJSON execution object, contextualizes the evaluation,
|
|
21
|
+
* and then processes the evaluation to produce a Profile.
|
|
22
|
+
*
|
|
23
|
+
* @param execJSON - The ExecJSON execution object to be processed.
|
|
24
|
+
* @returns The processed Profile.
|
|
25
|
+
*/
|
|
5
26
|
export declare function processExecJSON(execJSON: ExecJSON.Execution): Profile;
|
|
27
|
+
/**
|
|
28
|
+
* Processes an InSpec profile from a JSON string.
|
|
29
|
+
*
|
|
30
|
+
* This function takes a JSON string representing an InSpec profile, converts it,
|
|
31
|
+
* and processes it to return a `Profile` object. It handles different versions
|
|
32
|
+
* of the InSpec JSON format and sorts the controls by their ID.
|
|
33
|
+
*
|
|
34
|
+
* @param json - The JSON string representing the InSpec profile.
|
|
35
|
+
* @returns A `Profile` object containing the processed profile data.
|
|
36
|
+
* @throws Will throw an error if the JSON string does not match known InSpec formats.
|
|
37
|
+
*/
|
|
6
38
|
export declare function processInSpecProfile(json: string): Profile;
|