|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 |
|
3 | | -import json |
4 | | -from datetime import datetime |
| 3 | +from json import dump as json_dump, load as json_load |
| 4 | +from datetime import datetime, timezone |
5 | 5 | from pathlib import Path |
6 | | -from typing import Dict, List, Any |
| 6 | +from typing import Any, Dict, List |
7 | 7 |
|
8 | | -# Step 1: Load JSON data safely using context managers |
9 | | -SCHEMA_DIR = Path(__file__).parent.parent / "../../../schema" |
| 8 | +# config |
| 9 | +SCHEMA_DIR = Path(__file__).parent.parent.parent.parent.parent / "schema" |
10 | 10 | DEFS_FILE = SCHEMA_DIR / "cryptography-defs.json" |
11 | 11 | SCHEMA_FILE = SCHEMA_DIR / "cryptography-defs.schema.json" |
12 | 12 |
|
| 13 | +# Step 1: Load JSON data safely using context managers |
13 | 14 | with DEFS_FILE.open("r", encoding="utf-8") as defs_file: |
14 | | - defs_data: Dict[str, List[Dict[str, Any]]] = json.load(defs_file) |
| 15 | + defs_data: Dict[str, List[Dict[str, Any]]] = json_load(defs_file) |
15 | 16 |
|
16 | 17 | with SCHEMA_FILE.open("r", encoding="utf-8") as schema_file: |
17 | | - schema_data: Dict[str, Any] = json.load(schema_file) |
| 18 | + schema_data: Dict[str, Any] = json_load(schema_file) |
18 | 19 |
|
19 | 20 | # Step 2: Extract unique algorithm families and sort them |
20 | 21 | families: List[str] = sorted({algo['family'] for algo in defs_data.get('algorithms', [])}) |
|
25 | 26 | except KeyError as e: |
26 | 27 | raise KeyError(f"Required schema property 'properties' missing: {e}") |
27 | 28 |
|
28 | | -schema_data['$comment'] = datetime.now().isoformat() |
| 29 | +schema_data['$comment'] = datetime.now(timezone.utc).replace(microsecond=0) \ |
| 30 | + .isoformat().replace('+00:00', 'Z') |
29 | 31 |
|
30 | 32 | schema_data['definitions']['algorithmFamiliesEnum'] = { |
31 | 33 | "type": "string", |
|
36 | 38 |
|
37 | 39 | # Step 4: Write the updated schema back to the file |
38 | 40 | with SCHEMA_FILE.open("w", encoding="utf-8") as update_file: |
39 | | - json.dump(schema_data, update_file, indent=2, ensure_ascii=False) |
| 41 | + json_dump(schema_data, update_file, indent=2, ensure_ascii=False) |
40 | 42 |
|
41 | 43 | print("Schema updated successfully.") |
0 commit comments