Skip to content

Commit

Permalink
csmock: export apply_result_filters()
Browse files Browse the repository at this point in the history
... so that it can be reused by cspodman

Related: https://issues.redhat.com/browse/OSH-151
Closes: #115
  • Loading branch information
kdudka committed Sep 13, 2023
1 parent 8a0fd05 commit dd5baab
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
24 changes: 24 additions & 0 deletions py/common/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,30 @@ def finalize_results(js_file, results, props):
os.system("csgrep '%s'" % err_file)

Check warning

Code scanning / vcs-diff-lint

finalize_results: Formatting a regular string which could be a f-string Warning

finalize_results: Formatting a regular string which could be a f-string


def apply_result_filters(props, results, supp_filters=[]):

Check warning

Code scanning / vcs-diff-lint

apply_result_filters: Dangerous default value [] as argument Warning

apply_result_filters: Dangerous default value [] as argument
"""apply filters, sort the list and record suppressed results"""
js_file = os.path.join(results.resdir, "scan-results.js")
all_file = os.path.join(results.dbgdir, "scan-results-all.js")

# apply filters, sort the list and store the result as scan-results.js
cmd = f"cat '{all_file}'"
for filt in props.result_filters:
cmd += f" | {filt}"
cmd += f" | cssort --key=path > '{js_file}'"
results.exec_cmd(cmd, shell=True)

# record suppressed results
js_supp = os.path.join(results.dbgdir, "suppressed-results.js")
cmd = f"cat '{all_file}'"
for filt in supp_filters:
cmd += f" | {filt}"
cmd += f" | csdiff --show-internal '{js_file}' -"
cmd += f" | cssort > '{js_supp}'"
results.exec_cmd(cmd, shell=True)
finalize_results(js_supp, results, props)
finalize_results(js_file, results, props)


def handle_known_fp_list(props, results):
"""Update props.result_filters based on props.known_false_positives"""
if not props.known_false_positives:
Expand Down
20 changes: 4 additions & 16 deletions py/csmock
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ from csmock.common.util import shell_quote
from csmock.common.util import strlist_to_shell_cmd
from csmock.common.results import FatalError
from csmock.common.results import ScanResults
from csmock.common.results import apply_result_filters
from csmock.common.results import finalize_results

Check warning

Code scanning / vcs-diff-lint

Unable to import 'csmock.common.results' Warning

Unable to import 'csmock.common.results'
from csmock.common.results import handle_known_fp_list

Check warning

Code scanning / vcs-diff-lint

Unable to import 'csmock.common.results' Warning

Unable to import 'csmock.common.results'
from csmock.common.results import transform_results
Expand Down Expand Up @@ -1236,23 +1237,10 @@ cd %%s*/ || cd *\n\

# we are done with mock

# apply filters, sort the list and store the result as scan-results.js
cmd = "cat '%s'" % all_file
for filt in props.result_filters:
cmd += " | %s" % filt
cmd += " | cssort --key=path > '%s'" % js_file
results.exec_cmd(cmd, shell=True)

# record suppressed results
js_supp = "%s/suppressed-results.js" % results.dbgdir
cmd = "%s '%s' " % (RPM_BI_FILTER, all_file)
cmd += "| csgrep --mode=json --strip-path-prefix /builddir/build/BUILD/ "
cmd += "| csdiff --show-internal '%s' - " % js_file
cmd += "| cssort > '%s'" % js_supp
results.exec_cmd(cmd, shell=True)
finalize_results(js_supp, results, props)
# apply filters, sort the list and record suppressed results
supp_filters = [RPM_BI_FILTER, "csgrep --mode=json --strip-path-prefix /builddir/build/BUILD/"]
apply_result_filters(props, results, supp_filters=supp_filters)

finalize_results(js_file, results, props)
return results.ec

except FatalError as error:
Expand Down

0 comments on commit dd5baab

Please sign in to comment.