Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cycode/cli/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,8 @@

LICENSE_COMPLIANCE_POLICY_ID = '8f681450-49e1-4f7e-85b7-0c8fe84b3a35'
PACKAGE_VULNERABILITY_POLICY_ID = '9369d10a-9ac0-48d3-9921-5de7fe9a37a7'

# Shortcut dependency paths by remove all middle depndencies between direct dependency and influence/vulnerable dependency.
# Example: A -> B -> C
# Result: A -> ... -> C
SCA_SHORTCUT_DEPENDENCY_PATHS = 2
14 changes: 3 additions & 11 deletions cycode/cli/printers/sca_table_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from cycode.cli.consts import LICENSE_COMPLIANCE_POLICY_ID, PACKAGE_VULNERABILITY_POLICY_ID
from cycode.cli.models import DocumentDetections, Detection
from cycode.cli.printers.base_table_printer import BaseTablePrinter
from cycode.cli.utils.string_utils import shortcut_dependency_paths

SEVERITY_COLUMN = 'Severity'
LICENSE_COLUMN = 'License'
Expand Down Expand Up @@ -108,28 +109,19 @@ def set_table_width(headers: List[str], text_table: Texttable) -> None:
def _print_summary_issues(detections: List, title: str) -> None:
click.echo(f'⛔ Found {len(detections)} issues of type: {click.style(title, bold=True)}')

@staticmethod
def _shortcut_dependency_paths(dependency_paths: str) -> str:
dependencies = dependency_paths.split(' -> ')

if len(dependencies) < 2:
return dependencies[0]

return f'{dependencies[0]} -> ... -> {dependencies[-1]}'

def _get_common_detection_fields(self, detection: Detection) -> List[str]:
dependency_paths = 'N/A'
dependency_paths_raw = detection.detection_details.get('dependency_paths')
if dependency_paths_raw:
dependency_paths = self._shortcut_dependency_paths(dependency_paths_raw)
dependency_paths = shortcut_dependency_paths(dependency_paths_raw)

row = [
detection.detection_details.get('file_name'),
detection.detection_details.get('ecosystem'),
detection.detection_details.get('package_name'),
detection.detection_details.get('is_direct_dependency_str'),
detection.detection_details.get('is_dev_dependency_str'),
dependency_paths,
dependency_paths
]

if self._is_git_repository():
Expand Down
17 changes: 17 additions & 0 deletions cycode/cli/utils/string_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from sys import getsizeof
from binaryornot.check import is_binary_string

from cycode.cli.consts import SCA_SHORTCUT_DEPENDENCY_PATHS


def obfuscate_text(text: str) -> str:
match_len = len(text)
Expand Down Expand Up @@ -47,3 +49,18 @@ def generate_random_string(string_len: int):

def get_position_in_line(text: str, position: int) -> int:
return position - text.rfind('\n', 0, position) - 1


def shortcut_dependency_paths(dependency_paths_list: str) -> str:
separate_dependency_paths_list = dependency_paths_list.split(',')
result = ''
for dependency_paths in separate_dependency_paths_list:
dependency_paths = dependency_paths.strip().rstrip()
dependencies = dependency_paths.split(' -> ')
if len(dependencies) <= SCA_SHORTCUT_DEPENDENCY_PATHS:
result += dependency_paths
else:
result += f'{dependencies[0]} -> ... -> {dependencies[-1]}'
result += '\n\n'

return result.rstrip().rstrip(',')
7 changes: 7 additions & 0 deletions tests/utils/test_string_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from cycode.cli.utils.string_utils import shortcut_dependency_paths


def test_shortcut_dependency_paths_list_single_dependencies():
dependency_paths = "A, A -> B, A -> B -> C"
expected_result = "A\n\nA -> B\n\nA -> ... -> C"
assert shortcut_dependency_paths(dependency_paths) == expected_result