Skip to content

Commit c7f5781

Browse files
authored
CM-24707 - Fix dependency paths to add continuation dependencies sign for the list greater than 2 (#131)
* CM-24707 [SCA-CLI] fixing dependency paths to add continuation dependencies for list greater than 2 * CM-24707 - Fix dependency paths to add continuation dependencies sign for the list greater than 2 * CM-24707 - Fix dependency paths to add continuation dependencies sign for the list greater than 2 * CM-24707 - Fix dependency paths to add continuation dependencies sign for the list greater than 2 * CM-24707 - Fix dependency paths to add continuation dependencies sign for the list greater than 2
1 parent a4b13fb commit c7f5781

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

cycode/cli/consts.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,8 @@
126126

127127
LICENSE_COMPLIANCE_POLICY_ID = '8f681450-49e1-4f7e-85b7-0c8fe84b3a35'
128128
PACKAGE_VULNERABILITY_POLICY_ID = '9369d10a-9ac0-48d3-9921-5de7fe9a37a7'
129+
130+
# Shortcut dependency paths by remove all middle depndencies between direct dependency and influence/vulnerable dependency.
131+
# Example: A -> B -> C
132+
# Result: A -> ... -> C
133+
SCA_SHORTCUT_DEPENDENCY_PATHS = 2

cycode/cli/printers/sca_table_printer.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from cycode.cli.consts import LICENSE_COMPLIANCE_POLICY_ID, PACKAGE_VULNERABILITY_POLICY_ID
88
from cycode.cli.models import DocumentDetections, Detection
99
from cycode.cli.printers.base_table_printer import BaseTablePrinter
10+
from cycode.cli.utils.string_utils import shortcut_dependency_paths
1011

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

111-
@staticmethod
112-
def _shortcut_dependency_paths(dependency_paths: str) -> str:
113-
dependencies = dependency_paths.split(' -> ')
114-
115-
if len(dependencies) < 2:
116-
return dependencies[0]
117-
118-
return f'{dependencies[0]} -> ... -> {dependencies[-1]}'
119-
120112
def _get_common_detection_fields(self, detection: Detection) -> List[str]:
121113
dependency_paths = 'N/A'
122114
dependency_paths_raw = detection.detection_details.get('dependency_paths')
123115
if dependency_paths_raw:
124-
dependency_paths = self._shortcut_dependency_paths(dependency_paths_raw)
116+
dependency_paths = shortcut_dependency_paths(dependency_paths_raw)
125117

126118
row = [
127119
detection.detection_details.get('file_name'),
128120
detection.detection_details.get('ecosystem'),
129121
detection.detection_details.get('package_name'),
130122
detection.detection_details.get('is_direct_dependency_str'),
131123
detection.detection_details.get('is_dev_dependency_str'),
132-
dependency_paths,
124+
dependency_paths
133125
]
134126

135127
if self._is_git_repository():

cycode/cli/utils/string_utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from sys import getsizeof
77
from binaryornot.check import is_binary_string
88

9+
from cycode.cli.consts import SCA_SHORTCUT_DEPENDENCY_PATHS
10+
911

1012
def obfuscate_text(text: str) -> str:
1113
match_len = len(text)
@@ -47,3 +49,18 @@ def generate_random_string(string_len: int):
4749

4850
def get_position_in_line(text: str, position: int) -> int:
4951
return position - text.rfind('\n', 0, position) - 1
52+
53+
54+
def shortcut_dependency_paths(dependency_paths_list: str) -> str:
55+
separate_dependency_paths_list = dependency_paths_list.split(',')
56+
result = ''
57+
for dependency_paths in separate_dependency_paths_list:
58+
dependency_paths = dependency_paths.strip().rstrip()
59+
dependencies = dependency_paths.split(' -> ')
60+
if len(dependencies) <= SCA_SHORTCUT_DEPENDENCY_PATHS:
61+
result += dependency_paths
62+
else:
63+
result += f'{dependencies[0]} -> ... -> {dependencies[-1]}'
64+
result += '\n\n'
65+
66+
return result.rstrip().rstrip(',')

tests/utils/test_string_utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from cycode.cli.utils.string_utils import shortcut_dependency_paths
2+
3+
4+
def test_shortcut_dependency_paths_list_single_dependencies():
5+
dependency_paths = "A, A -> B, A -> B -> C"
6+
expected_result = "A\n\nA -> B\n\nA -> ... -> C"
7+
assert shortcut_dependency_paths(dependency_paths) == expected_result

0 commit comments

Comments
 (0)