regula-wasi 3.2.3 → 3.2.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.
- package/README.md +20 -0
- package/index.d.ts +119 -0
- package/index.js +41 -8
- package/package.json +3 -1
- package/regula.wasm +0 -0
package/README.md
CHANGED
|
@@ -89,6 +89,16 @@ if (result.summary.rule_results.FAIL > 0) {
|
|
|
89
89
|
console.error('Security violations found!');
|
|
90
90
|
process.exit(1);
|
|
91
91
|
}
|
|
92
|
+
|
|
93
|
+
// Error handling with detailed error information
|
|
94
|
+
try {
|
|
95
|
+
const result = await runRegula('./main.tf');
|
|
96
|
+
} catch (error) {
|
|
97
|
+
// RegulaError includes stdout, stderr, exitCode, and command
|
|
98
|
+
console.error('Error:', error.message);
|
|
99
|
+
console.error('Stderr:', error.stderr);
|
|
100
|
+
console.error('Exit code:', error.exitCode);
|
|
101
|
+
}
|
|
92
102
|
```
|
|
93
103
|
|
|
94
104
|
#### API Options
|
|
@@ -103,6 +113,16 @@ if (result.summary.rule_results.FAIL > 0) {
|
|
|
103
113
|
| `noIgnore` | boolean | Disable .gitignore filtering |
|
|
104
114
|
| `varFiles` | string[] | Terraform variable files (.tfvars) to use |
|
|
105
115
|
|
|
116
|
+
#### Error Handling
|
|
117
|
+
|
|
118
|
+
When an error occurs, a `RegulaError` is thrown with the following properties:
|
|
119
|
+
|
|
120
|
+
- `message` - Error description
|
|
121
|
+
- `stdout` - Standard output from regula command
|
|
122
|
+
- `stderr` - Standard error output (includes OPA errors and warnings)
|
|
123
|
+
- `exitCode` - Exit code from regula process
|
|
124
|
+
- `command` - The command that was executed
|
|
125
|
+
|
|
106
126
|
### Prebuilt Binary
|
|
107
127
|
|
|
108
128
|
Download from [Releases](https://github.com/nonfx/regula/releases) for your platform.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error class for Regula execution errors
|
|
3
|
+
*/
|
|
4
|
+
export class RegulaError extends Error {
|
|
5
|
+
/** Standard output from regula command */
|
|
6
|
+
stdout: string;
|
|
7
|
+
/** Standard error output from regula command */
|
|
8
|
+
stderr: string;
|
|
9
|
+
/** Exit code from regula process */
|
|
10
|
+
exitCode: number;
|
|
11
|
+
/** The command that was executed */
|
|
12
|
+
command: string;
|
|
13
|
+
|
|
14
|
+
constructor(
|
|
15
|
+
message: string,
|
|
16
|
+
details: {
|
|
17
|
+
stdout: string;
|
|
18
|
+
stderr: string;
|
|
19
|
+
exitCode: number;
|
|
20
|
+
command: string;
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface RegulaOptions {
|
|
26
|
+
/** Input type: auto, tf, tf-plan, cfn, k8s, arm */
|
|
27
|
+
inputType?: "auto" | "tf" | "tf-plan" | "cfn" | "k8s" | "arm";
|
|
28
|
+
/** Additional rego rule files/directories to include */
|
|
29
|
+
include?: string | string[];
|
|
30
|
+
/** Only run these specific rule IDs */
|
|
31
|
+
only?: string | string[];
|
|
32
|
+
/** Exclude these specific rule IDs */
|
|
33
|
+
exclude?: string | string[];
|
|
34
|
+
/** Disable built-in rules (use only custom rules from include) */
|
|
35
|
+
noBuiltIns?: boolean;
|
|
36
|
+
/** Disable .gitignore filtering */
|
|
37
|
+
noIgnore?: boolean;
|
|
38
|
+
/** Terraform variable files (.tfvars) to use */
|
|
39
|
+
varFiles?: string | string[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface SourceLocation {
|
|
43
|
+
path: string;
|
|
44
|
+
line: number;
|
|
45
|
+
column: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface RuleResult {
|
|
49
|
+
controls: string[];
|
|
50
|
+
families: string[];
|
|
51
|
+
filepath: string;
|
|
52
|
+
input_type: string;
|
|
53
|
+
provider: string;
|
|
54
|
+
resource_id: string;
|
|
55
|
+
resource_type: string;
|
|
56
|
+
resource_tags: Record<string, unknown>;
|
|
57
|
+
rule_description: string;
|
|
58
|
+
rule_id: string;
|
|
59
|
+
rule_message: string;
|
|
60
|
+
rule_name: string;
|
|
61
|
+
rule_raw_result: boolean;
|
|
62
|
+
rule_remediation_doc?: string;
|
|
63
|
+
rule_result: "PASS" | "FAIL" | "WAIVED";
|
|
64
|
+
rule_severity: "Unknown" | "Informational" | "Low" | "Medium" | "High" | "Critical";
|
|
65
|
+
rule_summary: string;
|
|
66
|
+
source_location?: SourceLocation[];
|
|
67
|
+
active_waivers?: string[];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface RegulaResult {
|
|
71
|
+
rule_results: RuleResult[];
|
|
72
|
+
summary: {
|
|
73
|
+
filepaths: string[];
|
|
74
|
+
rule_results: {
|
|
75
|
+
PASS: number;
|
|
76
|
+
FAIL: number;
|
|
77
|
+
WAIVED: number;
|
|
78
|
+
};
|
|
79
|
+
severities: {
|
|
80
|
+
Unknown: number;
|
|
81
|
+
Informational: number;
|
|
82
|
+
Low: number;
|
|
83
|
+
Medium: number;
|
|
84
|
+
High: number;
|
|
85
|
+
Critical: number;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Run regula on the specified path(s) and return parsed JSON results.
|
|
92
|
+
* @param paths - Path(s) to IaC files or directories
|
|
93
|
+
* @param options - Optional configuration
|
|
94
|
+
* @returns Parsed regula output with rule_results and summary
|
|
95
|
+
*/
|
|
96
|
+
export function runRegula(
|
|
97
|
+
paths: string | string[],
|
|
98
|
+
options?: RegulaOptions
|
|
99
|
+
): Promise<RegulaResult>;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Validate IaC files and return rule results.
|
|
103
|
+
* Alias for runRegula().
|
|
104
|
+
* @param paths - Path(s) to IaC files or directories
|
|
105
|
+
* @param options - Optional configuration
|
|
106
|
+
* @returns Object with rule_results and summary
|
|
107
|
+
*/
|
|
108
|
+
export function validate(
|
|
109
|
+
paths: string | string[],
|
|
110
|
+
options?: RegulaOptions
|
|
111
|
+
): Promise<RegulaResult>;
|
|
112
|
+
|
|
113
|
+
declare const _default: {
|
|
114
|
+
runRegula: typeof runRegula;
|
|
115
|
+
validate: typeof validate;
|
|
116
|
+
RegulaError: typeof RegulaError;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export default _default;
|
package/index.js
CHANGED
|
@@ -5,6 +5,20 @@ import { dirname, join } from "path";
|
|
|
5
5
|
const __filename = fileURLToPath(import.meta.url);
|
|
6
6
|
const __dirname = dirname(__filename);
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Custom error class for Regula execution errors
|
|
10
|
+
*/
|
|
11
|
+
export class RegulaError extends Error {
|
|
12
|
+
constructor(message, { stdout, stderr, exitCode, command }) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = "RegulaError";
|
|
15
|
+
this.stdout = stdout;
|
|
16
|
+
this.stderr = stderr;
|
|
17
|
+
this.exitCode = exitCode;
|
|
18
|
+
this.command = command;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
8
22
|
/**
|
|
9
23
|
* Run regula on the specified path(s) and return parsed JSON results.
|
|
10
24
|
* @param {string|string[]} paths - Path(s) to IaC files or directories
|
|
@@ -17,6 +31,7 @@ const __dirname = dirname(__filename);
|
|
|
17
31
|
* @param {boolean} options.noIgnore - Disable .gitignore filtering
|
|
18
32
|
* @param {string[]} options.varFiles - Terraform variable files to use
|
|
19
33
|
* @returns {Promise<Object>} - Parsed regula output with rule_results and summary
|
|
34
|
+
* @throws {RegulaError} - Throws RegulaError with stdout, stderr, exitCode, and command properties
|
|
20
35
|
*/
|
|
21
36
|
export async function runRegula(paths, options = {}) {
|
|
22
37
|
const pathArray = Array.isArray(paths) ? paths : [paths];
|
|
@@ -68,21 +83,38 @@ export async function runRegula(paths, options = {}) {
|
|
|
68
83
|
|
|
69
84
|
return new Promise((resolve, reject) => {
|
|
70
85
|
const cliPath = join(__dirname, "cli.js");
|
|
86
|
+
const command = `node ${cliPath} ${args.join(" ")}`;
|
|
71
87
|
|
|
72
88
|
execFile("node", [cliPath, ...args], { maxBuffer: 50 * 1024 * 1024 }, (error, stdout, stderr) => {
|
|
73
|
-
|
|
74
|
-
|
|
89
|
+
const exitCode = error?.code || 0;
|
|
90
|
+
|
|
91
|
+
// If there was an execution error (not just a non-zero exit), reject with details
|
|
92
|
+
if (error && error.code !== 1) {
|
|
93
|
+
// Exit code 1 is expected for security violations, so we don't treat it as an error
|
|
94
|
+
reject(
|
|
95
|
+
new RegulaError(`Regula execution failed: ${error.message}`, {
|
|
96
|
+
stdout,
|
|
97
|
+
stderr,
|
|
98
|
+
exitCode,
|
|
99
|
+
command,
|
|
100
|
+
})
|
|
101
|
+
);
|
|
102
|
+
return;
|
|
75
103
|
}
|
|
76
104
|
|
|
105
|
+
// Try to parse the output
|
|
77
106
|
try {
|
|
78
107
|
const result = JSON.parse(stdout);
|
|
79
108
|
resolve(result);
|
|
80
109
|
} catch (parseError) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
110
|
+
reject(
|
|
111
|
+
new RegulaError(`Failed to parse regula output: ${parseError.message}`, {
|
|
112
|
+
stdout,
|
|
113
|
+
stderr,
|
|
114
|
+
exitCode,
|
|
115
|
+
command,
|
|
116
|
+
})
|
|
117
|
+
);
|
|
86
118
|
}
|
|
87
119
|
});
|
|
88
120
|
});
|
|
@@ -94,9 +126,10 @@ export async function runRegula(paths, options = {}) {
|
|
|
94
126
|
* @param {string|string[]} paths - Path(s) to IaC files or directories
|
|
95
127
|
* @param {Object} options - Optional configuration
|
|
96
128
|
* @returns {Promise<Object>} - Object with rule_results and summary
|
|
129
|
+
* @throws {RegulaError} - Throws RegulaError with stdout, stderr, exitCode, and command properties
|
|
97
130
|
*/
|
|
98
131
|
export async function validate(paths, options = {}) {
|
|
99
132
|
return runRegula(paths, options);
|
|
100
133
|
}
|
|
101
134
|
|
|
102
|
-
export default { runRegula, validate };
|
|
135
|
+
export default { runRegula, validate, RegulaError };
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "regula-wasi",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.5",
|
|
4
4
|
"description": "Infrastructure as Code security and compliance evaluation tool (WASI build). Fork of fugue/regula with security patches.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
7
|
+
"types": "index.d.ts",
|
|
7
8
|
"bin": {
|
|
8
9
|
"regula": "cli.js"
|
|
9
10
|
},
|
|
@@ -15,6 +16,7 @@
|
|
|
15
16
|
},
|
|
16
17
|
"files": [
|
|
17
18
|
"index.js",
|
|
19
|
+
"index.d.ts",
|
|
18
20
|
"cli.js",
|
|
19
21
|
"regula.wasm",
|
|
20
22
|
"README.md",
|
package/regula.wasm
CHANGED
|
Binary file
|