Add get_fixed_purl in AffectedPackage, fix from_dict
from_dict is a factory, should be a classmethod
@@ -66,14 +66,12 @@ class VulnerabilitySeverity:
"value": self.value,
}
- @staticmethod
- def from_dict(severity: dict):
+ @classmethod
+ def from_dict(cls, severity: dict):
"""
Return a VulnerabilitySeverity object from dict generated by self.to_dict
"""
- return VulnerabilitySeverity(
- system=SCORING_SYSTEMS[severity["system"]], value=severity["value"]
- )
+ return cls(system=SCORING_SYSTEMS[severity["system"]], value=severity["value"])
@dataclasses.dataclass(order=True)
@@ -101,12 +99,12 @@ class Reference:
"severities": [severity.to_dict() for severity in self.severities],
}
- @staticmethod
- def from_dict(ref: dict):
+ @classmethod
+ def from_dict(cls, ref: dict):
"""
Return a Reference object from dict generated by self.to_dict
"""
- return Reference(
+ return cls(
reference_id=ref["reference_id"],
url=ref["url"],
severities=[
@@ -130,8 +128,16 @@ class AffectedPackage:
if self.package.version:
raise ValueError
- @staticmethod
- def merge(affected_packages: Iterable):
+ def get_fixed_purl(self):
+ """
+ Return PackageURL corresponding to object's fixed_version
+ """
+ fixed_version = self.fixed_version
+ fixed_purl = self.package._replace(version=str(fixed_version))
+ return fixed_purl
+
+ @classmethod
+ def merge(cls, affected_packages: Iterable):
"""
Return a tuple with all attributes of AffectedPackage as a set
for all values in the given iterable of AffectedPackage
@@ -166,8 +172,8 @@ class AffectedPackage:
"fixed_version": str(self.fixed_version) if self.fixed_version else None,
}
- @staticmethod
- def from_dict(affected_pkg: dict):
+ @classmethod
+ def from_dict(cls, affected_pkg: dict):
"""
Return an AffectedPackage object from dict generated by self.to_dict
"""
@@ -178,7 +184,7 @@ class AffectedPackage:
# TODO: revisit after https://github.com/nexB/univers/issues/10
fixed_version = affected_version_range.version_class(fixed_version)
- return AffectedPackage(
+ return cls(
package=package,
affected_version_range=affected_version_range,
fixed_version=fixed_version,
