Skip to content

Commit 5472319

Browse files
committed
feat: add missing command args
feat: ES-163 add build children logic to folder hashing scan feat: ES-163 mimic go implementation of hashing folder content feat: ES-163 create our own crc64 implementation feat: ES-163 create our own simhash implementation based on go library feat: ES-163 better error handling feat: ES-163 update changelog, client help and version. add headers feat: ES-163 add AbstractPresenter to handle results output in a centralized way feat: ES-163 update changelog feat: ES-163 fix pr comments, update lint.yml workflow
1 parent fcf84c0 commit 5472319

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

Diff for: src/scanoss/cli.py

+34-17
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
import sys
2828
from dataclasses import asdict
2929
from pathlib import Path
30+
from typing import List
3031

3132
import pypac
32-
from typing import List
3333

3434
from scanoss.scanners.folder_hasher import (
3535
FolderHasher,
@@ -73,6 +73,7 @@
7373
PYTHON3_OR_LATER = 3
7474
HEADER_PARTS_COUNT = 2
7575

76+
7677
def print_stderr(*args, **kwargs):
7778
"""
7879
Print the given message to STDERR
@@ -152,15 +153,17 @@ def setup_args() -> None: # noqa: PLR0915
152153
help='Timeout (in seconds) for API communication (optional - default 180)',
153154
)
154155
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)',
157161
)
158162
p_scan.add_argument('--no-wfp-output', action='store_true', help='Skip WFP file generation')
159163
p_scan.add_argument('--dependencies', '-D', action='store_true', help='Add Dependency scanning')
160164
p_scan.add_argument('--dependencies-only', action='store_true', help='Run Dependency scanning only')
161165
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).'
164167
)
165168
p_scan.add_argument(
166169
'--sc-timeout',
@@ -631,7 +634,7 @@ def setup_args() -> None: # noqa: PLR0915
631634
)
632635

633636
# 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]:
635638
p.add_argument(
636639
'--api2url', type=str, help='SCANOSS gRPC API 2.0 URL (optional - default: https://api.osskb.org)'
637640
)
@@ -642,10 +645,11 @@ def setup_args() -> None: # noqa: PLR0915
642645
'Can also use the environment variable "grcp_proxy=<ip>:<port>"',
643646
)
644647
p.add_argument(
645-
'--header','-hdr',
648+
'--header',
649+
'-hdr',
646650
action='append', # This allows multiple -H flags
647651
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',
649653
)
650654

651655
# Help/Trace command options
@@ -666,9 +670,8 @@ def setup_args() -> None: # noqa: PLR0915
666670
p_results,
667671
p_undeclared,
668672
p_copyleft,
669-
c_provenance
673+
c_provenance,
670674
p_folder_scan,
671-
p_folder_hash,
672675
]:
673676
p.add_argument('--debug', '-d', action='store_true', help='Enable debug messages')
674677
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
686689
sys.exit(1)
687690
args.func(parser, args) # Execute the function associated with the sub-command
688691

692+
689693
def ver(*_):
690694
"""
691695
Run the "ver" sub-command
@@ -983,7 +987,7 @@ def scan(parser, args): # noqa: PLR0912, PLR0915
983987
strip_hpsm_ids=args.strip_hpsm,
984988
strip_snippet_ids=args.strip_snippet,
985989
scan_settings=scan_settings,
986-
req_headers= process_req_headers(args.header),
990+
req_headers=process_req_headers(args.header),
987991
)
988992
if args.wfp:
989993
if not scanner.is_file_or_snippet_scan():
@@ -1195,7 +1199,7 @@ def utils_certloc(*_):
11951199
print(f'CA Cert File: {certifi.where()}')
11961200

11971201

1198-
def utils_cert_download(_, args): # pylint: disable=PLR0912 # noqa: PLR0912
1202+
def utils_cert_download(_, args): # pylint: disable=PLR0912 # noqa: PLR0912
11991203
"""
12001204
Run the "utils cert-download" sub-command
12011205
:param _: ignore/unused
@@ -1322,7 +1326,7 @@ def comp_crypto(parser, args):
13221326
grpc_proxy=args.grpc_proxy,
13231327
pac=pac_file,
13241328
timeout=args.timeout,
1325-
req_headers= process_req_headers(args.header),
1329+
req_headers=process_req_headers(args.header),
13261330
)
13271331
if not comps.get_crypto_details(args.input, args.purl, args.output):
13281332
sys.exit(1)
@@ -1480,6 +1484,7 @@ def comp_versions(parser, args):
14801484
if not comps.get_component_versions(args.output, json_file=args.input, purl=args.purl, limit=args.limit):
14811485
sys.exit(1)
14821486

1487+
14831488
def comp_provenance(parser, args):
14841489
"""
14851490
Run the "component semgrep" sub-command
@@ -1498,12 +1503,23 @@ def comp_provenance(parser, args):
14981503
print_stderr(f'Error: Certificate file does not exist: {args.ca_cert}.')
14991504
sys.exit(1)
15001505
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+
)
15041519
if not comps.get_provenance_details(args.input, args.purl, args.output):
15051520
sys.exit(1)
15061521

1522+
15071523
def results(parser, args):
15081524
"""
15091525
Run the "results" sub-command
@@ -1562,13 +1578,14 @@ def process_req_headers(headers_array: List[str]) -> dict:
15621578
dict_headers = {}
15631579
for header_str in headers_array:
15641580
# Split each "Name: Value" header
1565-
parts = header_str.split(":", 1)
1581+
parts = header_str.split(':', 1)
15661582
if len(parts) == HEADER_PARTS_COUNT:
15671583
name = parts[0].strip()
15681584
value = parts[1].strip()
15691585
dict_headers[name] = value
15701586
return dict_headers
15711587

1588+
15721589
def folder_hashing_scan(parser, args):
15731590
"""Run the "folder-scan" sub-command
15741591

0 commit comments

Comments
 (0)