-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathpath_command.py
More file actions
74 lines (61 loc) · 2.82 KB
/
path_command.py
File metadata and controls
74 lines (61 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import time
from pathlib import Path
from typing import Annotated
import typer
from cycode.cli import consts
from cycode.cli.apps.report.sbom.common import create_sbom_report, send_report_feedback
from cycode.cli.exceptions.handle_report_sbom_errors import handle_report_exception
from cycode.cli.files_collector.path_documents import get_relevant_documents
from cycode.cli.files_collector.sca.sca_code_scanner import perform_pre_scan_documents_actions
from cycode.cli.files_collector.zip_documents import zip_documents
from cycode.cli.utils.get_api_client import get_report_cycode_client
from cycode.cli.utils.progress_bar import SbomReportProgressBarSection
from cycode.cli.utils.sentry import add_breadcrumb
def path_command(
ctx: typer.Context,
path: Annotated[
Path,
typer.Argument(exists=True, resolve_path=True, help='Path to generate SBOM report for.', show_default=False),
],
) -> None:
add_breadcrumb('path')
client = get_report_cycode_client(ctx)
report_parameters = ctx.obj['report_parameters']
output_format = report_parameters.output_format
output_file = ctx.obj['output_file']
progress_bar = ctx.obj['progress_bar']
progress_bar.start()
start_scan_time = time.time()
report_execution_id = -1
try:
documents = get_relevant_documents(
progress_bar, SbomReportProgressBarSection.PREPARE_LOCAL_FILES, consts.SCA_SCAN_TYPE, (str(path),)
)
# TODO(MarshalX): combine perform_pre_scan_documents_actions with get_relevant_document.
# unhardcode usage of context in perform_pre_scan_documents_actions
perform_pre_scan_documents_actions(ctx, consts.SCA_SCAN_TYPE, documents)
zipped_documents = zip_documents(consts.SCA_SCAN_TYPE, documents)
report_execution = client.request_sbom_report_execution(report_parameters, zip_file=zipped_documents)
report_execution_id = report_execution.id
create_sbom_report(progress_bar, client, report_execution_id, output_file, output_format)
send_report_feedback(
client=client,
start_scan_time=start_scan_time,
report_type='SBOM',
report_command_type='path',
request_report_parameters=report_parameters.to_dict(without_entity_type=False),
report_execution_id=report_execution_id,
request_zip_file_size=zipped_documents.size,
)
except Exception as e:
progress_bar.stop()
send_report_feedback(
client=client,
start_scan_time=start_scan_time,
report_type='SBOM',
report_command_type='path',
request_report_parameters=report_parameters.to_dict(without_entity_type=False),
report_execution_id=report_execution_id,
error_message=str(e),
)
handle_report_exception(ctx, e)