Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies = [
'GitPython',
'packaging',
'python-dotenv',
'socket-sdk-python>=2.0.8'
'socket-sdk-python>=2.0.9'
]
readme = "README.md"
description = "Socket Security CLI for CI/CD"
Expand Down
2 changes: 1 addition & 1 deletion socketsecurity/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__author__ = 'socket.dev'
__version__ = '2.0.10'
__version__ = '2.0.11'
89 changes: 61 additions & 28 deletions socketsecurity/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ def create_sbom_output(self, diff: Diff) -> dict:
log.error(result.get("message", "No error message provided"))
return {}

@staticmethod
def find_files(path: str) -> List[str]:
def find_files(self, path: str) -> List[str]:
"""
Finds supported manifest files in the given path.

Expand All @@ -138,10 +137,19 @@ def find_files(path: str) -> List[str]:
start_time = time.time()
files = set()

for ecosystem in socket_globs:
patterns = socket_globs[ecosystem]
for file_name in patterns:
pattern = Core.to_case_insensitive_regex(patterns[file_name]["pattern"])
# Get supported patterns from the API
try:
patterns = self.get_supported_patterns()
except Exception as e:
log.error(f"Error getting supported patterns from API: {e}")
log.warning("Falling back to local patterns")
from .utils import socket_globs as fallback_patterns
patterns = fallback_patterns

for ecosystem in patterns:
ecosystem_patterns = patterns[ecosystem]
for file_name in ecosystem_patterns:
pattern = Core.to_case_insensitive_regex(ecosystem_patterns[file_name]["pattern"])
file_path = f"{path}/**/{pattern}"
#log.debug(f"Globbing {file_path}")
glob_start = time.time()
Expand All @@ -164,6 +172,53 @@ def find_files(path: str) -> List[str]:
log.debug(f"{len(files_list)} Files found ({total_time:.2f}s): {', '.join(files_list)}")
return list(files)

def get_supported_patterns(self) -> Dict:
"""
Gets supported file patterns from the Socket API.

Returns:
Dictionary of supported file patterns
"""
response = self.sdk.report.supported()
if not response:
log.error("Failed to get supported patterns from API")
# Import the old patterns as fallback
from .utils import socket_globs
return socket_globs

# The response is already in the format we need
return response

def has_manifest_files(self, files: list) -> bool:
"""
Checks if any files in the list are supported manifest files.

Args:
files: List of file paths to check

Returns:
True if any files match manifest patterns, False otherwise
"""
# Get supported patterns
try:
patterns = self.get_supported_patterns()
except Exception as e:
log.error(f"Error getting supported patterns from API: {e}")
log.warning("Falling back to local patterns")
from .utils import socket_globs as fallback_patterns
patterns = fallback_patterns

for ecosystem in patterns:
ecosystem_patterns = patterns[ecosystem]
for file_name in ecosystem_patterns:
pattern_str = ecosystem_patterns[file_name]["pattern"]
for file in files:
if "\\" in file:
file = file.replace("\\", "/")
if PurePath(file).match(pattern_str):
return True
return False

@staticmethod
def to_case_insensitive_regex(input_string: str) -> str:
"""
Expand Down Expand Up @@ -740,28 +795,6 @@ def save_file(file_name: str, content: str) -> None:
log.error(f"Failed to save file {file_name}: {e}")
raise

@staticmethod
def has_manifest_files(files: list) -> bool:
"""
Checks if any files in the list are supported manifest files.

Args:
files: List of file paths to check

Returns:
True if any files match manifest patterns, False otherwise
"""
for ecosystem in socket_globs:
patterns = socket_globs[ecosystem]
for file_name in patterns:
pattern = patterns[file_name]["pattern"]
for file in files:
if "\\" in file:
file = file.replace("\\", "/")
if PurePath(file).match(pattern):
return True
return False

@staticmethod
def get_capabilities_for_added_packages(added_packages: Dict[str, Package]) -> Dict[str, List[str]]:
"""
Expand Down
Loading