Parse the contents of lynis-report.dat into structured data.
(content: str)
| 48 | |
| 49 | |
| 50 | def parse_lynis_dat(content: str) -> Dict[str, object]: |
| 51 | """Parse the contents of lynis-report.dat into structured data.""" |
| 52 | data = { |
| 53 | "metadata": {}, |
| 54 | "warnings": [], |
| 55 | "suggestions": [], |
| 56 | "vulnerable_packages": [], |
| 57 | } |
| 58 | |
| 59 | if not content: |
| 60 | return data |
| 61 | |
| 62 | for line in content.splitlines(): |
| 63 | stripped = line.strip() |
| 64 | if not stripped or stripped.startswith("#"): |
| 65 | continue |
| 66 | if "=" not in stripped: |
| 67 | continue |
| 68 | |
| 69 | key, value = stripped.split("=", 1) |
| 70 | key = key.strip() |
| 71 | value = value.strip() |
| 72 | |
| 73 | base_key = key.split("[", 1)[0] |
| 74 | if base_key == "warning": |
| 75 | data["warnings"].append(_split_pipe_payload(value)) |
| 76 | elif base_key == "suggestion": |
| 77 | data["suggestions"].append(_split_pipe_payload(value)) |
| 78 | elif base_key == "vulnerable_package": |
| 79 | data["vulnerable_packages"].append(_parse_vulnerable_package(value)) |
| 80 | else: |
| 81 | data["metadata"][base_key] = value |
| 82 | |
| 83 | return data |