Skip to content

Commit

Permalink
secscan: ClairV2 datatype compatibility (PROJQUAY-3279) (#1133)
Browse files Browse the repository at this point in the history
Mormalize metadata fields when serializing from dict, if not defined.
  • Loading branch information
kleesc committed Feb 22, 2022
1 parent ca17eb4 commit b32ca31
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
24 changes: 17 additions & 7 deletions data/secscan_model/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ class ScanLookupStatus(IntEnum):
["Severity", "NamespaceName", "Link", "FixedBy", "Description", "Name", "Metadata"],
)
Metadata = namedtuple(
"Metadata", ["UpdatedBy", "RepoName", "RepoLink", "DistroName", "DistroVersion", "NVD"]
"Metadata",
["UpdatedBy", "RepoName", "RepoLink", "DistroName", "DistroVersion", "NVD"],
)
NVD = namedtuple("NVD", ["CVSSv3"])
CVSSv3 = namedtuple("CVSSv3", ["Vectors", "Score"])
CVSSv3 = namedtuple("CVSSv3", ["Vectors", "Score"], defaults=(None, None))
Feature = namedtuple(
"Feature", ["Name", "VersionFormat", "NamespaceName", "AddedBy", "Version", "Vulnerabilities"]
)
Expand Down Expand Up @@ -69,11 +70,20 @@ def from_dict(cls, data_dict):
Description=vuln.get("Description", None),
Name=vuln.get("Name", None),
Metadata=Metadata(
UpdatedBy=vuln["Metadata"].get("UpdatedBy", None),
RepoName=vuln["Metadata"].get("RepoName", None),
RepoLink=vuln["Metadata"].get("RepoLink", None),
DistroName=vuln["Metadata"].get("DistroName", None),
DistroVersion=vuln["Metadata"].get("DistroVersion", None),
UpdatedBy=vuln.get("Metadata", {}).get("UpdatedBy", None),
RepoName=vuln.get("Metadata", {}).get("RepoName", None),
RepoLink=vuln.get("Metadata", {}).get("RepoLink", None),
DistroName=vuln.get("Metadata", {}).get("DistroName", None),
DistroVersion=vuln.get("Metadata", {}).get(
"DistroVersion", None
),
NVD=NVD(
CVSSv3(
**vuln.get("Metadata", {})
.get("NVD", {})
.get(["CVSv3"], {})
)
),
),
)
for vuln in f.get("Vulnerabilities", [])
Expand Down
3 changes: 0 additions & 3 deletions data/secscan_model/secscan_v2_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
ScanLookupStatus,
SecurityInformationLookupResult,
SecurityInformation,
Layer,
Feature,
Vulnerability,
)

from data.registry_model import registry_model
Expand Down

0 comments on commit b32ca31

Please sign in to comment.