gesf-vscode 1.1.2 → 1.1.4
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/package.json +6 -1
- package/build.js +0 -13
- package/src/extension.ts +0 -264
- package/tsconfig.json +0 -15
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "gesf-vscode",
|
|
3
3
|
"displayName": "GESF - Green Engineering Standard Framework",
|
|
4
4
|
"description": "Real-time GDPR, security, and compliance warnings for your project",
|
|
5
|
-
"version": "1.1.
|
|
5
|
+
"version": "1.1.4",
|
|
6
6
|
"publisher": "greenarmor",
|
|
7
7
|
"engines": {
|
|
8
8
|
"vscode": "^1.80.0"
|
|
@@ -44,6 +44,11 @@
|
|
|
44
44
|
"typescript": "^6.0.0"
|
|
45
45
|
},
|
|
46
46
|
"license": "MIT",
|
|
47
|
+
"files": [
|
|
48
|
+
"dist",
|
|
49
|
+
"LICENSE",
|
|
50
|
+
"README.md"
|
|
51
|
+
],
|
|
47
52
|
"scripts": {
|
|
48
53
|
"build": "node build.js",
|
|
49
54
|
"test": "echo \"no tests yet\""
|
package/build.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const esbuild = require("esbuild");
|
|
2
|
-
|
|
3
|
-
esbuild.build({
|
|
4
|
-
entryPoints: ["src/extension.ts"],
|
|
5
|
-
bundle: true,
|
|
6
|
-
outfile: "dist/extension.js",
|
|
7
|
-
external: ["vscode"],
|
|
8
|
-
format: "cjs",
|
|
9
|
-
platform: "node",
|
|
10
|
-
target: "node18",
|
|
11
|
-
sourcemap: false,
|
|
12
|
-
minify: false,
|
|
13
|
-
}).catch(() => process.exit(1));
|
package/src/extension.ts
DELETED
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
import * as vscode from "vscode";
|
|
2
|
-
import * as fs from "node:fs";
|
|
3
|
-
import * as path from "node:path";
|
|
4
|
-
|
|
5
|
-
let diagnosticCollection: vscode.DiagnosticCollection;
|
|
6
|
-
let statusBarItem: vscode.StatusBarItem;
|
|
7
|
-
|
|
8
|
-
export function activate(context: vscode.ExtensionContext) {
|
|
9
|
-
diagnosticCollection = vscode.languages.createDiagnosticCollection("gesf");
|
|
10
|
-
context.subscriptions.push(diagnosticCollection);
|
|
11
|
-
|
|
12
|
-
statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 50);
|
|
13
|
-
statusBarItem.command = "gesf.showScore";
|
|
14
|
-
context.subscriptions.push(statusBarItem);
|
|
15
|
-
|
|
16
|
-
context.subscriptions.push(
|
|
17
|
-
vscode.commands.registerCommand("gesf.runAudit", runAudit),
|
|
18
|
-
);
|
|
19
|
-
context.subscriptions.push(
|
|
20
|
-
vscode.commands.registerCommand("gesf.showScore", showScore),
|
|
21
|
-
);
|
|
22
|
-
context.subscriptions.push(
|
|
23
|
-
vscode.commands.registerCommand("gesf.generateReport", generateReport),
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
context.subscriptions.push(
|
|
27
|
-
vscode.workspace.onDidSaveTextDocument(() => checkProject()),
|
|
28
|
-
);
|
|
29
|
-
context.subscriptions.push(
|
|
30
|
-
vscode.window.onDidChangeActiveTextEditor(() => checkProject()),
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
checkProject();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function getProjectRoot(): string | undefined {
|
|
37
|
-
const folders = vscode.workspace.workspaceFolders;
|
|
38
|
-
if (!folders || folders.length === 0) return undefined;
|
|
39
|
-
const root = folders[0].uri.fsPath;
|
|
40
|
-
if (fs.existsSync(path.join(root, ".ges", "config.json"))) return root;
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function checkProject() {
|
|
45
|
-
const root = getProjectRoot();
|
|
46
|
-
if (!root) {
|
|
47
|
-
statusBarItem.hide();
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const warnings = detectComplianceWarnings(root);
|
|
52
|
-
const diagnostics: vscode.Diagnostic[] = [];
|
|
53
|
-
|
|
54
|
-
for (const warning of warnings) {
|
|
55
|
-
const uri = vscode.Uri.file(path.join(root, warning.file));
|
|
56
|
-
const line = warning.line || 0;
|
|
57
|
-
const range = new vscode.Range(line, 0, line, 100);
|
|
58
|
-
const severity =
|
|
59
|
-
warning.severity === "critical"
|
|
60
|
-
? vscode.DiagnosticSeverity.Error
|
|
61
|
-
: warning.severity === "high"
|
|
62
|
-
? vscode.DiagnosticSeverity.Warning
|
|
63
|
-
: vscode.DiagnosticSeverity.Information;
|
|
64
|
-
const diag = new vscode.Diagnostic(range, `[GESF] ${warning.message}`, severity);
|
|
65
|
-
diag.source = "gesf";
|
|
66
|
-
diagnostics.push(diag);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
diagnosticCollection.clear();
|
|
70
|
-
for (const warning of warnings) {
|
|
71
|
-
const uri = vscode.Uri.file(path.join(root, warning.file));
|
|
72
|
-
const fileDiags = diagnostics.filter((_, i) => warnings[i].file === warning.file);
|
|
73
|
-
diagnosticCollection.set(uri, fileDiags);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
updateStatusBar(root);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
interface ComplianceWarning {
|
|
80
|
-
file: string;
|
|
81
|
-
line?: number;
|
|
82
|
-
severity: string;
|
|
83
|
-
message: string;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function detectComplianceWarnings(root: string): ComplianceWarning[] {
|
|
87
|
-
const warnings: ComplianceWarning[] = [];
|
|
88
|
-
const configPath = path.join(root, ".ges", "config.json");
|
|
89
|
-
|
|
90
|
-
if (!fs.existsSync(configPath)) {
|
|
91
|
-
warnings.push({
|
|
92
|
-
file: "package.json",
|
|
93
|
-
severity: "high",
|
|
94
|
-
message: "GESF not initialized. Run 'ges init' to set up compliance controls.",
|
|
95
|
-
});
|
|
96
|
-
return warnings;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
let config: Record<string, unknown>;
|
|
100
|
-
try {
|
|
101
|
-
config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
102
|
-
} catch {
|
|
103
|
-
return warnings;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const pkgPath = path.join(root, "package.json");
|
|
107
|
-
if (fs.existsSync(pkgPath)) {
|
|
108
|
-
try {
|
|
109
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
110
|
-
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
111
|
-
|
|
112
|
-
if (deps.express && !deps.helmet) {
|
|
113
|
-
warnings.push({
|
|
114
|
-
file: "package.json",
|
|
115
|
-
severity: "high",
|
|
116
|
-
message: "Missing security headers. Install 'helmet' middleware.",
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (deps.express && !deps.cors) {
|
|
121
|
-
warnings.push({
|
|
122
|
-
file: "package.json",
|
|
123
|
-
severity: "medium",
|
|
124
|
-
message: "No CORS configuration detected. Install 'cors' package.",
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
} catch {}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (!fs.existsSync(path.join(root, ".gitignore"))) {
|
|
131
|
-
warnings.push({
|
|
132
|
-
file: ".gitignore",
|
|
133
|
-
severity: "high",
|
|
134
|
-
message: "No .gitignore file. Secrets may be committed accidentally.",
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const gitignorePath = path.join(root, ".gitignore");
|
|
139
|
-
if (fs.existsSync(gitignorePath)) {
|
|
140
|
-
const gitignore = fs.readFileSync(gitignorePath, "utf-8");
|
|
141
|
-
if (!gitignore.includes(".env")) {
|
|
142
|
-
warnings.push({
|
|
143
|
-
file: ".gitignore",
|
|
144
|
-
severity: "critical",
|
|
145
|
-
message: ".env not in .gitignore. Environment secrets may be committed.",
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const requirements = config.requirements as Record<string, { required: boolean }> | undefined;
|
|
151
|
-
if (requirements?.mfa?.required) {
|
|
152
|
-
const hasMFA = checkForMFA(root);
|
|
153
|
-
if (!hasMFA) {
|
|
154
|
-
warnings.push({
|
|
155
|
-
file: "package.json",
|
|
156
|
-
severity: "high",
|
|
157
|
-
message: "MFA is required by GESF config but no MFA implementation detected.",
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (requirements?.encryption?.required) {
|
|
163
|
-
const hasEncryption = checkForEncryption(root);
|
|
164
|
-
if (!hasEncryption) {
|
|
165
|
-
warnings.push({
|
|
166
|
-
file: "package.json",
|
|
167
|
-
severity: "critical",
|
|
168
|
-
message: "Encryption is required by GESF config but no encryption detected.",
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (requirements?.retention_policy?.required) {
|
|
174
|
-
if (!fs.existsSync(path.join(root, "compliance", "retention-policy.md"))) {
|
|
175
|
-
warnings.push({
|
|
176
|
-
file: "compliance/retention-policy.md",
|
|
177
|
-
severity: "medium",
|
|
178
|
-
message: "Retention policy document missing. Run 'ges generate --docs'.",
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return warnings;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function checkForMFA(root: string): boolean {
|
|
187
|
-
const pkgPath = path.join(root, "package.json");
|
|
188
|
-
if (fs.existsSync(pkgPath)) {
|
|
189
|
-
try {
|
|
190
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
191
|
-
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
192
|
-
const mfaLibs = ["otpauth", "speakeasy", "otplib", "@simplewebauthn", "node-2fa"];
|
|
193
|
-
return mfaLibs.some((lib) => deps[lib] !== undefined);
|
|
194
|
-
} catch {}
|
|
195
|
-
}
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
function checkForEncryption(root: string): boolean {
|
|
200
|
-
const dirs = ["src", "lib", "crypto", "security"];
|
|
201
|
-
const patterns = [/aes-256/i, /AES_256_GCM/i, /createCipheriv/i, /ChaCha20/i, /crypto\.encrypt/i];
|
|
202
|
-
|
|
203
|
-
for (const dir of dirs) {
|
|
204
|
-
const dirPath = path.join(root, dir);
|
|
205
|
-
if (!fs.existsSync(dirPath)) continue;
|
|
206
|
-
try {
|
|
207
|
-
const entries = fs.readdirSync(dirPath, { recursive: true });
|
|
208
|
-
for (const entry of entries) {
|
|
209
|
-
const filePath = path.join(dirPath, entry.toString());
|
|
210
|
-
if (!fs.statSync(filePath).isFile()) continue;
|
|
211
|
-
const ext = path.extname(filePath);
|
|
212
|
-
if (![".ts", ".js"].includes(ext)) continue;
|
|
213
|
-
const content = fs.readFileSync(filePath, "utf-8");
|
|
214
|
-
if (patterns.some((p) => p.test(content))) return true;
|
|
215
|
-
}
|
|
216
|
-
} catch {}
|
|
217
|
-
}
|
|
218
|
-
return false;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
function updateStatusBar(root: string) {
|
|
222
|
-
const scorePath = path.join(root, ".ges", "score.json");
|
|
223
|
-
if (fs.existsSync(scorePath)) {
|
|
224
|
-
try {
|
|
225
|
-
const score = JSON.parse(fs.readFileSync(scorePath, "utf-8"));
|
|
226
|
-
const overall = score.overall || 0;
|
|
227
|
-
const grade = score.overall_grade || "?";
|
|
228
|
-
const icon = overall >= 80 ? "$(checkmark)" : overall >= 50 ? "$(warning)" : "$(error)";
|
|
229
|
-
statusBarItem.text = `${icon} GESF: ${overall}% (${grade})`;
|
|
230
|
-
} catch {
|
|
231
|
-
statusBarItem.text = "$(question) GESF: No score";
|
|
232
|
-
}
|
|
233
|
-
} else {
|
|
234
|
-
statusBarItem.text = "$(warning) GESF: Run audit";
|
|
235
|
-
}
|
|
236
|
-
statusBarItem.show();
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
async function runAudit() {
|
|
240
|
-
const terminal = vscode.window.createTerminal("GESF Audit");
|
|
241
|
-
terminal.show();
|
|
242
|
-
terminal.sendText("ges audit");
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
async function showScore() {
|
|
246
|
-
const terminal = vscode.window.createTerminal("GESF Score");
|
|
247
|
-
terminal.show();
|
|
248
|
-
terminal.sendText("ges score");
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
async function generateReport() {
|
|
252
|
-
const format = await vscode.window.showQuickPick(["markdown", "html", "pdf"], {
|
|
253
|
-
placeHolder: "Select report format",
|
|
254
|
-
});
|
|
255
|
-
if (!format) return;
|
|
256
|
-
const terminal = vscode.window.createTerminal("GESF Report");
|
|
257
|
-
terminal.show();
|
|
258
|
-
terminal.sendText(`ges report --format ${format}`);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
export function deactivate() {
|
|
262
|
-
diagnosticCollection?.clear();
|
|
263
|
-
statusBarItem?.hide();
|
|
264
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "Node16",
|
|
5
|
-
"moduleResolution": "Node16",
|
|
6
|
-
"lib": ["ES2022"],
|
|
7
|
-
"types": ["vscode", "node"],
|
|
8
|
-
"strict": true,
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"skipLibCheck": true,
|
|
11
|
-
"outDir": "./dist",
|
|
12
|
-
"rootDir": "./src"
|
|
13
|
-
},
|
|
14
|
-
"include": ["src/**/*"]
|
|
15
|
-
}
|