From f8935f6ee99f41be9f20a605b400ee654adc4afc Mon Sep 17 00:00:00 2001 From: Cristian Pana Date: Wed, 10 Jul 2024 19:07:46 +0300 Subject: [PATCH] Add optional params no_advanced_match_scoring and match_filtering_threshold --- .pylintrc | 3 ++- README.md | 7 +++++++ workbench-agent.py | 25 +++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/.pylintrc b/.pylintrc index 084b8b0..230a973 100755 --- a/.pylintrc +++ b/.pylintrc @@ -6,7 +6,8 @@ disable=consider-using-f-string, broad-exception-caught, unspecified-encoding, logging-fstring-interpolation, - logging-format-interpolation + logging-format-interpolation, + too-many-arguments # Specify a configuration file. #rcfile= diff --git a/README.md b/README.md index 30dafdb..9e148e1 100755 --- a/README.md +++ b/README.md @@ -120,6 +120,8 @@ usage: workbench-agent.py [-h] --api_url API_URL --api_user API_USER [--delta_only] [--reuse_identifications] [--identification_reuse_type {any,only_me,specific_project,specific_scan}] [--specific_code SPECIFIC_CODE] + [--no_advanced_match_scoring] + [--match_filtering_threshold MATCH_FILTERING_THRESHOLD] [--chunked_upload] [--scan_number_of_tries SCAN_NUMBER_OF_TRIES] [--scan_wait_time SCAN_WAIT_TIME] --path PATH @@ -178,6 +180,11 @@ optional arguments: --specific_code SPECIFIC_CODE The scan code used when creating the scan in Workbench. It can be based on some env var, for example: ${BUILD_NUMBER} + --no_advanced_match_scoring + Disable advanced match scoring which by default is enabled. + --match_filtering_threshold MATCH_FILTERING_THRESHOLD + Minimum length, in characters, of the snippet to be considered valid after applying intelligent match + Set to 0 to disable intelligent match filtering for current scan. --target_path TARGET_PATH The path on the Workbench server where the code to be scanned is stored. No upload is done in this scenario. diff --git a/workbench-agent.py b/workbench-agent.py index 92f08b9..bd1f6f4 100755 --- a/workbench-agent.py +++ b/workbench-agent.py @@ -796,6 +796,8 @@ def run_scan( reuse_identification: bool, identification_reuse_type: str = None, specific_code: str = None, + advanced_match_scoring: bool = True, + match_filtering_threshold: int = -1 ): """ @@ -810,7 +812,9 @@ def run_scan( reuse_identification (bool): Reuse previous identifications identification_reuse_type (str): Possible values: any,only_me,specific_project,specific_scan specific_code (str): Fill only when reuse type: specific_project or specific_scan - + advanced_match_scoring (bool): If true, scan will run with advanced match scoring. + match_filtering_threshold (int): Minimum length (in characters) of snippet to be considered + valid after applying intelligent match filtering. Returns: """ @@ -843,8 +847,11 @@ def run_scan( auto_identification_resolve_pending_ids ), "delta_only": int(delta_only), + "advanced_match_scoring": int(advanced_match_scoring), }, } + if match_filtering_threshold > -1: + payload["data"]['match_filtering_threshold'] = match_filtering_threshold if reuse_identification: data = payload["data"] data["reuse_identification"] = "1" @@ -1151,7 +1158,19 @@ def non_empty_string(s): type=str, required=False, ) - + optional.add_argument( + '--no_advanced_match_scoring', + help='Disable advanced match scoring which by default is enabled.', + dest='advanced_match_scoring', + action='store_false', + ) + optional.add_argument( + "--match_filtering_threshold", + help="Minimum length, in characters, of the snippet to be considered valid after applying match filtering.\n" + "Set to 0 to disable intelligent match filtering for current scan.", + type=int, + default=-1, + ) optional.add_argument( "--target_path", help="The path on the Workbench server where the code to be scanned is stored.\n" @@ -1420,6 +1439,8 @@ def main(): params.reuse_identifications, params.identification_reuse_type, params.specific_code, + params.advanced_match_scoring, + params.match_filtering_threshold ) # Check if finished based on: scan_number_of_tries X scan_wait_time until throwing an error workbench.wait_for_scan_to_finish(