|
| 1 | +import json |
| 2 | +import os |
| 3 | +import sys |
| 4 | + |
| 5 | +def generate_readme(json_file_path, output_file_path): |
| 6 | + try: |
| 7 | + # Read the JSON file |
| 8 | + with open(json_file_path, 'r') as json_file: |
| 9 | + data = json.load(json_file) |
| 10 | + |
| 11 | + # Extract results |
| 12 | + results = data.get("results", []) |
| 13 | + # Generate markdown content |
| 14 | + markdown_content = f""" |
| 15 | +### tfsec Scan Report: |
| 16 | +# Detected Vulnerabilities by tfsec |
| 17 | +
|
| 18 | +""" |
| 19 | + for result in results: |
| 20 | + markdown_content += f"## Issue: {result.get('description', 'No description')}\n\n" |
| 21 | + markdown_content += f"### Impact\n{result.get('impact', 'No impact information')}\n\n" |
| 22 | + markdown_content += "### Links\n" |
| 23 | + for link in result.get('links', []): |
| 24 | + markdown_content += f"- [{link}]({link})\n" |
| 25 | + markdown_content += "\n" |
| 26 | + markdown_content += "### Location\n" |
| 27 | + location = result.get('location', {}) |
| 28 | + markdown_content += f"- **File:** {location.get('filename', 'Unknown file')}\n" |
| 29 | + markdown_content += f"- **Start Line:** {location.get('start_line', 'Unknown start line')}\n" |
| 30 | + markdown_content += f"- **End Line:** {location.get('end_line', 'Unknown end line')}\n\n" |
| 31 | + markdown_content += "### Details\n" |
| 32 | + markdown_content += f"- **Long ID:** `{result.get('long_id', 'Unknown long ID')}`\n" |
| 33 | + markdown_content += f"- **Resolution:** {result.get('resolution', 'No resolution provided')}\n" |
| 34 | + markdown_content += f"- **Resource:** `{result.get('resource', 'Unknown resource')}`\n" |
| 35 | + markdown_content += f"- **Rule Description:** {result.get('rule_description', 'No rule description')}\n" |
| 36 | + markdown_content += f"- **Rule ID:** `{result.get('rule_id', 'Unknown rule ID')}`\n" |
| 37 | + markdown_content += f"- **Rule Provider:** `{result.get('rule_provider', 'Unknown rule provider')}`\n" |
| 38 | + markdown_content += f"- **Rule Service:** `{result.get('rule_service', 'Unknown rule service')}`\n" |
| 39 | + markdown_content += f"- **Severity:** `{result.get('severity', 'Unknown severity')}`\n" |
| 40 | + markdown_content += f"- **Status:** `{result.get('status', 'Unknown status')}`\n" |
| 41 | + markdown_content += f"- **Warning:** `{result.get('warning', 'Unknown warning')}`\n\n" |
| 42 | + |
| 43 | + # Write to the README file |
| 44 | + with open(output_file_path, 'w') as output_file: |
| 45 | + output_file.write(markdown_content) |
| 46 | + |
| 47 | + print(f"README file generated successfully at {output_file_path}") |
| 48 | + |
| 49 | + except Exception as e: |
| 50 | + print(f"An error occurred: {e}") |
| 51 | + |
| 52 | +if __name__ == "__main__": |
| 53 | + if len(sys.argv) != 2: |
| 54 | + print("Usage: python tfsec_json_to_markdown_helper.py <input_file>") |
| 55 | + sys.exit(1) |
| 56 | + # Define paths |
| 57 | + json_file_path = sys.argv[1] |
| 58 | + output_file_path = "tfsec.md" # Adjust path as needed |
| 59 | + |
| 60 | + # Generate README |
| 61 | + generate_readme(json_file_path, output_file_path) |
0 commit comments