cycode 3.26.1.dev5__py3-none-any.whl → 3.27.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
cycode/__init__.py CHANGED
@@ -5,4 +5,4 @@ import time as _time
5
5
  # end-to-end scan duration from the moment the user actually triggered it.
6
6
  _BOOT_WALL: float = _time.time()
7
7
 
8
- __version__ = '3.26.1.dev5' # DON'T TOUCH. Placeholder. Will be filled automatically on poetry build from Git Tag
8
+ __version__ = '3.27.1' # DON'T TOUCH. Placeholder. Will be filled automatically on poetry build from Git Tag
@@ -121,26 +121,17 @@ def _should_use_sync_flow(command_scan_type: str, scan_type: str, sync_option: b
121
121
  Passing `--sync` option does not mean that sync flow will be used in all cases.
122
122
 
123
123
  The logic:
124
- - for IAC scan, sync flow is always used
125
- - for SAST scan, sync flow is not supported
126
- - for SCA and Secrets scan, sync flow is supported only for path/repository scan
124
+ - for IaC and SAST scans, the async flow is always used
125
+ - for SCA and Secrets scans, sync flow is used only with `--sync` on path/repository scans
127
126
 
128
127
  """
129
- if not sync_option and scan_type != consts.IAC_SCAN_TYPE:
128
+ if scan_type in {consts.IAC_SCAN_TYPE, consts.SAST_SCAN_TYPE}:
130
129
  return False
131
130
 
132
- if command_scan_type not in {'path', 'repository', 'ai_guardrails'}:
131
+ if not sync_option:
133
132
  return False
134
133
 
135
- if scan_type == consts.IAC_SCAN_TYPE:
136
- # sync in the only available flow for IAC scan; we do not use detector directly anymore
137
- return True
138
-
139
- if scan_type is consts.SAST_SCAN_TYPE: # noqa: SIM103
140
- # SAST does not support sync flow
141
- return False
142
-
143
- return True
134
+ return command_scan_type in {'path', 'repository', 'ai_guardrails'}
144
135
 
145
136
 
146
137
  def _get_scan_documents_thread_func(
@@ -1,6 +1,7 @@
1
1
  import os
2
2
  import platform
3
3
  import re
4
+ from pathlib import Path
4
5
 
5
6
  import typer
6
7
 
@@ -8,11 +9,17 @@ from cycode.cli.files_collector.sca.base_restore_dependencies import BaseRestore
8
9
  from cycode.cli.models import Document
9
10
  from cycode.cli.utils.path_utils import get_path_from_context
10
11
  from cycode.cli.utils.shell_executor import shell
12
+ from cycode.logger import get_logger
13
+
14
+ logger = get_logger('Gradle Restore')
11
15
 
12
16
  BUILD_GRADLE_FILE_NAME = 'build.gradle'
13
17
  BUILD_GRADLE_KTS_FILE_NAME = 'build.gradle.kts'
14
18
  BUILD_GRADLE_DEP_TREE_FILE_NAME = 'gradle-dependencies-generated.txt'
15
19
  ALL_PROJECTS_REGEX = r"[+-]{3} Project '(.*?)'"
20
+ PROJECT_LOCATION_REGEX = r"^project '(.+?)' - (.+?)\s*$"
21
+ CURRENT_PROJECT_REGEX = r"^Project '(.+?)'\s*$"
22
+ ROOT_PROJECT_PATH = ':'
16
23
 
17
24
  GRADLE_EXECUTABLE = 'gradle'
18
25
  GRADLEW_FILE_NAME = 'gradlew'
@@ -27,6 +34,7 @@ class RestoreGradleDependencies(BaseRestoreDependencies):
27
34
  self.gradle_executable = self._resolve_gradle_executable()
28
35
  if projects is None:
29
36
  projects = set()
37
+ self.project_locations: dict[Path, str] = {}
30
38
  self.projects = self.get_all_projects() if self.is_gradle_sub_projects() else projects
31
39
 
32
40
  def _resolve_gradle_executable(self) -> str:
@@ -45,11 +53,13 @@ class RestoreGradleDependencies(BaseRestoreDependencies):
45
53
  return document.path.endswith(BUILD_GRADLE_FILE_NAME) or document.path.endswith(BUILD_GRADLE_KTS_FILE_NAME)
46
54
 
47
55
  def get_commands(self, manifest_file_path: str) -> list[list[str]]:
48
- return (
49
- self.get_commands_for_sub_projects(manifest_file_path)
50
- if self.is_gradle_sub_projects()
51
- else [[self.gradle_executable, 'dependencies', '-b', manifest_file_path, '-q', '--console', 'plain']]
52
- )
56
+ if self.is_gradle_sub_projects():
57
+ return self.get_commands_for_sub_projects(manifest_file_path)
58
+
59
+ # Gradle finds the root settings file above it and selects the project whose projectDir
60
+ # is that directory.
61
+ manifest_dir = str(Path(manifest_file_path).parent)
62
+ return [[self.gradle_executable, '-p', manifest_dir, 'dependencies', '-q', '--console', 'plain']]
53
63
 
54
64
  def get_lock_file_name(self) -> str:
55
65
  return BUILD_GRADLE_DEP_TREE_FILE_NAME
@@ -61,21 +71,66 @@ class RestoreGradleDependencies(BaseRestoreDependencies):
61
71
  return get_path_from_context(self.ctx) if self.is_gradle_sub_projects() else None
62
72
 
63
73
  def get_all_projects(self) -> set[str]:
74
+ scan_root = get_path_from_context(self.ctx)
64
75
  output = shell(
65
76
  command=[self.gradle_executable, 'projects'],
66
77
  timeout=self.command_timeout,
67
- working_directory=get_path_from_context(self.ctx),
78
+ working_directory=scan_root,
68
79
  )
69
80
  if not output:
70
81
  return set()
71
82
 
83
+ if scan_root:
84
+ self.project_locations = self._parse_project_locations(output, Path(scan_root))
85
+
72
86
  return set(re.findall(ALL_PROJECTS_REGEX, output))
73
87
 
88
+ @staticmethod
89
+ def _parse_project_locations(output: str, scan_root: Path) -> dict[Path, str]:
90
+ """Map each project directory to its Gradle project path, from the "Project locations" section."""
91
+ # A location starts with a separator ("/x/y"). Strip it, or pathlib treats it as an absolute path.
92
+ relative_dirs = {
93
+ project_path: Path(relative_dir.lstrip('/\\'))
94
+ for project_path, relative_dir in re.findall(PROJECT_LOCATION_REGEX, output, flags=re.MULTILINE)
95
+ }
96
+ if not relative_dirs:
97
+ return {}
98
+
99
+ build_root = RestoreGradleDependencies._find_build_root(output, scan_root, relative_dirs)
100
+ locations = {(build_root / relative_dir).resolve(): path for path, relative_dir in relative_dirs.items()}
101
+ locations[build_root] = ROOT_PROJECT_PATH
102
+ return locations
103
+
104
+ @staticmethod
105
+ def _find_build_root(output: str, scan_root: Path, relative_dirs: dict[str, Path]) -> Path:
106
+ build_root = scan_root.resolve()
107
+ current_project = re.search(CURRENT_PROJECT_REGEX, output, flags=re.MULTILINE)
108
+ if current_project and current_project.group(1) in relative_dirs:
109
+ for _ in relative_dirs[current_project.group(1)].parts:
110
+ build_root = build_root.parent
111
+
112
+ return build_root
113
+
114
+ def _get_sub_project_path(self, manifest_file_path: str) -> str | None:
115
+ manifest_dir = Path(manifest_file_path).parent
116
+ if self.project_locations:
117
+ return self.project_locations.get(manifest_dir.resolve())
118
+
119
+ scan_root = get_path_from_context(self.ctx)
120
+ if self.projects and scan_root and manifest_dir.resolve() == Path(scan_root).resolve():
121
+ return ROOT_PROJECT_PATH
122
+
123
+ project_path = f':{manifest_dir.name}'
124
+ return project_path if project_path in self.projects else None
125
+
74
126
  def get_commands_for_sub_projects(self, manifest_file_path: str) -> list[list[str]]:
75
- project_name = os.path.basename(os.path.dirname(manifest_file_path))
76
- project_name = f':{project_name}'
77
- return (
78
- [[self.gradle_executable, f'{project_name}:dependencies', '-q', '--console', 'plain']]
79
- if project_name in self.projects
80
- else []
81
- )
127
+ project_path = self._get_sub_project_path(manifest_file_path)
128
+ if project_path is None:
129
+ logger.debug(
130
+ 'Manifest does not match a Gradle project, skipping restore, %s',
131
+ {'manifest_file_path': manifest_file_path},
132
+ )
133
+ return []
134
+
135
+ task = 'dependencies' if project_path == ROOT_PROJECT_PATH else f'{project_path}:dependencies'
136
+ return [[self.gradle_executable, task, '-q', '--console', 'plain']]
@@ -23,6 +23,8 @@ from cycode.cyclient.logger import logger
23
23
  if TYPE_CHECKING:
24
24
  from cycode.cyclient.scan_config_base import ScanConfigBase
25
25
 
26
+ _DETECTION_RULES_IDS_PER_REQUEST = 50
27
+
26
28
 
27
29
  class ScanClient:
28
30
  def __init__(
@@ -317,13 +319,18 @@ class ScanClient:
317
319
  return models.DetectionRuleSchema().load(response.json(), many=True)
318
320
 
319
321
  def get_detection_rules(self, detection_rules_ids: set[str] | list[str]) -> list[models.DetectionRule]:
320
- response = self.scan_cycode_client.get(
321
- url_path=self.get_detection_rules_path(),
322
- params={'ids': detection_rules_ids},
323
- hide_response_content_log=self._hide_response_log,
324
- )
322
+ # The ids go in the query string; too many of them exceed the URL limit (HTTP 414).
323
+ ids = list(detection_rules_ids)
324
+ detection_rules = []
325
+ for start in range(0, len(ids), _DETECTION_RULES_IDS_PER_REQUEST):
326
+ response = self.scan_cycode_client.get(
327
+ url_path=self.get_detection_rules_path(),
328
+ params={'ids': ids[start : start + _DETECTION_RULES_IDS_PER_REQUEST]},
329
+ hide_response_content_log=self._hide_response_log,
330
+ )
331
+ detection_rules.extend(self.parse_detection_rules_response(response))
325
332
 
326
- return self.parse_detection_rules_response(response)
333
+ return detection_rules
327
334
 
328
335
  def get_scan_detections_path(self) -> str:
329
336
  return f'{self.scan_config.get_detections_prefix()}/{self._DETECTIONS_SERVICE_CLI_CONTROLLER_PATH}'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cycode
3
- Version: 3.26.1.dev5
3
+ Version: 3.27.1
4
4
  Summary: Boost security in your dev lifecycle via SAST, SCA, Secrets & IaC scanning.
5
5
  License-Expression: MIT
6
6
  License-File: LICENCE
@@ -34,7 +34,7 @@ Requires-Dist: pywin32 (>=312,<313) ; sys_platform == "win32"
34
34
  Requires-Dist: pyyaml (>=6.0,<7.0)
35
35
  Requires-Dist: requests (>=2.33.0,<3.0)
36
36
  Requires-Dist: rich (>=15.0.0,<16.0.0)
37
- Requires-Dist: tenacity (>=9.1.2,<9.2.0)
37
+ Requires-Dist: tenacity (>=9.2.1,<9.3.0)
38
38
  Requires-Dist: tomli (>=2.0.0,<3.0.0) ; python_version < "3.11"
39
39
  Requires-Dist: tomli-w (>=1.0.0,<2.0.0)
40
40
  Requires-Dist: truststore (>=0.10.4,<0.11.0)
@@ -1,4 +1,4 @@
1
- cycode/__init__.py,sha256=41M2oydcxIQJhmjCmwskClQxPPLgQA1_ZX3j-oyCkyY,396
1
+ cycode/__init__.py,sha256=SpO5Y8TzEzxPRu5asIgsUlnvWxvwi2ICk7WPG-tyzB8,391
2
2
  cycode/__main__.py,sha256=Z3bD5yrA7yPvAChcADQrqCaZd0ChGI1gdiwALwbWJ6U,104
3
3
  cycode/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  cycode/cli/app.py,sha256=sI6wBHmfo7RchO9rnOXaQyUHRG9fm4r9aIduV4ZOD5c,10167
@@ -69,7 +69,7 @@ cycode/cli/apps/report_import/sbom/sbom_command.py,sha256=9P56i7RobFPrkd5MmsVNe8
69
69
  cycode/cli/apps/sca_options.py,sha256=wqe7dZUML_iiBUko74k7ngeGcV8sdCxIOB-s1Zy5l_Q,1650
70
70
  cycode/cli/apps/scan/__init__.py,sha256=qGKJ5Hn9X1mygsHsCX7PP7ksuxA2jwIHMZIwsDsrGvA,2537
71
71
  cycode/cli/apps/scan/aggregation_report.py,sha256=5fSsLM8UajstayR5f-teEcjK05nSr7G7OeegP8tqwwQ,1528
72
- cycode/cli/apps/scan/code_scanner.py,sha256=Ucklo5vQAKNsdtlNcwd1fkMzXlphRdkjOYqYvph0cgE,19740
72
+ cycode/cli/apps/scan/code_scanner.py,sha256=8Mm7OHxo6mfl4Z3ujtIS64WI_MfUuKM0XxrG1p7GTeE,19447
73
73
  cycode/cli/apps/scan/commit_history/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
74
74
  cycode/cli/apps/scan/commit_history/commit_history_command.py,sha256=zTVmN8yeLXGAiCbyDL-EyEzSPNLzcRpP2q6Qq7p4uZA,1011
75
75
  cycode/cli/apps/scan/commit_range_scanner.py,sha256=eoXfUNQKR-qjBYRV_M7FE6JGAztWe3yj432aBl-lM7s,17993
@@ -122,7 +122,7 @@ cycode/cli/files_collector/sca/base_restore_dependencies.py,sha256=8wMKoh15CYLcm
122
122
  cycode/cli/files_collector/sca/go/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
123
123
  cycode/cli/files_collector/sca/go/restore_go_dependencies.py,sha256=_i4UBfhQ97Z14OYxVj5iUuckMSiVtbw-vYCBOowIHKQ,1868
124
124
  cycode/cli/files_collector/sca/maven/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
125
- cycode/cli/files_collector/sca/maven/restore_gradle_dependencies.py,sha256=4ajpSFkVHgz1U_LBYTeK5U7zJ7B8wQMsaIhQPKrZv9w,3227
125
+ cycode/cli/files_collector/sca/maven/restore_gradle_dependencies.py,sha256=Gf7KO3VTwVfmUgkhYFDjIT8bTUmA_KdHrvE5n729XmI,5848
126
126
  cycode/cli/files_collector/sca/maven/restore_maven_dependencies.py,sha256=zaXirOpVDMiZRUVjQzrHoLBfUpeAdP3ol_whNBbXkCY,3966
127
127
  cycode/cli/files_collector/sca/npm/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
128
128
  cycode/cli/files_collector/sca/npm/restore_bun_dependencies.py,sha256=r5MdGsezSRNeBMhGwxF1sPUMGr27SrQQC72-W0Aokz8,4817
@@ -221,11 +221,11 @@ cycode/cyclient/import_sbom_client.py,sha256=AvEa6APERHGT-1v3LtENuekrse7tGgLr18D
221
221
  cycode/cyclient/logger.py,sha256=oTkay7QzoOIVQ71cGOy4ukkijYGA3IKJlHkL24Px5ds,70
222
222
  cycode/cyclient/models.py,sha256=4JjBL7kxkoztXvbFy9fy67JZ0U8z6bMDabp4HN9uQD0,17942
223
223
  cycode/cyclient/report_client.py,sha256=PaKEo6Q0GFVdpNC18vvR4uBoUX1MnllVmKkS72eAPmk,4368
224
- cycode/cyclient/scan_client.py,sha256=AZ-3G9eC8Y_-jjivllP7ESPpdLds0Dkl4-KIxe5jNyE,16944
224
+ cycode/cyclient/scan_client.py,sha256=ft80sGTsW-BW4bECuGdfLv0CrSdIkp_RLlGfwHVf_Fs,17325
225
225
  cycode/cyclient/scan_config_base.py,sha256=mXsPZGYCtp85rv5GIige40yQZXuRcEKUW-VQJ0vgFzk,1201
226
226
  cycode/logger.py,sha256=OHmfkf4dnyZgfixGqkWf3js3uysrOXU_4cS8TChtAzc,2079
227
- cycode-3.26.1.dev5.dist-info/METADATA,sha256=j6T4taDmDbSnaWE0MvFRzRlK6-JAohRO1jxLYF7-ty4,97032
228
- cycode-3.26.1.dev5.dist-info/WHEEL,sha256=L-WvLdSBvJWHXv5zrQxDvNRnIgoBzLUpcbuiw19KCuQ,88
229
- cycode-3.26.1.dev5.dist-info/entry_points.txt,sha256=iDcVJM8ByLElVgvBgtYxDjw1kT7O8Mo0LcWZIT5L3Ig,45
230
- cycode-3.26.1.dev5.dist-info/licenses/LICENCE,sha256=2Wx4N6mD_4xB7-E3hPkZ3MPhpJy__k_I8MaCSO-PDRo,1068
231
- cycode-3.26.1.dev5.dist-info/RECORD,,
227
+ cycode-3.27.1.dist-info/METADATA,sha256=5pKpKtOO-hhaWJp9wFykVIYVkW5l26JIMR-5nH2Whzg,97027
228
+ cycode-3.27.1.dist-info/WHEEL,sha256=L-WvLdSBvJWHXv5zrQxDvNRnIgoBzLUpcbuiw19KCuQ,88
229
+ cycode-3.27.1.dist-info/entry_points.txt,sha256=iDcVJM8ByLElVgvBgtYxDjw1kT7O8Mo0LcWZIT5L3Ig,45
230
+ cycode-3.27.1.dist-info/licenses/LICENCE,sha256=2Wx4N6mD_4xB7-E3hPkZ3MPhpJy__k_I8MaCSO-PDRo,1068
231
+ cycode-3.27.1.dist-info/RECORD,,