|
26 | 26 |
|
27 | 27 | parser = argparse.ArgumentParser("Parse the Synopsys Detect log, load status.json, and wait for all scan processing to complete")
|
28 | 28 | parser.add_argument("-d", "--detect_log", help="By default, this script will read the detect log from stdin, but you can alternatively supply a detect log filename")
|
29 |
| -# parser.add_argument('-m', '--max_checks', type=int, default=10, help="Set the maximum number of checks before quitting") |
30 |
| -# parser.add_argument('-t', '--time_between_checks', type=int, default=5, help="Set the number of seconds to wait in-between checks") |
31 |
| -# parser.add_argument('-s', '--snippet_scan', action='store_true', help="Select this option if you want to wait for a snippet scan to complete along with it's corresponding component scan.") |
| 29 | +parser.add_argument("-m", "--max_checks", default=10, type=int, help="Set the maximum number of checks before timing out. Applies to each code/scan location") |
| 30 | +parser.add_argument("-c", "--check_delay", default=5, type=int, help="The number of seconds between each check") |
32 | 31 | args = parser.parse_args()
|
33 | 32 |
|
34 | 33 | logging.basicConfig(format='%(asctime)s:%(levelname)s:%(message)s', stream=sys.stderr, level=logging.DEBUG)
|
|
40 | 39 | else:
|
41 | 40 | detect_log = sys.stdin
|
42 | 41 |
|
43 |
| -snippet_scan = False |
| 42 | +snippet_scan_option_set = False |
44 | 43 | status_file_path = None
|
45 | 44 | start_time = None
|
46 | 45 |
|
|
60 | 59 | snippet_matching_re = re.search(".*detect.blackduck.signature.scanner.snippet.matching = (.*)", line)
|
61 | 60 | if snippet_matching_re:
|
62 | 61 | if 'SNIPPET' in snippet_matching_re[1]:
|
63 |
| - snippet_scan = True |
| 62 | + snippet_scan_option_set = True |
64 | 63 | logging.debug("Found snippet scanning option")
|
65 | 64 |
|
66 | 65 | status_file_re = re.search(".*Creating status file: (.*)", line)
|
|
71 | 70 | assert start_time, "Hmm, not sure how that happened but we need a start time"
|
72 | 71 |
|
73 | 72 | logging.debug(f"detect start time: {start_time}")
|
74 |
| -logging.debug(f"snippet_scan: {snippet_scan}") |
| 73 | +logging.debug(f"snippet_scan_option_set: {snippet_scan_option_set}") |
75 | 74 | logging.debug(f"status.json path: {status_file_path}")
|
76 | 75 |
|
77 | 76 | hub = HubInstance()
|
|
80 | 79 | status_info = json.load(status_file)
|
81 | 80 |
|
82 | 81 | # Monitoring status serially cause it's simpler (i.e. than spawning multiple threads and waiting for them)
|
| 82 | + scan_results = [] |
83 | 83 | for code_location in status_info['codeLocations']:
|
84 | 84 | logging.debug(f"Waiting for scan to finish at scan/code location {code_location['codeLocationName']}")
|
| 85 | + is_signature_scan = code_location['codeLocationName'].endswith("scan") |
| 86 | + snippet_scan = is_signature_scan and snippet_scan_option_set |
| 87 | + logging.debug(f"is_signature_scan: {is_signature_scan}, snippet_scan: {snippet_scan}") |
85 | 88 | scan_monitor = ScanMonitor(
|
86 | 89 | hub,
|
87 | 90 | start_time=start_time,
|
88 | 91 | scan_location_name=code_location['codeLocationName'],
|
89 |
| - snippet_scan=snippet_scan) |
90 |
| - scan_monitor.wait_for_scan_completion() |
| 92 | + snippet_scan=snippet_scan, |
| 93 | + max_checks=args.max_checks, |
| 94 | + check_delay=args.check_delay) |
| 95 | + scan_result = scan_monitor.wait_for_scan_completion() |
| 96 | + logging.debug(f"scan result for {code_location['codeLocationName']} was {scan_result}") |
| 97 | + |
| 98 | + if sum(scan_results) > 0: |
| 99 | + sys.exit(1) # failure |
| 100 | + else: |
| 101 | + sys.exit(0) |
91 | 102 |
|
92 | 103 |
|
0 commit comments