Skip to content

Commit 1412784

Browse files
authored
Merge pull request #6 from blackducksoftware/dev-local
ignore_archive_submatches
2 parents a4a640e + 066663f commit 1412784

File tree

8 files changed

+70
-6
lines changed

8 files changed

+70
-6
lines changed

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# bd_sig_filter - v1.7
1+
# bd_sig_filter - v1.8
22
BD Script to ignore components matched from Signature scan likely to be partial or invalid matches, and
33
mark components reviewed which are definitive matches (dependency or component name and version in matched path for
44
signature matches).
@@ -65,7 +65,7 @@ The package can be invoked as follows:
6565

6666
usage: bd-sig-filter [-h] [--blackduck_url BLACKDUCK_URL] [--blackduck_api_token BLACKDUCK_API_TOKEN] [--blackduck_trust_cert] [-p PROJECT] [-v VERSION] [--debug] [--logfile LOGFILE]
6767
[--report_file REPORT_FILE] [--version_match_reqd] [--ignore] [--review] [--no_ignore_test] [--no_ignore_synopsys] [--no_ignore_defaults]
68-
[--ignore_no_path_matches]
68+
[--ignore_no_path_matches] [--ignore_archive_submatches]
6969

7070
options:
7171
-h, --help show this help message and exit
@@ -94,6 +94,8 @@ The package can be invoked as follows:
9494
(Use with caution)
9595
--report_unmatched Report the list of components which will be left Unreviewed and why - these may need
9696
to be manually reviewed.
97+
--ignore_archive_submatches
98+
Process components to determine sub-matches within archives.
9799

98100
The minimum required options are:
99101

@@ -171,6 +173,11 @@ Options can be used to modify the behaviour of the script as follows:
171173
`--report_unmatched`:
172174
Create a list of Signature components which will be left UNreviewed
173175

176+
`--ignore_archive_submatches`:
177+
Process components in the project version looking for those matched within
178+
archive files, and report which can be ignored because they are sub-matches (from folders within the archive).
179+
All other operations are replaced by this action.
180+
174181
The options `--report_file` and `--logfile` can be used to output the tabular report and logging data to
175182
specified files.
176183

bd_sig_filter/BOMClass.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,5 @@ def report_unmatched(self):
8787
# Writing data to a file
8888
rfile.writelines(data)
8989

90+
def process_archives(self):
91+
self.complist.process_archives()

bd_sig_filter/ComponentClass.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def __init__(self, name, version, data):
2222
self.best_sigpath = ''
2323
self.oriname_arr = self.get_origin_compnames()
2424
self.unmatched = False
25+
self.archive_match = False
2526

2627
def get_compverid(self):
2728
try:
@@ -233,3 +234,25 @@ def get_sigpaths(self):
233234
data += f"{sigentry.get_sigpath()}\n"
234235
count += 1
235236
return data
237+
238+
def get_archive_match(self):
239+
for sigentry in self.sigentry_arr:
240+
paths = sigentry.path.split('!')
241+
if len(paths) == 1:
242+
self.archive_match = True
243+
return paths[0]
244+
245+
def get_top_match(self, archive_list):
246+
import re
247+
ver_digits = re.sub("[^0-9._-]", "", self.version)
248+
249+
for sigentry in self.sigentry_arr:
250+
paths = sigentry.path.split('!')
251+
if len(paths) == 1:
252+
continue
253+
for oricompname in self.oriname_arr:
254+
# if oricompname in paths[0]:
255+
if oricompname in paths[0] and ver_digits in paths[0]:
256+
# print(oricompname, self.version, paths[0])
257+
self.archive_match = True
258+
return

bd_sig_filter/ComponentListClass.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,4 +344,25 @@ def get_unmatched_list(self):
344344
paths = comp.get_sigpaths()
345345
orinames = ','.join(comp.oriname_arr)
346346
data += f"Comp: {comp.name}/{comp.version} (Origin names={orinames}):\n{paths}"
347-
return data
347+
return data
348+
349+
def process_archives(self):
350+
archive_list = []
351+
for comp in self.components:
352+
if comp.is_ignored():
353+
continue
354+
if comp.is_only_signature():
355+
archive = comp.get_archive_match()
356+
archive_list.append(archive)
357+
358+
for comp in self.components:
359+
if not comp.is_ignored() and not comp.archive_match:
360+
comp.get_top_match(archive_list)
361+
362+
ignored_count = 0
363+
for comp in self.components:
364+
if not comp.is_ignored() and not comp.archive_match:
365+
comp.ignore = True
366+
ignored_count += 1
367+
368+
logging.info(f"Found {ignored_count} archive sub-components to ignore")

bd_sig_filter/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
parser.add_argument("--no_ignore_defaults", help="Do not ignore components in default folders", action='store_true')
2828
parser.add_argument("--ignore_no_path_matches", help="Also ignore components with no component/version match in signature path", action='store_true')
2929
parser.add_argument("--report_unmatched", help="Report unmatched (not reviewed or ignored) components", action='store_true')
30+
parser.add_argument("--ignore_archive_submatches", help="Ignore sub-components within archives", action='store_true')
3031

3132
args = parser.parse_args()
3233

@@ -104,6 +105,9 @@ def check_args():
104105
if args.no_ignore_defaults:
105106
global_values.no_ignore_defaults = True
106107

108+
if args.ignore_archive_submatches:
109+
global_values.ignore_archive_submatches = True
110+
107111
if args.ignore_no_path_matches:
108112
if not args.ignore:
109113
logging.warning(f"Option --ignore_no_path_matches set without --ignore")

bd_sig_filter/global_values.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
1515
ignore_no_path_matches = False
1616
review = False
1717
report_file = ''
18-
report_unmatched = False
18+
report_unmatched = False
19+
ignore_archive_submatches = False

bd_sig_filter/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ def main():
1616

1717
logging.debug('- Getting matched file data ... ')
1818
bom.get_bom_files()
19+
if global_values.ignore_archive_submatches:
20+
logging.info("Processing components within archives ...")
21+
bom.process_archives()
22+
bom.update_components()
23+
return
24+
1925
bom.process()
2026
bom.update_components()
2127
bom.report_summary()

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "bd_sig_filter"
7-
version = "1.7"
7+
version = "1.8"
88
authors = [
9-
{ name="Matthew Brady", email="mbrad@synopsys.com" },
9+
{ name="Matthew Brady", email="mbrad@blackduck.com" },
1010
]
1111
description = "BD_sig_filter - BD Script to ignore components matched from Signature scan likely to be partial or invalid matches."
1212
readme = "README.md"

0 commit comments

Comments
 (0)