Skip to content

Commit b6ff01f

Browse files
committed
moving back to main to re-add SARIF
1 parent e6456e6 commit b6ff01f

File tree

2 files changed

+64
-11
lines changed

2 files changed

+64
-11
lines changed

socketsecurity/core/__init__.py

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ def create_full_scan(self, files: List[str], params: FullScanParams, store_resul
224224

225225
# Time the post API call
226226
post_start = time.time()
227+
227228
res = self.sdk.fullscans.post(files, params)
228229
post_end = time.time()
229230
log.debug(f"API fullscans.post took {post_end - post_start:.2f} seconds")
@@ -235,13 +236,32 @@ def create_full_scan(self, files: List[str], params: FullScanParams, store_resul
235236
full_scan = FullScan(**asdict(res.data))
236237

237238
if not store_results:
239+
log.debug("Skipping results storage as requested")
238240
full_scan.sbom_artifacts = []
239241
full_scan.packages = {}
240242
return full_scan
241243

244+
# Add extensive debug logging
245+
log.debug(f"Full scan created with ID: {full_scan.id}")
246+
log.debug(f"Organization slug: {self.config.org_slug}")
247+
log.debug(f"store_results is {store_results}")
248+
log.debug(f"Params used for scan: {params}")
249+
242250
# Time the stream API call
243251
stream_start = time.time()
244-
artifacts_response = self.sdk.fullscans.stream(self.config.org_slug, full_scan.id)
252+
log.debug(f"Initiating stream request for full scan {full_scan.id}")
253+
try:
254+
artifacts_response = self.sdk.fullscans.stream(self.config.org_slug, full_scan.id)
255+
log.debug(f"Stream response received: success={artifacts_response.success}")
256+
if hasattr(artifacts_response, 'status'):
257+
log.debug(f"Stream response status: {artifacts_response.status}")
258+
if hasattr(artifacts_response, 'message'):
259+
log.debug(f"Stream response message: {artifacts_response.message}")
260+
except Exception as e:
261+
log.error(f"Exception during stream request: {str(e)}")
262+
log.error(f"Exception type: {type(e)}")
263+
raise
264+
245265
stream_end = time.time()
246266
log.debug(f"API fullscans.stream took {stream_end - stream_start:.2f} seconds")
247267

@@ -254,11 +274,13 @@ def create_full_scan(self, files: List[str], params: FullScanParams, store_resul
254274

255275
# Store the original SocketArtifact objects
256276
full_scan.sbom_artifacts = list(artifacts_response.artifacts.values())
277+
log.debug(f"Retrieved {len(full_scan.sbom_artifacts)} artifacts")
257278

258279
# Create packages dictionary directly from the artifacts
259280
packages = {}
260281
top_level_count = {}
261282

283+
log.debug("Starting package processing from artifacts")
262284
for artifact in artifacts_response.artifacts.values():
263285
package = Package.from_socket_artifact(artifact)
264286
if package.id not in packages:
@@ -275,6 +297,7 @@ def create_full_scan(self, files: List[str], params: FullScanParams, store_resul
275297
package.transitives = top_level_count.get(package.id, 0)
276298

277299
full_scan.packages = packages
300+
log.debug(f"Processed {len(packages)} packages")
278301

279302
create_full_end = time.time()
280303
total_time = create_full_end - create_full_start
@@ -412,7 +435,7 @@ def get_added_and_removed_packages(self, head_full_scan_id: Optional[str], new_f
412435
# Process added and updated artifacts
413436
for artifact in chain(diff_report.artifacts.added, diff_report.artifacts.updated):
414437
try:
415-
pkg = Package.from_socket_artifact(artifact)
438+
pkg = Package.from_diff_artifact(artifact)
416439
added_packages[artifact.id] = pkg
417440
except KeyError as e:
418441
log.error(f"KeyError creating package from added artifact {artifact.id}: {e}")
@@ -457,6 +480,8 @@ def create_new_diff(
457480
pass
458481

459482
# Create new scan - only store results if we don't have a head scan to diff against
483+
if head_full_scan_id is None:
484+
log.debug("No head scan found to diff against")
460485
new_full_scan = self.create_full_scan(files_for_sending, params, store_results=head_full_scan_id is None)
461486

462487
added_packages, removed_packages = self.get_added_and_removed_packages(head_full_scan_id, new_full_scan)
@@ -595,26 +620,31 @@ def get_source_data(package: Package, packages: dict) -> list:
595620
introduced_by = []
596621
if package.direct:
597622
manifests = ""
598-
for manifest_data in package.manifestFiles:
599-
manifest_file = manifest_data.get("file")
600-
manifests += f"{manifest_file};"
601-
manifests = manifests.rstrip(";")
623+
if package.manifestFiles:
624+
for manifest_data in package.manifestFiles:
625+
manifest_file = manifest_data["file"]
626+
if manifest_file:
627+
manifests += f"{manifest_file};"
628+
manifests = manifests.rstrip(";")
602629
source = ("direct", manifests)
603630
introduced_by.append(source)
604631
else:
605-
for top_id in package.topLevelAncestors:
632+
for top_id in package.topLevelAncestors or []:
606633
top_package = packages.get(top_id)
607634
if top_package:
608635
manifests = ""
609636
top_purl = f"{top_package.type}/{top_package.name}@{top_package.version}"
610-
for manifest_data in top_package.manifestFiles:
611-
manifest_file = manifest_data.get("file")
612-
manifests += f"{manifest_file};"
613-
manifests = manifests.rstrip(";")
637+
if top_package.manifestFiles:
638+
for manifest_data in top_package.manifestFiles:
639+
manifest_file = manifest_data["file"]
640+
if manifest_file:
641+
manifests += f"{manifest_file};"
642+
manifests = manifests.rstrip(";")
614643
source = (top_purl, manifests)
615644
introduced_by.append(source)
616645
else:
617646
log.debug(f"Unable to get top level package info for {top_id}")
647+
618648
return introduced_by
619649

620650
@staticmethod

socketsecurity/core/utils.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,28 @@
8181
"pom.xml": {
8282
"pattern": "pom.xml"
8383
}
84+
},
85+
".net": {
86+
"proj": {
87+
"pattern": "*.*proj"
88+
},
89+
"props": {
90+
"pattern": "*.props"
91+
},
92+
"targets": {
93+
"pattern": "*.targets"
94+
},
95+
"nuspec": {
96+
"pattern": "*.nuspec"
97+
},
98+
"nugetConfig": {
99+
"pattern": "nuget.config"
100+
},
101+
"packagesConfig": {
102+
"pattern": "packages.config"
103+
},
104+
"packagesLock": {
105+
"pattern": "packages.lock.json"
106+
}
84107
}
85108
}

0 commit comments

Comments
 (0)