Skip to content

Commit 7aa329e

Browse files
committed
chore: make csv2xlsx CI-safe when risk_matrix.csv is gitignored
1 parent 9a8b2f4 commit 7aa329e

1 file changed

Lines changed: 47 additions & 6 deletions

File tree

tools/csv2xlsx.py

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,59 @@
2121
}
2222

2323
def load_csv(csv_path: Path) -> pd.DataFrame:
24-
"""Loads the risk matrix from CSV."""
24+
"""
25+
Loads the risk matrix from CSV.
26+
27+
- En local : lit 02-Matrices/risk_matrix.csv
28+
- En CI (GitHub Actions) : si le fichier est absent (gitignore), génère un dataset de démo
29+
"""
30+
# Cas 1 : fichier absent (runner CI ou repo public sans CSV réel)
31+
if not csv_path.exists():
32+
print(f"Warning: {csv_path} not found. Using demo dataset (CI mode).")
33+
34+
demo_data = [
35+
{
36+
"ID": "R001",
37+
"Asset": "Demo infusion pump",
38+
"Threat": "Ransomware",
39+
"Vulnerability": "Unpatched OS",
40+
"Probability": 4,
41+
"Impact": 5,
42+
"Risk": 20,
43+
"Decision": "Reduce",
44+
"Recommendation": "Patch management + network segmentation"
45+
},
46+
{
47+
"ID": "R002",
48+
"Asset": "Demo patient monitor",
49+
"Threat": "Unauthorized access",
50+
"Vulnerability": "Weak credentials",
51+
"Probability": 3,
52+
"Impact": 4,
53+
"Risk": 12,
54+
"Decision": "Reduce",
55+
"Recommendation": "Strong auth + MFA where possible"
56+
},
57+
]
58+
59+
df = pd.DataFrame(demo_data)
60+
return df
61+
62+
# Cas 2 : fichier présent (ton environnement local)
2563
try:
64+
print(f"Loading CSV from: {csv_path}")
2665
df = pd.read_csv(csv_path)
27-
# Required English Column Names
28-
required_cols = ['ID', 'Asset', 'Threat', 'Vulnerability',
29-
'Probability', 'Impact', 'Risk', 'Decision', 'Recommendation']
66+
67+
required_cols = [
68+
'ID', 'Asset', 'Threat', 'Vulnerability',
69+
'Probability', 'Impact', 'Risk', 'Decision', 'Recommendation'
70+
]
3071

3172
if not all(col in df.columns for col in required_cols):
3273
print(f"Error: Missing columns in CSV. Expected: {required_cols}")
3374
sys.exit(1)
3475

35-
# Ensure Risk is calculated correctly (since it might be missing or pre-calculated)
76+
# Recalcule le risque pour être sûr
3677
df['Risk'] = df['Probability'] * df['Impact']
3778

3879
return df
@@ -259,7 +300,7 @@ def main():
259300

260301
print("Creating Excel file...") # Pas besoin de f-string ici
261302
print("Success: Excel file generated successfully!") # Pas besoin de f-string ici
262-
print(f" - {len(df)} risks processed") # F-string nécessaire ici pour afficher len(df)
303+
print(" - " + str(len(df)) + " risks processed") # F-string nécessaire ici pour afficher len(df)
263304
print(" - 3 tabs created: Matrix + Heatmap + Dashboard") # Pas besoin de f-string ici
264305

265306
if __name__ == '__main__':

0 commit comments

Comments
 (0)