MCPcopy Create free account
hub / github.com/ShipSecAI/studio / parseRawOutput

Function parseRawOutput

worker/src/components/security/trufflehog.ts:259–308  ·  view source on GitHub ↗
(rawOutput: string)

Source from the content-addressed store, hash-verified

257
258// Helper function to parse raw TruffleHog JSON output
259function parseRawOutput(rawOutput: string): Output {
260 if (!rawOutput || rawOutput.trim().length === 0) {
261 return {
262 secrets: [],
263 rawOutput: '',
264 secretCount: 0,
265 verifiedCount: 0,
266 hasVerifiedSecrets: false,
267 results: [],
268 };
269 }
270
271 // Try to parse as a single JSON object first (for test mocks)
272 try {
273 const parsed = JSON.parse(rawOutput);
274 // If it has the expected output structure, return it
275 if ('secrets' in parsed && 'secretCount' in parsed) {
276 return outputSchema.parse(parsed);
277 }
278 } catch {
279 // Not a single JSON object, continue to NDJSON parsing
280 }
281
282 // TruffleHog outputs one JSON object per line for each secret found (NDJSON format)
283 const lines = rawOutput.split('\n').filter((line) => line.trim().length > 0);
284 const secrets: Secret[] = [];
285 let verifiedCount = 0;
286
287 for (const line of lines) {
288 try {
289 const secret = JSON.parse(line);
290 secrets.push(secret);
291 if (secret.Verified === true) {
292 verifiedCount++;
293 }
294 } catch (_error) {
295 // Skip non-JSON lines (like status messages)
296 continue;
297 }
298 }
299
300 return {
301 secrets,
302 rawOutput,
303 secretCount: secrets.length,
304 verifiedCount,
305 hasVerifiedSecrets: verifiedCount > 0,
306 results: [], // Populated in execute() with scanner metadata
307 };
308}
309
310const definition = defineComponent({
311 id: 'shipsec.trufflehog.scan',

Callers 1

executeFunction · 0.85

Calls 2

parseMethod · 0.80
pushMethod · 0.65

Tested by

no test coverage detected