Skip to content

Bumped version for release #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2025
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "hatchling.build"

[project]
name = "socketsecurity"
version = "2.0.33"
version = "2.0.34"
requires-python = ">= 3.10"
license = {"file" = "LICENSE"}
dependencies = [
Expand Down
2 changes: 1 addition & 1 deletion socketsecurity/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__author__ = 'socket.dev'
__version__ = '2.0.33'
__version__ = '2.0.34'

21 changes: 12 additions & 9 deletions socketsecurity/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,17 @@ def get_org_id_slug(self) -> Tuple[str, str]:
return org_id, organizations[org_id]['slug']
return None, None

def get_sbom_data(self, full_scan_id: str) -> Dict[str, SocketArtifact]:
def get_sbom_data(self, full_scan_id: str) -> List[SocketArtifact]:
"""Returns the list of SBOM artifacts for a full scan."""
response = self.sdk.fullscans.stream(self.config.org_slug, full_scan_id, use_types=True)
artifacts: List[SocketArtifact] = []
if not response.success:
log.debug(f"Failed to get SBOM data for full-scan {full_scan_id}")
log.debug(response.message)
return {}

return response.artifacts
for artifact_id in response.artifacts:
artifacts.append(response.artifacts[artifact_id])
return artifacts

def get_sbom_data_list(self, artifacts_dict: Dict[str, SocketArtifact]) -> list[SocketArtifact]:
"""Converts artifacts dictionary to a list."""
Expand Down Expand Up @@ -326,8 +328,7 @@ def create_full_scan(self, files: List[str], params: FullScanParams, has_head_sc

full_scan = FullScan(**asdict(res.data))
if not has_head_scan:
full_scan_artifacts_dict = self.get_sbom_data(full_scan.id)
full_scan.sbom_artifacts = self.get_sbom_data_list(full_scan_artifacts_dict)
full_scan.sbom_artifacts = self.get_sbom_data(full_scan.id)
full_scan.packages = self.create_packages_dict(full_scan.sbom_artifacts)

create_full_end = time.time()
Expand Down Expand Up @@ -436,7 +437,8 @@ def get_repo_info(self, repo_slug: str, default_branch: str = "socket-default-br
log.error("Failed to create repository: empty response")
raise Exception("Failed to create repository: empty response")
else:
return create_response
response = self.sdk.repos.repo(self.config.org_slug, repo_slug, use_types=True)
return response.data

except APIFailure as e:
log.error(f"API failure while creating repository: {e}")
Expand Down Expand Up @@ -554,22 +556,23 @@ def create_new_diff(
# Find manifest files
files = self.find_files(path)
files_for_sending = self.load_files_for_sending(files, path)

has_head_scan = False
if not files:
return Diff(id="no_diff_id")

try:
# Get head scan ID
head_full_scan_id = self.get_head_scan_for_repo(params.repo)
has_head_scan = True
if head_full_scan_id is not None:
has_head_scan = True
except APIResourceNotFound:
head_full_scan_id = None
has_head_scan = False

# Create new scan
try:
new_scan_start = time.time()
new_full_scan = self.create_full_scan(files_for_sending, params, has_head_scan)
new_full_scan.sbom_artifacts = self.get_sbom_data(new_full_scan.id)
new_scan_end = time.time()
log.info(f"Total time to create new full scan: {new_scan_end - new_scan_start:.2f}")
except APIFailure as e:
Expand Down
12 changes: 11 additions & 1 deletion socketsecurity/core/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ def from_socket_artifact(cls, data: dict) -> "Package":
Returns:
New Package instance
"""
purl = f"{data['type']}/"
namespace = data.get("namespace")
if namespace:
purl += f"{namespace}@"
purl += f"{data['name']}@{data['version']}"
base_url = "https://socket.dev"
url = f"{base_url}/{data['type']}/package/{namespace or ''}{data['name']}/overview/{data['version']}"
return cls(
id=data["id"],
name=data["name"],
Expand All @@ -152,7 +159,10 @@ def from_socket_artifact(cls, data: dict) -> "Package":
direct=data.get("direct", False),
manifestFiles=data.get("manifestFiles", []),
dependencies=data.get("dependencies"),
artifact=data.get("artifact")
artifact=data.get("artifact"),
purl=purl,
url=url,
namespace=namespace
)

@classmethod
Expand Down
Loading