()
| 78 | |
| 79 | |
| 80 | def export_all(): |
| 81 | requirements = [] |
| 82 | |
| 83 | # | APTS-SC-001 | Impact Classification and CIA Scoring | MUST \| Tier 1 | |
| 84 | # or with extra columns: | APTS-AL-001 | Single Technique Execution | MUST \| Tier 1 | L1 | |
| 85 | pattern = re.compile(r'^\|\s*(APTS-[A-Z]+-\d+)\s*\|\s*(.*?)\s*\|\s*(MUST|SHOULD)\s*\\?\|\s*Tier\s*(\d+)\s*\|.*$') |
| 86 | |
| 87 | for dir_name, domain_name in get_domain_dirs().items(): |
| 88 | readme_path = os.path.join(STANDARD_DIR, dir_name, "README.md") |
| 89 | if not os.path.exists(readme_path): |
| 90 | print(f"Warning: {readme_path} not found.") |
| 91 | continue |
| 92 | |
| 93 | with open(readme_path, "r", encoding="utf-8") as f: |
| 94 | content = f.read() |
| 95 | |
| 96 | lines = content.split('\n') |
| 97 | for line in lines: |
| 98 | line = line.strip() |
| 99 | match = pattern.match(line) |
| 100 | if match: |
| 101 | req_id, title, classification, tier = match.groups() |
| 102 | requirements.append({ |
| 103 | "id": req_id, |
| 104 | "domain": domain_name, |
| 105 | "tier": int(tier), |
| 106 | "classification": classification, |
| 107 | "title": title |
| 108 | }) |
| 109 | |
| 110 | output_data = { |
| 111 | "version": SCHEMA_VERSION, |
| 112 | "source": SOURCE, |
| 113 | "last_updated": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"), |
| 114 | "requirements": requirements |
| 115 | } |
| 116 | |
| 117 | # Export requirements JSON |
| 118 | with open(OUTPUT_JSON, "w", encoding="utf-8") as f: |
| 119 | json.dump(output_data, f, indent=2) |
| 120 | |
| 121 | print(f"Successfully generated {OUTPUT_JSON} with {len(requirements)} requirements.") |
| 122 | |
| 123 | # Update schema domain enum dynamically |
| 124 | SCHEMA["properties"]["requirements"]["items"]["properties"]["domain"]["enum"] = list(get_domain_dirs().values()) |
| 125 | |
| 126 | # Export schema JSON |
| 127 | with open(OUTPUT_SCHEMA, "w", encoding="utf-8") as f: |
| 128 | json.dump(SCHEMA, f, indent=2) |
| 129 | |
| 130 | print(f"Successfully generated {OUTPUT_SCHEMA}.") |
| 131 | |
| 132 | if __name__ == "__main__": |
| 133 | export_all() |
no test coverage detected