-
Notifications
You must be signed in to change notification settings - Fork 546
feat(parser): add conan parser #4569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9c3f88c
feat(parser): add conan parser
AryanBakliwal f814b59
feat(parser): add example and test build_requires
AryanBakliwal d88322b
Merge branch 'main' into conan_parser
AryanBakliwal 21a1f62
Merge branch 'main' into conan_parser
AryanBakliwal add8cea
feat(parser): add conan to expect.txt
AryanBakliwal bc1b052
Merge branch 'main' into conan_parser
AryanBakliwal 8a0aa5f
feat(parser): add conan spelling
AryanBakliwal 7b45bcf
Merge branch 'main' into conan_parser
AryanBakliwal 4ad9bb7
Merge branch 'main' into conan_parser
terriko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.