Skip to content

Commit fb5c18d

Browse files
committed
Moved the logic for find_sbom_files to find_files to avoid code duplication. Left the new function in place and just called find_files with the optional params
1 parent 2838704 commit fb5c18d

File tree

4 files changed

+670
-591
lines changed

4 files changed

+670
-591
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
66

77
[project]
88
name = "socketsecurity"
9-
version = "2.2.44"
9+
version = "2.2.45"
1010
requires-python = ">= 3.10"
1111
license = {"file" = "LICENSE"}
1212
dependencies = [

socketsecurity/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
__author__ = 'socket.dev'
2-
__version__ = '2.2.44'
2+
__version__ = '2.2.45'
33
USER_AGENT = f'SocketPythonCLI/{__version__}'

socketsecurity/core/__init__.py

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,13 @@ def format_bytes(bytes_value):
281281
except Exception as e:
282282
log.error(f"Failed to save manifest tar.gz to {output_path}: {e}")
283283

284-
def find_files(self, path: str) -> List[str]:
284+
def find_files(self, path: str, ecosystems: Optional[List[str]] = None) -> List[str]:
285285
"""
286286
Finds supported manifest files in the given path.
287287
288288
Args:
289289
path: Path to search for manifest files.
290+
ecosystems: Optional list of ecosystems to include. If None, all ecosystems are included.
290291
291292
Returns:
292293
List of found manifest file paths.
@@ -299,6 +300,9 @@ def find_files(self, path: str) -> List[str]:
299300
patterns = self.get_supported_patterns()
300301

301302
for ecosystem in patterns:
303+
# If ecosystems filter is provided, only include specified ecosystems
304+
if ecosystems is not None and ecosystem not in ecosystems:
305+
continue
302306
if ecosystem in self.config.excluded_ecosystems:
303307
continue
304308
log.debug(f'Scanning ecosystem: {ecosystem}')
@@ -357,42 +361,8 @@ def find_sbom_files(self, path: str) -> List[str]:
357361
List of found CDX and SPDX file paths.
358362
"""
359363
log.debug("Starting Find SBOM Files (CDX and SPDX only)")
360-
files: Set[str] = set()
361-
362-
# Get supported patterns from the API and filter to only cdx and spdx
363-
all_patterns = self.get_supported_patterns()
364364
sbom_ecosystems = ['cdx', 'spdx']
365-
sbom_patterns = {k: v for k, v in all_patterns.items() if k in sbom_ecosystems}
366-
367-
if not sbom_patterns:
368-
log.warning("No CDX or SPDX patterns found in supported patterns from API")
369-
return []
370-
371-
for ecosystem in sbom_patterns:
372-
log.debug(f'Scanning for {ecosystem} files')
373-
ecosystem_patterns = sbom_patterns[ecosystem]
374-
for file_name in ecosystem_patterns:
375-
original_pattern = ecosystem_patterns[file_name]["pattern"]
376-
377-
# Expand brace patterns
378-
expanded_patterns = Core.expand_brace_pattern(original_pattern)
379-
380-
for pattern in expanded_patterns:
381-
case_insensitive_pattern = Core.to_case_insensitive_regex(pattern)
382-
file_path = os.path.join(path, "**", case_insensitive_pattern)
383-
384-
log.debug(f"Globbing {file_path}")
385-
glob_files = glob(file_path, recursive=True)
386-
387-
for glob_file in glob_files:
388-
if os.path.isfile(glob_file) and not Core.is_excluded(glob_file, self.config.excluded_dirs):
389-
files.add(glob_file.replace("\\", "/"))
390-
391-
file_list = sorted(files)
392-
file_count = len(file_list)
393-
log.info(f"Total SBOM files found (CDX/SPDX): {file_count}")
394-
395-
return file_list
365+
return self.find_files(path, ecosystems=sbom_ecosystems)
396366

397367
def get_supported_patterns(self) -> Dict:
398368
"""

0 commit comments

Comments
 (0)