27
27
import sys
28
28
from dataclasses import asdict
29
29
from pathlib import Path
30
+ from typing import List
30
31
31
32
import pypac
32
- from typing import List
33
33
34
34
from scanoss .scanners .folder_hasher import (
35
35
FolderHasher ,
73
73
PYTHON3_OR_LATER = 3
74
74
HEADER_PARTS_COUNT = 2
75
75
76
+
76
77
def print_stderr (* args , ** kwargs ):
77
78
"""
78
79
Print the given message to STDERR
@@ -152,15 +153,17 @@ def setup_args() -> None: # noqa: PLR0915
152
153
help = 'Timeout (in seconds) for API communication (optional - default 180)' ,
153
154
)
154
155
p_scan .add_argument (
155
- '--retry' , '-R' , type = int , default = DEFAULT_RETRY ,
156
- help = 'Retry limit for API communication (optional - default 5)'
156
+ '--retry' ,
157
+ '-R' ,
158
+ type = int ,
159
+ default = DEFAULT_RETRY ,
160
+ help = 'Retry limit for API communication (optional - default 5)' ,
157
161
)
158
162
p_scan .add_argument ('--no-wfp-output' , action = 'store_true' , help = 'Skip WFP file generation' )
159
163
p_scan .add_argument ('--dependencies' , '-D' , action = 'store_true' , help = 'Add Dependency scanning' )
160
164
p_scan .add_argument ('--dependencies-only' , action = 'store_true' , help = 'Run Dependency scanning only' )
161
165
p_scan .add_argument (
162
- '--sc-command' , type = str ,
163
- help = 'Scancode command and path if required (optional - default scancode).'
166
+ '--sc-command' , type = str , help = 'Scancode command and path if required (optional - default scancode).'
164
167
)
165
168
p_scan .add_argument (
166
169
'--sc-timeout' ,
@@ -631,7 +634,7 @@ def setup_args() -> None: # noqa: PLR0915
631
634
)
632
635
633
636
# Global GRPC options
634
- for p in [p_scan , c_crypto , c_vulns , c_search , c_versions , c_semgrep , c_provenance ]:
637
+ for p in [p_scan , c_crypto , c_vulns , c_search , c_versions , c_semgrep , c_provenance , p_folder_scan ]:
635
638
p .add_argument (
636
639
'--api2url' , type = str , help = 'SCANOSS gRPC API 2.0 URL (optional - default: https://api.osskb.org)'
637
640
)
@@ -642,10 +645,11 @@ def setup_args() -> None: # noqa: PLR0915
642
645
'Can also use the environment variable "grcp_proxy=<ip>:<port>"' ,
643
646
)
644
647
p .add_argument (
645
- '--header' ,'-hdr' ,
648
+ '--header' ,
649
+ '-hdr' ,
646
650
action = 'append' , # This allows multiple -H flags
647
651
type = str ,
648
- help = 'Headers to be sent on request (e.g., -hdr "Name: Value") - can be used multiple times'
652
+ help = 'Headers to be sent on request (e.g., -hdr "Name: Value") - can be used multiple times' ,
649
653
)
650
654
651
655
# Help/Trace command options
@@ -666,9 +670,8 @@ def setup_args() -> None: # noqa: PLR0915
666
670
p_results ,
667
671
p_undeclared ,
668
672
p_copyleft ,
669
- c_provenance
673
+ c_provenance ,
670
674
p_folder_scan ,
671
- p_folder_hash ,
672
675
]:
673
676
p .add_argument ('--debug' , '-d' , action = 'store_true' , help = 'Enable debug messages' )
674
677
p .add_argument ('--trace' , '-t' , action = 'store_true' , help = 'Enable trace messages, including API posts' )
@@ -686,6 +689,7 @@ def setup_args() -> None: # noqa: PLR0915
686
689
sys .exit (1 )
687
690
args .func (parser , args ) # Execute the function associated with the sub-command
688
691
692
+
689
693
def ver (* _ ):
690
694
"""
691
695
Run the "ver" sub-command
@@ -983,7 +987,7 @@ def scan(parser, args): # noqa: PLR0912, PLR0915
983
987
strip_hpsm_ids = args .strip_hpsm ,
984
988
strip_snippet_ids = args .strip_snippet ,
985
989
scan_settings = scan_settings ,
986
- req_headers = process_req_headers (args .header ),
990
+ req_headers = process_req_headers (args .header ),
987
991
)
988
992
if args .wfp :
989
993
if not scanner .is_file_or_snippet_scan ():
@@ -1195,7 +1199,7 @@ def utils_certloc(*_):
1195
1199
print (f'CA Cert File: { certifi .where ()} ' )
1196
1200
1197
1201
1198
- def utils_cert_download (_ , args ): # pylint: disable=PLR0912 # noqa: PLR0912
1202
+ def utils_cert_download (_ , args ): # pylint: disable=PLR0912 # noqa: PLR0912
1199
1203
"""
1200
1204
Run the "utils cert-download" sub-command
1201
1205
:param _: ignore/unused
@@ -1322,7 +1326,7 @@ def comp_crypto(parser, args):
1322
1326
grpc_proxy = args .grpc_proxy ,
1323
1327
pac = pac_file ,
1324
1328
timeout = args .timeout ,
1325
- req_headers = process_req_headers (args .header ),
1329
+ req_headers = process_req_headers (args .header ),
1326
1330
)
1327
1331
if not comps .get_crypto_details (args .input , args .purl , args .output ):
1328
1332
sys .exit (1 )
@@ -1480,6 +1484,7 @@ def comp_versions(parser, args):
1480
1484
if not comps .get_component_versions (args .output , json_file = args .input , purl = args .purl , limit = args .limit ):
1481
1485
sys .exit (1 )
1482
1486
1487
+
1483
1488
def comp_provenance (parser , args ):
1484
1489
"""
1485
1490
Run the "component semgrep" sub-command
@@ -1498,12 +1503,23 @@ def comp_provenance(parser, args):
1498
1503
print_stderr (f'Error: Certificate file does not exist: { args .ca_cert } .' )
1499
1504
sys .exit (1 )
1500
1505
pac_file = get_pac_file (args .pac )
1501
- comps = Components (debug = args .debug , trace = args .trace , quiet = args .quiet , grpc_url = args .api2url , api_key = args .key ,
1502
- ca_cert = args .ca_cert , proxy = args .proxy , grpc_proxy = args .grpc_proxy , pac = pac_file ,
1503
- timeout = args .timeout , req_headers = process_req_headers (args .header ))
1506
+ comps = Components (
1507
+ debug = args .debug ,
1508
+ trace = args .trace ,
1509
+ quiet = args .quiet ,
1510
+ grpc_url = args .api2url ,
1511
+ api_key = args .key ,
1512
+ ca_cert = args .ca_cert ,
1513
+ proxy = args .proxy ,
1514
+ grpc_proxy = args .grpc_proxy ,
1515
+ pac = pac_file ,
1516
+ timeout = args .timeout ,
1517
+ req_headers = process_req_headers (args .header ),
1518
+ )
1504
1519
if not comps .get_provenance_details (args .input , args .purl , args .output ):
1505
1520
sys .exit (1 )
1506
1521
1522
+
1507
1523
def results (parser , args ):
1508
1524
"""
1509
1525
Run the "results" sub-command
@@ -1562,13 +1578,14 @@ def process_req_headers(headers_array: List[str]) -> dict:
1562
1578
dict_headers = {}
1563
1579
for header_str in headers_array :
1564
1580
# Split each "Name: Value" header
1565
- parts = header_str .split (":" , 1 )
1581
+ parts = header_str .split (':' , 1 )
1566
1582
if len (parts ) == HEADER_PARTS_COUNT :
1567
1583
name = parts [0 ].strip ()
1568
1584
value = parts [1 ].strip ()
1569
1585
dict_headers [name ] = value
1570
1586
return dict_headers
1571
1587
1588
+
1572
1589
def folder_hashing_scan (parser , args ):
1573
1590
"""Run the "folder-scan" sub-command
1574
1591
0 commit comments