-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(parser): add conan parser (#4569)
--------- Signed-off-by: Aryan Bakliwal <aryanbakliwal12345@gmail.com> Co-authored-by: Terri Oda <terri.oda@intel.com>
- Loading branch information
1 parent
fc85cc8
commit 37f514c
Showing
7 changed files
with
102 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,6 +94,7 @@ codecov | |
collectd | ||
commons | ||
compress | ||
conan | ||
conda | ||
config | ||
connman | ||
|
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 |
---|---|---|
|
@@ -13,4 +13,4 @@ NOTKNOWN | |
pyyaml | ||
skontar | ||
Svunknown | ||
urllib | ||
urllib |
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 |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
"perl", | ||
"dart", | ||
"env", | ||
"ccpp", | ||
] | ||
|
||
|
||
|
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,65 @@ | ||
# Copyright (C) 2024 Intel Corporation | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
"""Python script containing all functionalities related to parsing of C/C++ conan.lock files.""" | ||
|
||
import json | ||
import re | ||
|
||
from cve_bin_tool.parsers import Parser | ||
|
||
|
||
class CCppParser(Parser): | ||
""" | ||
Parser for C/C++ conan.lock files based on | ||
https://docs.conan.io/2/tutorial/versioning/lockfiles.html | ||
""" | ||
|
||
PARSER_MATCH_FILENAMES = [ | ||
"conan.lock", | ||
] | ||
|
||
def __init__(self, cve_db, logger): | ||
super().__init__(cve_db, logger) | ||
self.purl_pkg_type = "conan" | ||
|
||
def generate_purl(self, product, vendor="", version="", qualifier={}, subpath=None): | ||
"""Generates PURL after normalizing all components.""" | ||
product = re.sub(r"[^a-zA-Z0-9._-]", "", product).lower() | ||
|
||
if not product: | ||
return None | ||
|
||
purl = super().generate_purl( | ||
product, | ||
vendor, | ||
version, | ||
qualifier, | ||
subpath, | ||
) | ||
|
||
return purl | ||
|
||
def run_checker(self, filename): | ||
"""Parse the file and yield valid PURLs.""" | ||
self.filename = filename | ||
with open(self.filename) as fh: | ||
data = json.load(fh) | ||
requires = data["requires"] | ||
build_requires = data["build_requires"] | ||
if requires: | ||
for require in requires: | ||
product = require.split("#")[0].split("/")[0] | ||
version = require.split("#")[0].split("/")[1] | ||
purl = self.generate_purl(product) | ||
vendor = self.get_vendor(purl, product, version) | ||
if vendor is not None: | ||
yield from vendor | ||
if build_requires: | ||
for build_require in build_requires: | ||
product = build_require.split("#")[0].split("/")[0] | ||
version = build_require.split("#")[0].split("/")[1] | ||
purl = self.generate_purl(product) | ||
vendor = self.get_vendor(purl, product, version) | ||
if vendor is not None: | ||
yield from vendor | ||
self.logger.debug(f"Done scanning file: {self.filename}") |
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,12 @@ | ||
{ | ||
"version": "0.5", | ||
"requires": [ | ||
"zlib/1.2.11#fca992a7d96a1b92bd956caa8a97d18f%1705999194.642", | ||
"openssl/3.0.1w#a8f0792d7c5121b954578a7149d23e03%1717541485.78" | ||
], | ||
"build_requires": [ | ||
"cmake/3.22.6#f305019023c2db74d1001c5afa5cf362" | ||
], | ||
"python_requires": [], | ||
"config_requires": [] | ||
} |
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