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

Function get_affected_purl

vulnerabilities/importers/osv.py:216–256  ·  view source on GitHub ↗

Return an affected PackageURL or None given a mapping of ``affected_pkg`` data and a ``raw_id``.

(affected_pkg, raw_id)

Source from the content-addressed store, hash-verified

214
215
216def get_affected_purl(affected_pkg, raw_id):
217 """
218 Return an affected PackageURL or None given a mapping of ``affected_pkg``
219 data and a ``raw_id``.
220 """
221 package = affected_pkg.get("package") or {}
222 purl = package.get("purl")
223 if purl:
224 try:
225 purl = PackageURL.from_string(purl)
226 except ValueError:
227 logger.error(
228 f"Invalid PackageURL: {purl!r} for OSV "
229 f"affected_pkg {affected_pkg} and id: {raw_id}"
230 )
231 else:
232 ecosys = package.get("ecosystem")
233 name = package.get("name")
234 if ecosys and name:
235 ecosys = ecosys.lower()
236 purl_type = PURL_TYPE_BY_OSV_ECOSYSTEM.get(ecosys)
237 if not purl_type:
238 return
239 namespace = ""
240 if purl_type == "maven":
241 namespace, _, name = name.partition(":")
242
243 purl = PackageURL(type=purl_type, namespace=namespace, name=name)
244 else:
245 logger.error(
246 f"No PackageURL possible: {purl!r} for affected_pkg {affected_pkg} for OSV id: {raw_id}"
247 )
248 return
249 try:
250 package_url = PackageURL.from_string(str(purl))
251 return package_url
252 except:
253 logger.error(
254 f"Invalid PackageURL: {purl!r} for affected_pkg {affected_pkg} for OSV id: {raw_id}"
255 )
256 return None
257
258
259def get_affected_version_range(affected_pkg, raw_id, supported_ecosystem):

Callers 1

parse_advisory_dataFunction · 0.70

Calls 1

getMethod · 0.45

Tested by

no test coverage detected