-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delete example package and files Update Python version to 3.12 in build workflows Update package name and description in setup.py Update dependencies in setup.py
- Loading branch information
Showing
14 changed files
with
193 additions
and
290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = "0.0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from odmantic import Model, Field | ||
from pydantic import ValidationInfo, field_validator | ||
from typing import Literal | ||
|
||
class CVE(Model): | ||
id: str = Field(primary_field=True) | ||
cvss_score: float | ||
cvss_version: Literal["2.0", "3.0", "3.1"] | ||
severity: Literal[1,2,3,4] = Field(default_factory=lambda: 1) | ||
|
||
model_config = { | ||
"collection": "cves" | ||
} | ||
|
||
@field_validator("cvss_score") | ||
def validate_cvss_score(cls, v: float) -> float: | ||
if v < 0.0 or v > 10.0: | ||
raise ValueError("CVSS score must be between 0.0 and 10.0 inclusive") | ||
return v | ||
|
||
def calculate_severity(self): | ||
if self.cvss_version == "2.0": | ||
if self.cvss_score == 10: | ||
self.severity = 4 | ||
elif self.cvss_score >= 7.0: | ||
self.severity = 3 | ||
elif self.cvss_score >= 4.0: | ||
self.severity = 2 | ||
else: | ||
self.severity = 1 | ||
else: # 3.0 or 3.1 | ||
if self.cvss_score >= 9.0: | ||
self.severity = 4 | ||
elif self.cvss_score >= 7.0: | ||
self.severity = 3 | ||
elif self.cvss_score >= 4.0: | ||
self.severity = 2 | ||
else: | ||
self.severity = 1 | ||
|
||
async def save(self, engine): | ||
self.calculate_severity() | ||
await engine.save(self) |
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.