Skip to content

Commit 76b8bb3

Browse files
authored
CM-48559 - Add commit history scan and pre-commit hook for SAST (#314)
1 parent 8ac74b3 commit 76b8bb3

34 files changed

+1476
-1164
lines changed

.pre-commit-hooks.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@
1010
language_version: python3
1111
entry: cycode
1212
args: [ '-o', 'text', '--no-progress-meter', 'scan', '-t', 'sca', 'pre-commit' ]
13+
- id: cycode-sast
14+
name: Cycode SAST pre-commit defender
15+
language: python
16+
language_version: python3
17+
entry: cycode
18+
args: [ '-o', 'text', '--no-progress-meter', 'scan', '-t', 'sast', 'pre-commit' ]

README.md

Lines changed: 99 additions & 66 deletions
Large diffs are not rendered by default.

cycode/cli/apps/report/sbom/path/path_command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from cycode.cli.apps.report.sbom.common import create_sbom_report, send_report_feedback
99
from cycode.cli.exceptions.handle_report_sbom_errors import handle_report_exception
1010
from cycode.cli.files_collector.path_documents import get_relevant_documents
11-
from cycode.cli.files_collector.sca.sca_code_scanner import perform_pre_scan_documents_actions
11+
from cycode.cli.files_collector.sca.sca_file_collector import add_sca_dependencies_tree_documents_if_needed
1212
from cycode.cli.files_collector.zip_documents import zip_documents
1313
from cycode.cli.utils.get_api_client import get_report_cycode_client
1414
from cycode.cli.utils.progress_bar import SbomReportProgressBarSection
@@ -41,7 +41,7 @@ def path_command(
4141
)
4242
# TODO(MarshalX): combine perform_pre_scan_documents_actions with get_relevant_document.
4343
# unhardcode usage of context in perform_pre_scan_documents_actions
44-
perform_pre_scan_documents_actions(ctx, consts.SCA_SCAN_TYPE, documents)
44+
add_sca_dependencies_tree_documents_if_needed(ctx, consts.SCA_SCAN_TYPE, documents)
4545

4646
zipped_documents = zip_documents(consts.SCA_SCAN_TYPE, documents)
4747
report_execution = client.request_sbom_report_execution(report_parameters, zip_file=zipped_documents)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from typing import TYPE_CHECKING, Optional
2+
3+
import typer
4+
5+
from cycode.logger import get_logger
6+
7+
if TYPE_CHECKING:
8+
from cycode.cyclient.scan_client import ScanClient
9+
10+
logger = get_logger('Aggregation Report URL')
11+
12+
13+
def _set_aggregation_report_url(ctx: typer.Context, aggregation_report_url: Optional[str] = None) -> None:
14+
ctx.obj['aggregation_report_url'] = aggregation_report_url
15+
16+
17+
def try_get_aggregation_report_url_if_needed(
18+
scan_parameters: dict, cycode_client: 'ScanClient', scan_type: str
19+
) -> Optional[str]:
20+
if not scan_parameters.get('report', False):
21+
return None
22+
23+
aggregation_id = scan_parameters.get('aggregation_id')
24+
if aggregation_id is None:
25+
return None
26+
27+
try:
28+
report_url_response = cycode_client.get_scan_aggregation_report_url(aggregation_id, scan_type)
29+
return report_url_response.report_url
30+
except Exception as e:
31+
logger.debug('Failed to get aggregation report url: %s', str(e))
32+
33+
34+
def try_set_aggregation_report_url_if_needed(
35+
ctx: typer.Context, scan_parameters: dict, cycode_client: 'ScanClient', scan_type: str
36+
) -> None:
37+
aggregation_report_url = try_get_aggregation_report_url_if_needed(scan_parameters, cycode_client, scan_type)
38+
if aggregation_report_url:
39+
_set_aggregation_report_url(ctx, aggregation_report_url)
40+
logger.debug('Aggregation report URL set successfully', {'aggregation_report_url': aggregation_report_url})
41+
else:
42+
logger.debug('No aggregation report URL found or report generation is disabled')

0 commit comments

Comments
 (0)