Skip to content

Commit d9890b2

Browse files
authored
Merge pull request #96 from GitGuardian/kashyapajayasekera/scrt-5903-add-secret-path-and-vault-instance-information-to-vs-code
feat: show vault information in results
2 parents 58fb5d1 + 2179972 commit d9890b2

File tree

5 files changed

+94
-6
lines changed

5 files changed

+94
-6
lines changed

src/lib/api-types.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,25 @@ export type Validity =
1616
| "invalid"
1717
| "valid";
1818

19-
export interface Incident {
19+
type IncidentVaultProperties = {
20+
secret_vaulted: false;
21+
} | {
22+
secret_vaulted: true;
23+
vault_type: string;
24+
vault_name: string;
25+
vault_path: string;
26+
vault_path_count: number;
27+
}
28+
29+
export type Incident = {
2030
type: string;
2131
occurrences: Occurrence[];
2232
validity: Validity;
2333
ignore_sha: string;
2434
known_secret: boolean;
2535
incident_url: string;
2636
total_occurrences: number;
27-
secret_vaulted: boolean;
28-
}
37+
} & IncidentVaultProperties
2938

3039
export interface EntityWithIncidents {
3140
incidents: Incident[];

src/lib/ggshield-results-parser.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
Occurrence,
1414
Validity,
1515
} from "./api-types";
16+
import { pluralize } from "../utils";
1617

1718
const validityDisplayName: Record<Validity, string> = {
1819
unknown: "Unknown",
@@ -45,6 +46,7 @@ function filterUriOccurrences(occurrences: Occurrence[]): Occurrence[] {
4546
* @param results ggshield scan results
4647
* @returns incidents diagnostics
4748
*/
49+
4850
export function parseGGShieldResults(
4951
results: GGShieldScanResults,
5052
): Diagnostic[] {
@@ -63,6 +65,22 @@ export function parseGGShieldResults(
6365
new Position(occurrence.line_start - 1, occurrence.index_start),
6466
new Position(occurrence.line_end - 1, occurrence.index_end),
6567
);
68+
69+
let vaultInfo = "";
70+
71+
if (incident.secret_vaulted) {
72+
if (incident.vault_path_count !== null) {
73+
vaultInfo += `Secret found in vault: YES (${incident.vault_path_count} ${pluralize(incident.vault_path_count, "location")})
74+
├─ Vault Type: ${incident.vault_type}
75+
├─ Vault Name: ${incident.vault_name}
76+
└─ Secret Path: ${incident.vault_path}`;
77+
} else {
78+
vaultInfo += "Secret found in vault: YES";
79+
}
80+
} else {
81+
vaultInfo += "Secret found in vault: NO";
82+
}
83+
6684
let diagnostic = new Diagnostic(
6785
range,
6886
`ggshield: ${occurrence.type}
@@ -73,11 +91,11 @@ Known by GitGuardian dashboard: ${incident.known_secret ? "YES" : "NO"}
7391
Total occurrences: ${incident.total_occurrences}
7492
Incident URL: ${incident.incident_url || "N/A"}
7593
Secret SHA: ${incident.ignore_sha}
76-
Secret in Secrets Manager: ${incident.secret_vaulted ? "YES" : "NO"}`,
94+
${vaultInfo}`,
7795
DiagnosticSeverity.Warning,
7896
);
7997

80-
diagnostic.source = "gitguardian";
98+
diagnostic.source = "\ngitguardian";
8199
diagnostics.push(diagnostic);
82100
},
83101
);

src/test/constants.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,48 @@ export const scanResultsWithUriIncident = `{
8585
"total_occurrences": 1,
8686
"secrets_engine_version": "2.126.0"
8787
}`;
88+
89+
export const scanResultsVaulted = `{
90+
"id":"test.py",
91+
"type":"path_scan",
92+
"entities_with_incidents":[
93+
{
94+
"mode":"FILE",
95+
"filename":"test.py",
96+
"incidents":[
97+
{
98+
"policy":"Secrets detection",
99+
"occurrences":[
100+
{
101+
"match":"DDACC73DdB04********************************************057c78317C39",
102+
"type":"apikey",
103+
"line_start":4,
104+
"line_end":4,
105+
"index_start":11,
106+
"index_end":79,
107+
"pre_line_start":4,
108+
"pre_line_end":4
109+
}
110+
],
111+
"type":"Generic High Entropy Secret",
112+
"validity":"no_checker",
113+
"ignore_sha":"38353eb1a2aac5b24f39ed67912234d4b4a2e23976d504a88b28137ed2b9185e",
114+
"total_occurrences":2,
115+
"incident_url":"",
116+
"known_secret":false,
117+
"secret_vaulted": true,
118+
"vault_type": "AWS Secrets Manager",
119+
"vault_name": "463175827647/us-west-2",
120+
"vault_path": "arn:aws:secretsmanager:us-west-2:463175827647:secret:xav-test-svef2q:pwd",
121+
"vault_path_count": 2
122+
123+
}
124+
],
125+
"total_incidents":1,
126+
"total_occurrences":1
127+
}
128+
],
129+
"total_incidents":1,
130+
"total_occurrences":1,
131+
"secrets_engine_version":"2.96.0"
132+
}`;

src/test/suite/results-parser.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { parseGGShieldResults } from "../../lib/ggshield-results-parser";
44
import { DiagnosticSeverity } from "vscode";
55
import {
66
scanResultsNoIncident,
7+
scanResultsVaulted,
78
scanResultsWithIncident,
89
scanResultsWithUriIncident,
910
} from "../constants";
@@ -17,14 +18,25 @@ suite("parseGGShieldResults", () => {
1718
const diagnostic = diagnostics[0];
1819
assert.ok(diagnostic.message.includes("apikey"));
1920
assert.ok(diagnostic.message.includes("Generic High Entropy Secret"));
20-
assert.ok(diagnostic.message.includes("Secret in Secrets Manager: NO"));
21+
assert.ok(diagnostic.message.includes("Secret found in vault: NO"));
2122
assert.strictEqual(diagnostic.range.start.line, 3);
2223
assert.strictEqual(diagnostic.range.start.character, 11);
2324
assert.strictEqual(diagnostic.range.end.line, 3);
2425
assert.strictEqual(diagnostic.range.end.character, 79);
2526
assert.strictEqual(diagnostic.severity, DiagnosticSeverity.Warning);
2627
});
2728

29+
test("Should parse vault information", () => {
30+
const diagnostics = parseGGShieldResults(
31+
JSON.parse(scanResultsVaulted),
32+
);
33+
const diagnostic = diagnostics[0];
34+
assert.ok(diagnostic.message.includes("Secret found in vault: YES"));
35+
assert.ok(diagnostic.message.includes("├─ Vault Type: AWS Secrets Manager"));
36+
assert.ok(diagnostic.message.includes("├─ Vault Name: 463175827647/us-west-2"));
37+
assert.ok(diagnostic.message.includes("└─ Secret Path: arn:aws:secretsmanager:us-west-2:463175827647:secret:xav-test-svef2q:pwd"));
38+
});
39+
2840
test("Should return an empty array if there are no incidents", () => {
2941
const diagnostics = parseGGShieldResults(JSON.parse(scanResultsNoIncident));
3042
assert.strictEqual(diagnostics.length, 0);

src/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ export function getCurrentFile(): string {
2929
return "";
3030
}
3131
}
32+
33+
export function pluralize(num: number, word: string): string {
34+
return `${[1, -1].includes(num) ? word : word + "s"}`
35+
}

0 commit comments

Comments
 (0)