|
2 | 2 | import json
|
3 | 3 | import logging
|
4 | 4 | from io import StringIO
|
5 |
| -from json.decoder import JSONDecodeError |
6 | 5 |
|
7 | 6 | from dojo.models import Finding
|
8 | 7 |
|
@@ -44,27 +43,20 @@ def get_findings(self, file, test):
|
44 | 43 | csv_data = self._parse_csv(content)
|
45 | 44 | findings = self._parse_csv_findings(csv_data, test, file_name=file_name)
|
46 | 45 | else:
|
47 |
| - # Try to detect format from content if extension not recognized |
48 |
| - try: |
49 |
| - data = self._parse_json(content) |
50 |
| - findings = self._parse_json_findings(data, test, file_name=file_name) |
51 |
| - except (JSONDecodeError, ValueError): |
52 |
| - csv_data = self._parse_csv(content) |
53 |
| - findings = self._parse_csv_findings(csv_data, test, file_name=file_name) |
| 46 | + # If file type can't be determined from extension, throw an error |
| 47 | + error_message = f"Unsupported file format. Prowler parser only supports JSON and CSV files. File name: {file_name}" |
| 48 | + raise ValueError(error_message) |
54 | 49 |
|
55 | 50 | return findings
|
56 | 51 |
|
57 | 52 | def _parse_json(self, content):
|
58 | 53 | """Safely parse JSON content"""
|
59 |
| - if isinstance(content, bytes): |
60 |
| - content = content.decode("utf-8") |
| 54 | + # Content is already decoded in get_findings method |
61 | 55 | return json.loads(content)
|
62 | 56 |
|
63 | 57 | def _parse_csv(self, content):
|
64 | 58 | """Parse CSV content"""
|
65 |
| - if isinstance(content, bytes): |
66 |
| - content = content.decode("utf-8") |
67 |
| - |
| 59 | + # Content is already decoded in get_findings method |
68 | 60 | f = StringIO(content)
|
69 | 61 | csv_reader = csv.DictReader(f, delimiter=";")
|
70 | 62 | results = list(csv_reader)
|
@@ -107,6 +99,7 @@ def _parse_json_findings(self, data, test, *, file_name=""):
|
107 | 99 | for item in data:
|
108 | 100 | # Skip items without required fields
|
109 | 101 | if not isinstance(item, dict) or "message" not in item:
|
| 102 | + logger.debug(f"Skipping Prowler finding because it's not a dict or missing 'message' field: {item}") |
110 | 103 | continue
|
111 | 104 |
|
112 | 105 | # Get basic information
|
|
0 commit comments