Skip to content

Commit e0ca3cd

Browse files
committed
added use_types, made alerts and score optional
1 parent 051f77c commit e0ca3cd

File tree

14 files changed

+437
-291
lines changed

14 files changed

+437
-291
lines changed

socketdev/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
__all__ = ["socketdev", "Utils", "IntegrationType", "INTEGRATION_TYPES"]
2424

2525

26-
2726
global encoded_key
2827
encoded_key: str
2928

@@ -32,6 +31,8 @@
3231
log = logging.getLogger("socketdev")
3332
log.addHandler(logging.NullHandler())
3433

34+
# TODO: Add debug flag to constructor to enable verbose error logging for API response parsing.
35+
3536

3637
class socketdev:
3738
def __init__(self, token: str, timeout: int = 1200):

socketdev/dependencies/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import json
22
from urllib.parse import urlencode
3-
3+
import logging
44
from socketdev.tools import load_files
55

6+
log = logging.getLogger("socketdev")
7+
8+
# TODO: Add types for responses. Not currently used in the CLI.
9+
610

711
class Dependencies:
812
def __init__(self, api):
@@ -17,7 +21,7 @@ def post(self, files: list, params: dict) -> dict:
1721
result = response.json()
1822
else:
1923
result = {}
20-
print(f"Error posting {files} to the Dependency API")
24+
log.error(f"Error posting {files} to the Dependency API")
2125
print(response.text)
2226
return result
2327

socketdev/export/__init__.py

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from urllib.parse import urlencode
22
from dataclasses import dataclass, asdict
33
from typing import Optional
4+
import logging
5+
6+
log = logging.getLogger("socketdev")
47

58

69
@dataclass
@@ -23,40 +26,50 @@ class Export:
2326
def __init__(self, api):
2427
self.api = api
2528

26-
def cdx_bom(self, org_slug: str, id: str, query_params: Optional[ExportQueryParams] = None) -> dict:
29+
def cdx_bom(
30+
self, org_slug: str, id: str, query_params: Optional[ExportQueryParams] = None, use_types: bool = False
31+
) -> dict:
2732
"""
2833
Export a Socket SBOM as a CycloneDX SBOM
2934
:param org_slug: String - The slug of the organization
3035
:param id: String - The id of either a full scan or an sbom report
3136
:param query_params: Optional[ExportQueryParams] - Query parameters for filtering
32-
:return:
37+
:param use_types: Optional[bool] - Whether to return typed responses
38+
:return: dict
3339
"""
3440
path = f"orgs/{org_slug}/export/cdx/{id}"
3541
if query_params:
3642
path += query_params.to_query_params()
3743
response = self.api.do_request(path=path)
38-
try:
39-
sbom = response.json()
40-
sbom["success"] = True
41-
except Exception as error:
42-
sbom = {"success": False, "message": str(error)}
43-
return sbom
44-
45-
def spdx_bom(self, org_slug: str, id: str, query_params: Optional[ExportQueryParams] = None) -> dict:
44+
45+
if response.status_code == 200:
46+
return response.json()
47+
# TODO: Add typed response when types are defined
48+
49+
log.error(f"Error exporting CDX BOM: {response.status_code}")
50+
print(response.text)
51+
return {}
52+
53+
def spdx_bom(
54+
self, org_slug: str, id: str, query_params: Optional[ExportQueryParams] = None, use_types: bool = False
55+
) -> dict:
4656
"""
4757
Export a Socket SBOM as an SPDX SBOM
4858
:param org_slug: String - The slug of the organization
4959
:param id: String - The id of either a full scan or an sbom report
5060
:param query_params: Optional[ExportQueryParams] - Query parameters for filtering
51-
:return:
61+
:param use_types: Optional[bool] - Whether to return typed responses
62+
:return: dict
5263
"""
5364
path = f"orgs/{org_slug}/export/spdx/{id}"
5465
if query_params:
5566
path += query_params.to_query_params()
5667
response = self.api.do_request(path=path)
57-
try:
58-
sbom = response.json()
59-
sbom["success"] = True
60-
except Exception as error:
61-
sbom = {"success": False, "message": str(error)}
62-
return sbom
68+
69+
if response.status_code == 200:
70+
return response.json()
71+
# TODO: Add typed response when types are defined
72+
73+
log.error(f"Error exporting SPDX BOM: {response.status_code}")
74+
print(response.text)
75+
return {}

0 commit comments

Comments
 (0)