diff --git a/pyproject.toml b/pyproject.toml index ef2a2d2..2bfa41f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = [ diff --git a/socketsecurity/__init__.py b/socketsecurity/__init__.py index 948d0ca..6bdd25c 100644 --- a/socketsecurity/__init__.py +++ b/socketsecurity/__init__.py @@ -1,3 +1,3 @@ __author__ = 'socket.dev' -__version__ = '2.0.33' +__version__ = '2.0.34' diff --git a/socketsecurity/core/__init__.py b/socketsecurity/core/__init__.py index d6d9805..23466bd 100644 --- a/socketsecurity/core/__init__.py +++ b/socketsecurity/core/__init__.py @@ -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.""" @@ -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() @@ -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}") @@ -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: diff --git a/socketsecurity/core/classes.py b/socketsecurity/core/classes.py index 006bb0c..416cd06 100644 --- a/socketsecurity/core/classes.py +++ b/socketsecurity/core/classes.py @@ -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"], @@ -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