MCPcopy Create free account
hub / github.com/aboutcode-org/vulnerablecode / to_advisory

Function to_advisory

vulnerabilities/importers/redhat.py:76–164  ·  view source on GitHub ↗
(advisory_data)

Source from the content-addressed store, hash-verified

74
75
76def to_advisory(advisory_data):
77 affected_packages: List[AffectedPackage] = []
78 for rpm in advisory_data.get("affected_packages") or []:
79 purl = rpm_to_purl(rpm_string=rpm, namespace="redhat")
80 if purl:
81 try:
82 affected_version_range = RpmVersionRange.from_versions(sequence=[purl.version])
83 affected_packages.append(
84 AffectedPackage(
85 package=PackageURL(
86 type=purl.type,
87 name=purl.name,
88 namespace=purl.namespace,
89 qualifiers=purl.qualifiers,
90 subpath=purl.subpath,
91 ),
92 affected_version_range=affected_version_range,
93 fixed_version=None,
94 )
95 )
96 except Exception as e:
97 logger.error(f"Failed to parse version range {purl.version} for {purl} {e}")
98
99 references = []
100 bugzilla = advisory_data.get("bugzilla")
101 if bugzilla:
102 url = "https://bugzilla.redhat.com/show_bug.cgi?id={}".format(bugzilla)
103 references.append(
104 Reference(
105 url=url,
106 reference_id=bugzilla,
107 )
108 )
109
110 for rh_adv in advisory_data.get("advisories") or []:
111 # RH provides 3 types of advisories RHSA, RHBA, RHEA. Only RHSA's contain severity score.
112 # See https://access.redhat.com/articles/2130961 for more details.
113
114 if not isinstance(rh_adv, str):
115 logger.error(f"Invalid advisory type {rh_adv}")
116 continue
117
118 if "RHSA" in rh_adv.upper():
119 references.append(
120 Reference(
121 url="https://access.redhat.com/errata/{}".format(rh_adv),
122 reference_id=rh_adv,
123 )
124 )
125
126 else:
127 references.append(Reference(severities=[], url=url, reference_id=rh_adv))
128
129 redhat_scores = []
130 cvssv3_score = advisory_data.get("cvss3_score")
131 cvssv3_vector = advisory_data.get("cvss3_scoring_vector", "")
132 if cvssv3_score:
133 redhat_scores.append(

Callers 1

advisory_dataMethod · 0.85

Calls 6

rpm_to_purlFunction · 0.90
AffectedPackageClass · 0.90
ReferenceClass · 0.90
AdvisoryDataClass · 0.90
getMethod · 0.45

Tested by

no test coverage detected