Threat intel fix (#484)
* feat: add validator to convert score from string to integer in IoCMapping * precommit fixes
taylor_socfortress committed
Aug 1, 2025 at 08:46 UTC
1396844d58f9a26c6a56e7bac753c9c2aaf0fabc
1 file changed
+16
backend/app/threat_intel/schema/socfortress.py
+16
@@ -43,6 +43,22 @@ class IoCMapping(BaseModel):
43
description="URL to the VirusTotal report",
44
)
45
46
+ @validator("score", pre=True)
47
+ def convert_score_to_int(cls, v):
48
+ """Convert score from string to integer"""
49
+ if v is None:
50
+ return None
51
+ if isinstance(v, str):
52
+ try:
53
+ # Convert string to float first, then to int to handle "100.0" format
54
+ return int(float(v))
55
+ except (ValueError, TypeError):
56
+ # If conversion fails, return None or raise an error
57
+ return None
58
+ elif isinstance(v, (int, float)):
59
+ return int(v)
60
+ return v
61
+
62
def to_dict(self):
63
return self.dict()
64