socketdev 3.0.2__py3-none-any.whl → 3.0.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- socketdev/__init__.py +10 -0
- socketdev/alerttypes/__init__.py +38 -0
- socketdev/analytics/__init__.py +64 -0
- socketdev/apitokens/__init__.py +126 -0
- socketdev/auditlog/__init__.py +30 -0
- socketdev/core/dedupe.py +28 -33
- socketdev/dependencies/__init__.py +16 -11
- socketdev/diffscans/__init__.py +3 -2
- socketdev/fullscans/__init__.py +13 -4
- socketdev/purl/__init__.py +1 -1
- socketdev/report/__init__.py +19 -4
- socketdev/threatfeed/__init__.py +37 -0
- socketdev/utils/__init__.py +30 -8
- socketdev/version.py +1 -1
- {socketdev-3.0.2.dist-info → socketdev-3.0.5.dist-info}/METADATA +372 -33
- {socketdev-3.0.2.dist-info → socketdev-3.0.5.dist-info}/RECORD +18 -16
- {socketdev-3.0.2.dist-info → socketdev-3.0.5.dist-info}/WHEEL +0 -0
- {socketdev-3.0.2.dist-info → socketdev-3.0.5.dist-info}/licenses/LICENSE +0 -0
socketdev/__init__.py
CHANGED
|
@@ -19,6 +19,11 @@ from socketdev.utils import Utils, IntegrationType, INTEGRATION_TYPES
|
|
|
19
19
|
from socketdev.version import __version__
|
|
20
20
|
from socketdev.labels import Labels
|
|
21
21
|
from socketdev.licensemetadata import LicenseMetadata
|
|
22
|
+
from socketdev.threatfeed import ThreatFeed
|
|
23
|
+
from socketdev.apitokens import ApiTokens
|
|
24
|
+
from socketdev.auditlog import AuditLog
|
|
25
|
+
from socketdev.analytics import Analytics
|
|
26
|
+
from socketdev.alerttypes import AlertTypes
|
|
22
27
|
from socketdev.log import log
|
|
23
28
|
|
|
24
29
|
__author__ = "socket.dev"
|
|
@@ -62,6 +67,11 @@ class socketdev:
|
|
|
62
67
|
self.labels = Labels(self.api)
|
|
63
68
|
self.licensemetadata = LicenseMetadata(self.api)
|
|
64
69
|
self.diffscans = DiffScans(self.api)
|
|
70
|
+
self.threatfeed = ThreatFeed(self.api)
|
|
71
|
+
self.apitokens = ApiTokens(self.api)
|
|
72
|
+
self.auditlog = AuditLog(self.api)
|
|
73
|
+
self.analytics = Analytics(self.api)
|
|
74
|
+
self.alerttypes = AlertTypes(self.api)
|
|
65
75
|
|
|
66
76
|
@staticmethod
|
|
67
77
|
def set_timeout(timeout: int):
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import json
|
|
3
|
+
from urllib.parse import urlencode
|
|
4
|
+
|
|
5
|
+
log = logging.getLogger("socketdev")
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class AlertTypes:
|
|
9
|
+
def __init__(self, api):
|
|
10
|
+
self.api = api
|
|
11
|
+
|
|
12
|
+
def get(self, alert_types: list = None, language: str = "en-US", **kwargs) -> dict:
|
|
13
|
+
"""
|
|
14
|
+
Get alert types metadata.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
alert_types: List of alert type strings to get metadata for
|
|
18
|
+
language: Language for alert metadata (default: en-US)
|
|
19
|
+
**kwargs: Additional query parameters
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
dict: API response containing alert types metadata
|
|
23
|
+
"""
|
|
24
|
+
path = "alert-types"
|
|
25
|
+
query_params = {"language": language}
|
|
26
|
+
query_params.update(kwargs)
|
|
27
|
+
|
|
28
|
+
if query_params:
|
|
29
|
+
path += "?" + urlencode(query_params)
|
|
30
|
+
|
|
31
|
+
payload = json.dumps(alert_types or [])
|
|
32
|
+
response = self.api.do_request(path=path, method="POST", payload=payload)
|
|
33
|
+
|
|
34
|
+
if response.status_code == 200:
|
|
35
|
+
return response.json()
|
|
36
|
+
log.error(f"Error getting alert types: {response.status_code}")
|
|
37
|
+
log.error(response.text)
|
|
38
|
+
return {}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from urllib.parse import urlencode
|
|
3
|
+
|
|
4
|
+
log = logging.getLogger("socketdev")
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Analytics:
|
|
8
|
+
def __init__(self, api):
|
|
9
|
+
self.api = api
|
|
10
|
+
|
|
11
|
+
def get_org(self, filter: str, **kwargs) -> list:
|
|
12
|
+
"""
|
|
13
|
+
Get organization analytics (deprecated).
|
|
14
|
+
|
|
15
|
+
**DEPRECATED**: Use the Historical module methods instead:
|
|
16
|
+
- sdk.historical.alerts_trend() for alerts analytics
|
|
17
|
+
- sdk.historical.dependencies_trend() for dependencies analytics
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
filter: Analytics filter type
|
|
21
|
+
**kwargs: Additional query parameters
|
|
22
|
+
|
|
23
|
+
Returns:
|
|
24
|
+
list: API response containing analytics data
|
|
25
|
+
"""
|
|
26
|
+
log.warning("Analytics.get_org() is deprecated. Use Historical module methods instead.")
|
|
27
|
+
path = f"analytics/org/{filter}"
|
|
28
|
+
if kwargs:
|
|
29
|
+
path += "?" + urlencode(kwargs)
|
|
30
|
+
|
|
31
|
+
response = self.api.do_request(path=path)
|
|
32
|
+
if response.status_code == 200:
|
|
33
|
+
return response.json()
|
|
34
|
+
log.error(f"Error getting org analytics: {response.status_code}")
|
|
35
|
+
log.error(response.text)
|
|
36
|
+
return []
|
|
37
|
+
|
|
38
|
+
def get_repo(self, name: str, filter: str, **kwargs) -> list:
|
|
39
|
+
"""
|
|
40
|
+
Get repository analytics (deprecated).
|
|
41
|
+
|
|
42
|
+
**DEPRECATED**: Use the Historical module methods instead:
|
|
43
|
+
- sdk.historical.alerts_trend() for alerts analytics
|
|
44
|
+
- sdk.historical.dependencies_trend() for dependencies analytics
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
name: Repository name
|
|
48
|
+
filter: Analytics filter type
|
|
49
|
+
**kwargs: Additional query parameters
|
|
50
|
+
|
|
51
|
+
Returns:
|
|
52
|
+
list: API response containing analytics data
|
|
53
|
+
"""
|
|
54
|
+
log.warning("Analytics.get_repo() is deprecated. Use Historical module methods instead.")
|
|
55
|
+
path = f"analytics/repo/{name}/{filter}"
|
|
56
|
+
if kwargs:
|
|
57
|
+
path += "?" + urlencode(kwargs)
|
|
58
|
+
|
|
59
|
+
response = self.api.do_request(path=path)
|
|
60
|
+
if response.status_code == 200:
|
|
61
|
+
return response.json()
|
|
62
|
+
log.error(f"Error getting repo analytics: {response.status_code}")
|
|
63
|
+
log.error(response.text)
|
|
64
|
+
return []
|
socketdev/apitokens/__init__.py
CHANGED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
log = logging.getLogger("socketdev")
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ApiTokens:
|
|
8
|
+
def __init__(self, api):
|
|
9
|
+
self.api = api
|
|
10
|
+
|
|
11
|
+
def create(self, org_slug: str, **kwargs) -> dict:
|
|
12
|
+
"""
|
|
13
|
+
Create a new API token.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
org_slug: Organization slug
|
|
17
|
+
**kwargs: Token configuration parameters
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
dict: API response containing the created token details
|
|
21
|
+
"""
|
|
22
|
+
path = f"orgs/{org_slug}/api-tokens"
|
|
23
|
+
payload = json.dumps(kwargs) if kwargs else "{}"
|
|
24
|
+
response = self.api.do_request(path=path, method="POST", payload=payload)
|
|
25
|
+
if response.status_code == 201:
|
|
26
|
+
return response.json()
|
|
27
|
+
log.error(f"Error creating API token: {response.status_code}")
|
|
28
|
+
log.error(response.text)
|
|
29
|
+
return {}
|
|
30
|
+
|
|
31
|
+
def list(self, org_slug: str, **kwargs) -> dict:
|
|
32
|
+
"""
|
|
33
|
+
List API tokens for an organization.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
org_slug: Organization slug
|
|
37
|
+
**kwargs: Query parameters
|
|
38
|
+
|
|
39
|
+
Returns:
|
|
40
|
+
dict: API response containing list of tokens
|
|
41
|
+
"""
|
|
42
|
+
path = f"orgs/{org_slug}/api-tokens"
|
|
43
|
+
query_params = {}
|
|
44
|
+
if kwargs:
|
|
45
|
+
query_params.update(kwargs)
|
|
46
|
+
|
|
47
|
+
if query_params:
|
|
48
|
+
from urllib.parse import urlencode
|
|
49
|
+
path += "?" + urlencode(query_params)
|
|
50
|
+
response = self.api.do_request(path=path, method="GET")
|
|
51
|
+
if response.status_code == 200:
|
|
52
|
+
return response.json()
|
|
53
|
+
log.error(f"Error listing API tokens: {response.status_code}")
|
|
54
|
+
log.error(response.text)
|
|
55
|
+
return {}
|
|
56
|
+
|
|
57
|
+
def update(self, org_slug: str, token_id: str = None, **kwargs) -> dict:
|
|
58
|
+
"""
|
|
59
|
+
Update an API token.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
org_slug: Organization slug
|
|
63
|
+
token_id: Token ID to update (optional, can be in kwargs)
|
|
64
|
+
**kwargs: Token update parameters
|
|
65
|
+
|
|
66
|
+
Returns:
|
|
67
|
+
dict: API response containing the updated token details
|
|
68
|
+
"""
|
|
69
|
+
# Extract token_id from kwargs if not provided as parameter
|
|
70
|
+
if token_id is None and 'token_id' in kwargs:
|
|
71
|
+
token_id = kwargs.pop('token_id')
|
|
72
|
+
|
|
73
|
+
if token_id:
|
|
74
|
+
path = f"orgs/{org_slug}/api-tokens/{token_id}"
|
|
75
|
+
method = "PUT"
|
|
76
|
+
else:
|
|
77
|
+
path = f"orgs/{org_slug}/api-tokens/update"
|
|
78
|
+
method = "POST"
|
|
79
|
+
|
|
80
|
+
payload = json.dumps(kwargs) if kwargs else "{}"
|
|
81
|
+
response = self.api.do_request(path=path, method=method, payload=payload)
|
|
82
|
+
if response.status_code == 200:
|
|
83
|
+
return response.json()
|
|
84
|
+
log.error(f"Error updating API token: {response.status_code}")
|
|
85
|
+
log.error(response.text)
|
|
86
|
+
return {}
|
|
87
|
+
|
|
88
|
+
def rotate(self, org_slug: str, **kwargs) -> dict:
|
|
89
|
+
"""
|
|
90
|
+
Rotate an API token.
|
|
91
|
+
|
|
92
|
+
Args:
|
|
93
|
+
org_slug: Organization slug
|
|
94
|
+
**kwargs: Token rotation parameters
|
|
95
|
+
|
|
96
|
+
Returns:
|
|
97
|
+
dict: API response containing the rotated token details
|
|
98
|
+
"""
|
|
99
|
+
path = f"orgs/{org_slug}/api-tokens/rotate"
|
|
100
|
+
payload = json.dumps(kwargs) if kwargs else "{}"
|
|
101
|
+
response = self.api.do_request(path=path, method="POST", payload=payload)
|
|
102
|
+
if response.status_code == 200:
|
|
103
|
+
return response.json()
|
|
104
|
+
log.error(f"Error rotating API token: {response.status_code}")
|
|
105
|
+
log.error(response.text)
|
|
106
|
+
return {}
|
|
107
|
+
|
|
108
|
+
def revoke(self, org_slug: str, **kwargs) -> dict:
|
|
109
|
+
"""
|
|
110
|
+
Revoke an API token.
|
|
111
|
+
|
|
112
|
+
Args:
|
|
113
|
+
org_slug: Organization slug
|
|
114
|
+
**kwargs: Token revocation parameters
|
|
115
|
+
|
|
116
|
+
Returns:
|
|
117
|
+
dict: API response confirming token revocation
|
|
118
|
+
"""
|
|
119
|
+
path = f"orgs/{org_slug}/api-tokens/revoke"
|
|
120
|
+
payload = json.dumps(kwargs) if kwargs else "{}"
|
|
121
|
+
response = self.api.do_request(path=path, method="POST", payload=payload)
|
|
122
|
+
if response.status_code == 200:
|
|
123
|
+
return response.json()
|
|
124
|
+
log.error(f"Error revoking API token: {response.status_code}")
|
|
125
|
+
log.error(response.text)
|
|
126
|
+
return {}
|
socketdev/auditlog/__init__.py
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
log = logging.getLogger("socketdev")
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class AuditLog:
|
|
7
|
+
def __init__(self, api):
|
|
8
|
+
self.api = api
|
|
9
|
+
|
|
10
|
+
def get(self, org_slug: str, **kwargs) -> dict:
|
|
11
|
+
"""
|
|
12
|
+
Get audit log entries for an organization.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
org_slug: Organization slug
|
|
16
|
+
**kwargs: Query parameters like limit, cursor, etc.
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
dict: API response containing audit log entries
|
|
20
|
+
"""
|
|
21
|
+
path = f"orgs/{org_slug}/audit-log"
|
|
22
|
+
if kwargs:
|
|
23
|
+
from urllib.parse import urlencode
|
|
24
|
+
path += "?" + urlencode(kwargs)
|
|
25
|
+
response = self.api.do_request(path=path)
|
|
26
|
+
if response.status_code == 200:
|
|
27
|
+
return response.json()
|
|
28
|
+
log.error(f"Error getting audit log: {response.status_code}")
|
|
29
|
+
log.error(response.text)
|
|
30
|
+
return {"results": []}
|
socketdev/core/dedupe.py
CHANGED
|
@@ -88,40 +88,35 @@ class Dedupe:
|
|
|
88
88
|
|
|
89
89
|
@staticmethod
|
|
90
90
|
def dedupe(packages: List[Dict[str, Any]], batched: bool = True) -> List[Dict[str, Any]]:
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
91
|
+
# Always group by inputPurl now, but keep the batched parameter for backward compatibility
|
|
92
|
+
grouped = Dedupe.consolidate_by_input_purl(packages)
|
|
93
|
+
results = []
|
|
94
|
+
for group in grouped.values():
|
|
95
|
+
result = Dedupe.consolidate_and_merge_alerts(group)
|
|
96
|
+
# Remove batchIndex from the result
|
|
97
|
+
if "batchIndex" in result:
|
|
98
|
+
del result["batchIndex"]
|
|
99
|
+
results.append(result)
|
|
100
|
+
return results
|
|
96
101
|
|
|
97
102
|
@staticmethod
|
|
98
|
-
def
|
|
99
|
-
|
|
103
|
+
def consolidate_by_input_purl(packages: List[Dict[str, Any]]) -> dict[str, list[dict[str, Any]]]:
|
|
104
|
+
"""Group packages by their inputPurl field"""
|
|
105
|
+
grouped: Dict[str, List[Dict[str, Any]]] = defaultdict(list)
|
|
106
|
+
|
|
107
|
+
# Handle both list of packages and nested structure
|
|
108
|
+
if packages and isinstance(packages[0], list):
|
|
109
|
+
# If we get a nested list, flatten it
|
|
110
|
+
flat_packages = []
|
|
111
|
+
for sublist in packages:
|
|
112
|
+
if isinstance(sublist, list):
|
|
113
|
+
flat_packages.extend(sublist)
|
|
114
|
+
else:
|
|
115
|
+
flat_packages.append(sublist)
|
|
116
|
+
packages = flat_packages
|
|
117
|
+
|
|
100
118
|
for pkg in packages:
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
@staticmethod
|
|
105
|
-
def consolidate_by_order(packages: List[Dict[str, Any]]) -> dict[int, list[dict[str, Any]]]:
|
|
106
|
-
grouped: Dict[int, List[Dict[str, Any]]] = defaultdict(list)
|
|
107
|
-
batch_index = 0
|
|
108
|
-
package_purl = None
|
|
109
|
-
try:
|
|
110
|
-
for pkg in packages:
|
|
111
|
-
name = pkg["name"]
|
|
112
|
-
version = pkg["version"]
|
|
113
|
-
namespace = pkg.get("namespace")
|
|
114
|
-
ecosystem = pkg.get("type")
|
|
115
|
-
new_purl = f"pkg:{ecosystem}/"
|
|
116
|
-
if namespace:
|
|
117
|
-
new_purl += f"{namespace}/"
|
|
118
|
-
new_purl += f"{name}@{version}"
|
|
119
|
-
if package_purl is None:
|
|
120
|
-
package_purl = new_purl
|
|
121
|
-
if package_purl != new_purl:
|
|
122
|
-
batch_index += 1
|
|
123
|
-
pkg["batchIndex"] = batch_index
|
|
124
|
-
grouped[pkg["batchIndex"]].append(pkg)
|
|
125
|
-
except Exception as error:
|
|
126
|
-
log.error(error)
|
|
119
|
+
# inputPurl should always exist now, fallback to purl if not found
|
|
120
|
+
group_key = pkg.get("inputPurl", pkg.get("purl", str(hash(str(pkg)))))
|
|
121
|
+
grouped[group_key].append(pkg)
|
|
127
122
|
return grouped
|
|
@@ -13,9 +13,9 @@ class Dependencies:
|
|
|
13
13
|
def __init__(self, api):
|
|
14
14
|
self.api = api
|
|
15
15
|
|
|
16
|
-
def post(self, files: list, params: dict, use_lazy_loading: bool =
|
|
16
|
+
def post(self, files: list, params: dict, use_lazy_loading: bool = True, workspace: str = None, base_path: str = None) -> dict:
|
|
17
17
|
if use_lazy_loading:
|
|
18
|
-
loaded_files = Utils.load_files_for_sending_lazy(files, workspace)
|
|
18
|
+
loaded_files = Utils.load_files_for_sending_lazy(files, workspace, base_path=base_path)
|
|
19
19
|
else:
|
|
20
20
|
loaded_files = []
|
|
21
21
|
loaded_files = load_files(files, loaded_files)
|
|
@@ -30,15 +30,20 @@ class Dependencies:
|
|
|
30
30
|
log.error(response.text)
|
|
31
31
|
return result
|
|
32
32
|
|
|
33
|
-
def get(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
33
|
+
def get(self, org_slug: str = None, ecosystem: str = None, package: str = None, version: str = None, **kwargs) -> dict:
|
|
34
|
+
# If all specific parameters are provided, use the specific dependency endpoint
|
|
35
|
+
if org_slug and ecosystem and package and version:
|
|
36
|
+
path = f"orgs/{org_slug}/dependencies/{ecosystem}/{package}/{version}"
|
|
37
|
+
response = self.api.do_request(path=path, method="GET")
|
|
38
|
+
else:
|
|
39
|
+
# Otherwise use the search endpoint
|
|
40
|
+
limit = kwargs.get('limit', 50)
|
|
41
|
+
offset = kwargs.get('offset', 0)
|
|
42
|
+
path = "dependencies/search"
|
|
43
|
+
payload = {"limit": limit, "offset": offset}
|
|
44
|
+
payload_str = json.dumps(payload)
|
|
45
|
+
response = self.api.do_request(path=path, method="POST", payload=payload_str)
|
|
46
|
+
|
|
42
47
|
if response.status_code == 200:
|
|
43
48
|
result = response.json()
|
|
44
49
|
else:
|
socketdev/diffscans/__init__.py
CHANGED
|
@@ -30,7 +30,7 @@ class DiffScans:
|
|
|
30
30
|
log.error(f"Error fetching diff scan: {response.status_code}, message: {response.text}")
|
|
31
31
|
return {}
|
|
32
32
|
|
|
33
|
-
def create_from_repo(self, org_slug: str, repo_slug: str, files: list, params: Optional[Dict[str, Any]] = None, use_lazy_loading: bool = False, workspace: str = None, max_open_files: int = 100) -> dict:
|
|
33
|
+
def create_from_repo(self, org_slug: str, repo_slug: str, files: list, params: Optional[Dict[str, Any]] = None, use_lazy_loading: bool = False, workspace: str = None, max_open_files: int = 100, base_path: str = None) -> dict:
|
|
34
34
|
"""
|
|
35
35
|
Create a diff scan from repo HEAD, uploading files as multipart form data.
|
|
36
36
|
|
|
@@ -45,6 +45,7 @@ class DiffScans:
|
|
|
45
45
|
workspace: Base directory path to make file paths relative to
|
|
46
46
|
max_open_files: Maximum number of files to keep open simultaneously when using
|
|
47
47
|
lazy loading. Useful for systems with low ulimit values (default: 100)
|
|
48
|
+
base_path: Optional base path to strip from key names for cleaner file organization
|
|
48
49
|
|
|
49
50
|
Returns:
|
|
50
51
|
dict: API response containing diff scan results
|
|
@@ -63,7 +64,7 @@ class DiffScans:
|
|
|
63
64
|
|
|
64
65
|
# Use lazy loading if requested
|
|
65
66
|
if use_lazy_loading:
|
|
66
|
-
prepared_files = Utils.load_files_for_sending_lazy(files, workspace, max_open_files)
|
|
67
|
+
prepared_files = Utils.load_files_for_sending_lazy(files, workspace, max_open_files, base_path)
|
|
67
68
|
else:
|
|
68
69
|
prepared_files = files
|
|
69
70
|
|
socketdev/fullscans/__init__.py
CHANGED
|
@@ -701,8 +701,16 @@ class FullScans:
|
|
|
701
701
|
|
|
702
702
|
|
|
703
703
|
def get(self, org_slug: str, params: dict, use_types: bool = False) -> Union[dict, GetFullScanMetadataResponse]:
|
|
704
|
-
|
|
705
|
-
|
|
704
|
+
# Check if this is a request for a specific scan by ID
|
|
705
|
+
if 'id' in params and len(params) == 1:
|
|
706
|
+
# Get specific scan by ID: /orgs/{org_slug}/full-scans/{full_scan_id}
|
|
707
|
+
scan_id = params['id']
|
|
708
|
+
path = f"orgs/{org_slug}/full-scans/{scan_id}"
|
|
709
|
+
else:
|
|
710
|
+
# List scans with query parameters: /orgs/{org_slug}/full-scans?params
|
|
711
|
+
params_arg = urllib.parse.urlencode(params)
|
|
712
|
+
path = "orgs/" + org_slug + "/full-scans?" + str(params_arg)
|
|
713
|
+
|
|
706
714
|
response = self.api.do_request(path=path)
|
|
707
715
|
|
|
708
716
|
if response.status_code == 200:
|
|
@@ -720,7 +728,7 @@ class FullScans:
|
|
|
720
728
|
)
|
|
721
729
|
return {}
|
|
722
730
|
|
|
723
|
-
def post(self, files: list, params: FullScanParams, use_types: bool = False, use_lazy_loading: bool = False, workspace: str = None, max_open_files: int = 100) -> Union[dict, CreateFullScanResponse]:
|
|
731
|
+
def post(self, files: list, params: FullScanParams, use_types: bool = False, use_lazy_loading: bool = False, workspace: str = None, max_open_files: int = 100, base_path: str = None) -> Union[dict, CreateFullScanResponse]:
|
|
724
732
|
"""
|
|
725
733
|
Create a new full scan by uploading manifest files.
|
|
726
734
|
|
|
@@ -734,6 +742,7 @@ class FullScans:
|
|
|
734
742
|
workspace: Base directory path to make file paths relative to
|
|
735
743
|
max_open_files: Maximum number of files to keep open simultaneously when using
|
|
736
744
|
lazy loading. Useful for systems with low ulimit values (default: 100)
|
|
745
|
+
base_path: Optional base path to strip from key names for cleaner file organization
|
|
737
746
|
|
|
738
747
|
Returns:
|
|
739
748
|
dict or CreateFullScanResponse: API response containing scan results
|
|
@@ -754,7 +763,7 @@ class FullScans:
|
|
|
754
763
|
|
|
755
764
|
# Use lazy loading if requested
|
|
756
765
|
if use_lazy_loading:
|
|
757
|
-
prepared_files = Utils.load_files_for_sending_lazy(files, workspace, max_open_files)
|
|
766
|
+
prepared_files = Utils.load_files_for_sending_lazy(files, workspace, max_open_files, base_path)
|
|
758
767
|
else:
|
|
759
768
|
prepared_files = files
|
|
760
769
|
|
socketdev/purl/__init__.py
CHANGED
|
@@ -33,7 +33,7 @@ class Purl:
|
|
|
33
33
|
purl.append(item)
|
|
34
34
|
except json.JSONDecodeError:
|
|
35
35
|
continue
|
|
36
|
-
purl_deduped = Dedupe.dedupe(purl)
|
|
36
|
+
purl_deduped = Dedupe.dedupe(purl, batched=True)
|
|
37
37
|
return purl_deduped
|
|
38
38
|
|
|
39
39
|
log.error(f"Error posting {components} to the Purl API: {response.status_code}")
|
socketdev/report/__init__.py
CHANGED
|
@@ -58,14 +58,29 @@ class Report:
|
|
|
58
58
|
return {}
|
|
59
59
|
|
|
60
60
|
def create(self, files: list) -> dict:
|
|
61
|
+
# Handle both file path strings and file tuples
|
|
61
62
|
open_files = []
|
|
62
|
-
for
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
for file_entry in files:
|
|
64
|
+
if isinstance(file_entry, tuple) and len(file_entry) == 2:
|
|
65
|
+
name, file_data = file_entry
|
|
66
|
+
if isinstance(file_data, tuple) and len(file_data) == 2:
|
|
67
|
+
# Format: [("field_name", ("filename", file_obj))]
|
|
68
|
+
filename, file_obj = file_data
|
|
69
|
+
file_info = (name, (filename, file_obj, "text/plain"))
|
|
70
|
+
open_files.append(file_info)
|
|
71
|
+
else:
|
|
72
|
+
# Format: [("field_name", "file_path")]
|
|
73
|
+
file_info = (name, (name, open(file_data, "rb"), "text/plain"))
|
|
74
|
+
open_files.append(file_info)
|
|
75
|
+
else:
|
|
76
|
+
# Handle other formats if needed
|
|
77
|
+
log.error(f"Unexpected file format: {file_entry}")
|
|
78
|
+
return {}
|
|
79
|
+
|
|
65
80
|
path = "report/upload"
|
|
66
81
|
payload = {}
|
|
67
82
|
response = self.api.do_request(path=path, method="PUT", files=open_files, payload=payload)
|
|
68
|
-
if response.status_code
|
|
83
|
+
if response.status_code in (200, 201):
|
|
69
84
|
return response.json()
|
|
70
85
|
log.error(f"Error creating report: {response.status_code}")
|
|
71
86
|
log.error(response.text)
|
socketdev/threatfeed/__init__.py
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from urllib.parse import urlencode
|
|
3
|
+
|
|
4
|
+
log = logging.getLogger("socketdev")
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ThreatFeed:
|
|
8
|
+
def __init__(self, api):
|
|
9
|
+
self.api = api
|
|
10
|
+
|
|
11
|
+
def get(self, org_slug: str = None, **kwargs) -> dict:
|
|
12
|
+
"""
|
|
13
|
+
Get threat feed items.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
org_slug: Organization slug (required for the new endpoint)
|
|
17
|
+
**kwargs: Query parameters like per_page, page_cursor, sort, etc.
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
dict: API response containing threat feed items
|
|
21
|
+
"""
|
|
22
|
+
if org_slug:
|
|
23
|
+
# Use the new org-scoped endpoint
|
|
24
|
+
path = f"orgs/{org_slug}/threat-feed"
|
|
25
|
+
else:
|
|
26
|
+
# Use the deprecated global endpoint
|
|
27
|
+
path = "threat-feed"
|
|
28
|
+
|
|
29
|
+
if kwargs:
|
|
30
|
+
path += "?" + urlencode(kwargs)
|
|
31
|
+
|
|
32
|
+
response = self.api.do_request(path=path)
|
|
33
|
+
if response.status_code == 200:
|
|
34
|
+
return response.json()
|
|
35
|
+
log.error(f"Error getting threat feed: {response.status_code}")
|
|
36
|
+
log.error(response.text)
|
|
37
|
+
return {"results": [], "nextPage": None}
|
socketdev/utils/__init__.py
CHANGED
|
@@ -233,7 +233,7 @@ class Utils:
|
|
|
233
233
|
return integration_type # type: ignore
|
|
234
234
|
|
|
235
235
|
@staticmethod
|
|
236
|
-
def load_files_for_sending_lazy(files: List[str], workspace: str = None, max_open_files: int = 100) -> List[Tuple[str, Tuple[str, LazyFileLoader]]]:
|
|
236
|
+
def load_files_for_sending_lazy(files: List[str], workspace: str = None, max_open_files: int = 100, base_path: str = None) -> List[Tuple[str, Tuple[str, LazyFileLoader]]]:
|
|
237
237
|
"""
|
|
238
238
|
Prepares files for sending to the Socket API using lazy loading.
|
|
239
239
|
|
|
@@ -246,6 +246,7 @@ class Utils:
|
|
|
246
246
|
files: List of file paths from find_files()
|
|
247
247
|
workspace: Base directory path to make paths relative to
|
|
248
248
|
max_open_files: Maximum number of files to keep open simultaneously (default: 100)
|
|
249
|
+
base_path: Optional base path to strip from key names for cleaner file organization
|
|
249
250
|
|
|
250
251
|
Returns:
|
|
251
252
|
List of tuples formatted for requests multipart upload:
|
|
@@ -257,6 +258,8 @@ class Utils:
|
|
|
257
258
|
send_files = []
|
|
258
259
|
if workspace and "\\" in workspace:
|
|
259
260
|
workspace = workspace.replace("\\", "/")
|
|
261
|
+
if base_path and "\\" in base_path:
|
|
262
|
+
base_path = base_path.replace("\\", "/")
|
|
260
263
|
|
|
261
264
|
for file_path in files:
|
|
262
265
|
# Normalize file path
|
|
@@ -265,14 +268,33 @@ class Utils:
|
|
|
265
268
|
|
|
266
269
|
_, name = file_path.rsplit("/", 1)
|
|
267
270
|
|
|
268
|
-
# Calculate the key
|
|
269
|
-
|
|
271
|
+
# Calculate the key name for the form data
|
|
272
|
+
key = file_path
|
|
273
|
+
|
|
274
|
+
# If base_path is provided, strip it from the file path to create the key
|
|
275
|
+
if base_path:
|
|
276
|
+
# Normalize base_path to ensure consistent handling of trailing slashes
|
|
277
|
+
normalized_base_path = base_path.rstrip("/") + "/" if not base_path.endswith("/") else base_path
|
|
278
|
+
if key.startswith(normalized_base_path):
|
|
279
|
+
key = key[len(normalized_base_path):]
|
|
280
|
+
elif key.startswith(base_path.rstrip("/")):
|
|
281
|
+
# Handle case where base_path matches exactly without trailing slash
|
|
282
|
+
stripped_base = base_path.rstrip("/")
|
|
283
|
+
if key.startswith(stripped_base + "/") or key == stripped_base:
|
|
284
|
+
key = key[len(stripped_base):]
|
|
285
|
+
key = key.lstrip("/")
|
|
286
|
+
|
|
287
|
+
# If workspace is provided and base_path wasn't used, fall back to workspace logic
|
|
288
|
+
elif workspace and file_path.startswith(workspace):
|
|
270
289
|
key = file_path[len(workspace):]
|
|
271
|
-
|
|
272
|
-
key =
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
key
|
|
290
|
+
key = key.lstrip("/")
|
|
291
|
+
key = key.lstrip("./")
|
|
292
|
+
|
|
293
|
+
# If neither base_path nor workspace matched, clean up the key
|
|
294
|
+
if key == file_path:
|
|
295
|
+
# No base_path or workspace stripping occurred, clean up leading parts
|
|
296
|
+
key = key.lstrip("/")
|
|
297
|
+
key = key.lstrip("./")
|
|
276
298
|
|
|
277
299
|
# Create lazy file loader instead of opening file immediately
|
|
278
300
|
# Use the relative path (key) as filename instead of truncated basename
|
socketdev/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "3.0.
|
|
1
|
+
__version__ = "3.0.5"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: socketdev
|
|
3
|
-
Version: 3.0.
|
|
3
|
+
Version: 3.0.5
|
|
4
4
|
Summary: Socket Security Python SDK
|
|
5
5
|
Project-URL: Homepage, https://github.com/socketdev/socketdev
|
|
6
6
|
Author-email: Douglas Coburn <douglas@socket.dev>
|
|
@@ -161,9 +161,9 @@ Export a Socket SBOM as an SPDX SBOM
|
|
|
161
161
|
- **project_version (str)** - Filter by project version
|
|
162
162
|
- **project_id (str)** - Filter by project ID
|
|
163
163
|
|
|
164
|
-
fullscans.get(org_slug)
|
|
165
|
-
"""""""""""""""""""""""
|
|
166
|
-
Retrieve the Fullscans information for an Organization
|
|
164
|
+
fullscans.get(org_slug, params)
|
|
165
|
+
"""""""""""""""""""""""""""""""
|
|
166
|
+
Retrieve the Fullscans information for an Organization with query parameters
|
|
167
167
|
|
|
168
168
|
**Usage:**
|
|
169
169
|
|
|
@@ -171,11 +171,20 @@ Retrieve the Fullscans information for an Organization
|
|
|
171
171
|
|
|
172
172
|
from socketdev import socketdev
|
|
173
173
|
socket = socketdev(token="REPLACE_ME")
|
|
174
|
-
|
|
174
|
+
|
|
175
|
+
# Query parameters for filtering full scans
|
|
176
|
+
params = {
|
|
177
|
+
"repo": "my-repo",
|
|
178
|
+
"branch": "main",
|
|
179
|
+
"limit": 10,
|
|
180
|
+
"offset": 0
|
|
181
|
+
}
|
|
182
|
+
print(socket.fullscans.get("org_slug", params))
|
|
175
183
|
|
|
176
184
|
**PARAMETERS:**
|
|
177
185
|
|
|
178
186
|
- **org_slug (str)** - The organization name
|
|
187
|
+
- **params (dict)** - Query parameters for filtering results (required)
|
|
179
188
|
|
|
180
189
|
fullscans.post(files, params)
|
|
181
190
|
"""""""""""""""""""""""""""""
|
|
@@ -186,29 +195,30 @@ Create a full scan from a set of package manifest files. Returns a full scan inc
|
|
|
186
195
|
.. code-block:: python
|
|
187
196
|
|
|
188
197
|
from socketdev import socketdev
|
|
198
|
+
from socketdev.fullscans import FullScanParams
|
|
199
|
+
|
|
189
200
|
socket = socketdev(token="REPLACE_ME")
|
|
190
201
|
files = [
|
|
191
202
|
"/path/to/manifest/package.json"
|
|
192
203
|
]
|
|
193
|
-
params =
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
204
|
+
params = FullScanParams(
|
|
205
|
+
org_slug="org_name",
|
|
206
|
+
repo="TestRepo",
|
|
207
|
+
branch="main",
|
|
208
|
+
commit_message="Test Commit Message",
|
|
209
|
+
commit_hash="abc123def456",
|
|
210
|
+
pull_request=123,
|
|
211
|
+
committers=["committer1", "committer2"],
|
|
212
|
+
make_default_branch=False,
|
|
213
|
+
set_as_pending_head=False
|
|
214
|
+
)
|
|
205
215
|
|
|
206
216
|
print(socket.fullscans.post(files, params))
|
|
207
217
|
|
|
208
218
|
**PARAMETERS:**
|
|
209
219
|
|
|
210
220
|
- **files (list)** - List of file paths of manifest files
|
|
211
|
-
- **params (
|
|
221
|
+
- **params (FullScanParams)** - FullScanParams object containing scan configuration
|
|
212
222
|
|
|
213
223
|
+------------------------+------------+-------------------------------------------------------------------------------+
|
|
214
224
|
| Parameter | Required | Description |
|
|
@@ -219,20 +229,23 @@ Create a full scan from a set of package manifest files. Returns a full scan inc
|
|
|
219
229
|
+------------------------+------------+-------------------------------------------------------------------------------+
|
|
220
230
|
| branch | False | The string name in a git approved name for branches. |
|
|
221
231
|
+------------------------+------------+-------------------------------------------------------------------------------+
|
|
222
|
-
| committers | False |
|
|
223
|
-
| | | Can be specified multiple times to have more than one committer. |
|
|
232
|
+
| committers | False | List of committer names (List[str]). |
|
|
224
233
|
+------------------------+------------+-------------------------------------------------------------------------------+
|
|
225
234
|
| pull_request | False | The integer for the PR or MR number. |
|
|
226
235
|
+------------------------+------------+-------------------------------------------------------------------------------+
|
|
227
236
|
| commit_message | False | The string for a commit message if there is one. |
|
|
228
237
|
+------------------------+------------+-------------------------------------------------------------------------------+
|
|
229
|
-
| make_default_branch | False |
|
|
238
|
+
| make_default_branch | False | Boolean to signal that this is the default branch. |
|
|
230
239
|
+------------------------+------------+-------------------------------------------------------------------------------+
|
|
231
240
|
| commit_hash | False | Optional git commit hash |
|
|
232
241
|
+------------------------+------------+-------------------------------------------------------------------------------+
|
|
233
|
-
| set_as_pending_head | False |
|
|
242
|
+
| set_as_pending_head | False | Boolean to set as pending head |
|
|
234
243
|
+------------------------+------------+-------------------------------------------------------------------------------+
|
|
235
|
-
| tmp | False |
|
|
244
|
+
| tmp | False | Boolean temporary flag |
|
|
245
|
+
+------------------------+------------+-------------------------------------------------------------------------------+
|
|
246
|
+
| integration_type | False | IntegrationType enum value (e.g., "api", "github") |
|
|
247
|
+
+------------------------+------------+-------------------------------------------------------------------------------+
|
|
248
|
+
| integration_org_slug | False | Organization slug for integration |
|
|
236
249
|
+------------------------+------------+-------------------------------------------------------------------------------+
|
|
237
250
|
|
|
238
251
|
fullscans.delete(org_slug, full_scan_id)
|
|
@@ -245,15 +258,15 @@ Delete an existing full scan.
|
|
|
245
258
|
|
|
246
259
|
from socketdev import socketdev
|
|
247
260
|
socket = socketdev(token="REPLACE_ME")
|
|
248
|
-
print(socket.fullscans.delete(org_slug, full_scan_id))
|
|
261
|
+
print(socket.fullscans.delete("org_slug", "full_scan_id"))
|
|
249
262
|
|
|
250
263
|
**PARAMETERS:**
|
|
251
264
|
|
|
252
265
|
- **org_slug (str)** - The organization name
|
|
253
266
|
- **full_scan_id (str)** - The ID of the full scan
|
|
254
267
|
|
|
255
|
-
fullscans.stream_diff(org_slug, before, after,
|
|
256
|
-
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
268
|
+
fullscans.stream_diff(org_slug, before, after, use_types=True, include_license_details="true", \*\*kwargs)
|
|
269
|
+
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
257
270
|
Stream a diff between two full scans. Returns a scan diff.
|
|
258
271
|
|
|
259
272
|
**Usage:**
|
|
@@ -263,16 +276,27 @@ Stream a diff between two full scans. Returns a scan diff.
|
|
|
263
276
|
from socketdev import socketdev
|
|
264
277
|
socket = socketdev(token="REPLACE_ME")
|
|
265
278
|
print(socket.fullscans.stream_diff("org_slug", "before_scan_id", "after_scan_id"))
|
|
279
|
+
|
|
280
|
+
# With additional parameters
|
|
281
|
+
print(socket.fullscans.stream_diff(
|
|
282
|
+
"org_slug",
|
|
283
|
+
"before_scan_id",
|
|
284
|
+
"after_scan_id",
|
|
285
|
+
use_types=False,
|
|
286
|
+
include_license_details="false"
|
|
287
|
+
))
|
|
266
288
|
|
|
267
289
|
**PARAMETERS:**
|
|
268
290
|
|
|
269
291
|
- **org_slug (str)** - The organization name
|
|
270
292
|
- **before (str)** - The base full scan ID
|
|
271
293
|
- **after (str)** - The comparison full scan ID
|
|
272
|
-
- **
|
|
294
|
+
- **use_types (bool)** - Whether to return typed response objects (default: True)
|
|
295
|
+
- **include_license_details (str)** - Include license details ("true"/"false"). Can greatly increase response size. Defaults to "true".
|
|
296
|
+
- **kwargs** - Additional query parameters
|
|
273
297
|
|
|
274
|
-
fullscans.stream(org_slug, full_scan_id)
|
|
275
|
-
""""""""""""""""""""""""""""""""""""""""
|
|
298
|
+
fullscans.stream(org_slug, full_scan_id, use_types=False)
|
|
299
|
+
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
276
300
|
Stream all SBOM artifacts for a full scan.
|
|
277
301
|
|
|
278
302
|
**Usage:**
|
|
@@ -281,15 +305,19 @@ Stream all SBOM artifacts for a full scan.
|
|
|
281
305
|
|
|
282
306
|
from socketdev import socketdev
|
|
283
307
|
socket = socketdev(token="REPLACE_ME")
|
|
284
|
-
print(socket.fullscans.stream(org_slug, full_scan_id))
|
|
308
|
+
print(socket.fullscans.stream("org_slug", "full_scan_id"))
|
|
309
|
+
|
|
310
|
+
# With typed response
|
|
311
|
+
print(socket.fullscans.stream("org_slug", "full_scan_id", use_types=True))
|
|
285
312
|
|
|
286
313
|
**PARAMETERS:**
|
|
287
314
|
|
|
288
315
|
- **org_slug (str)** - The organization name
|
|
289
316
|
- **full_scan_id (str)** - The ID of the full scan
|
|
317
|
+
- **use_types (bool)** - Whether to return typed response objects (default: False)
|
|
290
318
|
|
|
291
|
-
fullscans.metadata(org_slug, full_scan_id)
|
|
292
|
-
""""""""""""""""""""""""""""""""""""""""""
|
|
319
|
+
fullscans.metadata(org_slug, full_scan_id, use_types=False)
|
|
320
|
+
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
293
321
|
Get metadata for a single full scan
|
|
294
322
|
|
|
295
323
|
**Usage:**
|
|
@@ -298,12 +326,34 @@ Get metadata for a single full scan
|
|
|
298
326
|
|
|
299
327
|
from socketdev import socketdev
|
|
300
328
|
socket = socketdev(token="REPLACE_ME")
|
|
301
|
-
print(socket.fullscans.metadata(org_slug, full_scan_id))
|
|
329
|
+
print(socket.fullscans.metadata("org_slug", "full_scan_id"))
|
|
330
|
+
|
|
331
|
+
# With typed response
|
|
332
|
+
print(socket.fullscans.metadata("org_slug", "full_scan_id", use_types=True))
|
|
302
333
|
|
|
303
334
|
**PARAMETERS:**
|
|
304
335
|
|
|
305
336
|
- **org_slug (str)** - The organization name
|
|
306
337
|
- **full_scan_id (str)** - The ID of the full scan
|
|
338
|
+
- **use_types (bool)** - Whether to return typed response objects (default: False)
|
|
339
|
+
|
|
340
|
+
fullscans.gfm(org_slug, before, after)
|
|
341
|
+
""""""""""""""""""""""""""""""""""""""
|
|
342
|
+
Get GitHub Flavored Markdown diff between two full scans.
|
|
343
|
+
|
|
344
|
+
**Usage:**
|
|
345
|
+
|
|
346
|
+
.. code-block:: python
|
|
347
|
+
|
|
348
|
+
from socketdev import socketdev
|
|
349
|
+
socket = socketdev(token="REPLACE_ME")
|
|
350
|
+
print(socket.fullscans.gfm("org_slug", "before_scan_id", "after_scan_id"))
|
|
351
|
+
|
|
352
|
+
**PARAMETERS:**
|
|
353
|
+
|
|
354
|
+
- **org_slug (str)** - The organization name
|
|
355
|
+
- **before (str)** - The base full scan ID
|
|
356
|
+
- **after (str)** - The comparison full scan ID
|
|
307
357
|
|
|
308
358
|
dependencies.get(limit, offset)
|
|
309
359
|
"""""""""""""""""""""""""""""""
|
|
@@ -828,3 +878,292 @@ List all historical snapshots for an organization.
|
|
|
828
878
|
|
|
829
879
|
- **org_slug (str)** – The organization name
|
|
830
880
|
- **query_params (dict, optional)** – Optional query parameters
|
|
881
|
+
|
|
882
|
+
diffscans.list(org_slug, params=None)
|
|
883
|
+
"""""""""""""""""""""""""""""""""""""
|
|
884
|
+
List all diff scans for an organization.
|
|
885
|
+
|
|
886
|
+
**Usage:**
|
|
887
|
+
|
|
888
|
+
.. code-block:: python
|
|
889
|
+
|
|
890
|
+
from socketdev import socketdev
|
|
891
|
+
socket = socketdev(token="REPLACE_ME")
|
|
892
|
+
print(socket.diffscans.list("org_slug", {"limit": 10, "offset": 0}))
|
|
893
|
+
|
|
894
|
+
**PARAMETERS:**
|
|
895
|
+
|
|
896
|
+
- **org_slug (str)** – The organization name
|
|
897
|
+
- **params (dict, optional)** – Optional query parameters for filtering
|
|
898
|
+
|
|
899
|
+
diffscans.get(org_slug, diff_scan_id)
|
|
900
|
+
"""""""""""""""""""""""""""""""""""""
|
|
901
|
+
Fetch a specific diff scan by ID.
|
|
902
|
+
|
|
903
|
+
**Usage:**
|
|
904
|
+
|
|
905
|
+
.. code-block:: python
|
|
906
|
+
|
|
907
|
+
from socketdev import socketdev
|
|
908
|
+
socket = socketdev(token="REPLACE_ME")
|
|
909
|
+
print(socket.diffscans.get("org_slug", "diff_scan_id"))
|
|
910
|
+
|
|
911
|
+
**PARAMETERS:**
|
|
912
|
+
|
|
913
|
+
- **org_slug (str)** – The organization name
|
|
914
|
+
- **diff_scan_id (str)** – The ID of the diff scan to retrieve
|
|
915
|
+
|
|
916
|
+
diffscans.create_from_ids(org_slug, params)
|
|
917
|
+
"""""""""""""""""""""""""""""""""""""""""""
|
|
918
|
+
Create a diff scan from two full scan IDs.
|
|
919
|
+
|
|
920
|
+
**Usage:**
|
|
921
|
+
|
|
922
|
+
.. code-block:: python
|
|
923
|
+
|
|
924
|
+
from socketdev import socketdev
|
|
925
|
+
socket = socketdev(token="REPLACE_ME")
|
|
926
|
+
params = {
|
|
927
|
+
"before": "full_scan_id_1",
|
|
928
|
+
"after": "full_scan_id_2",
|
|
929
|
+
"description": "Compare two scans"
|
|
930
|
+
}
|
|
931
|
+
print(socket.diffscans.create_from_ids("org_slug", params))
|
|
932
|
+
|
|
933
|
+
**PARAMETERS:**
|
|
934
|
+
|
|
935
|
+
- **org_slug (str)** – The organization name
|
|
936
|
+
- **params (dict)** – Parameters including before and after scan IDs
|
|
937
|
+
|
|
938
|
+
diffscans.create_from_repo(org_slug, repo_slug, files, params=None)
|
|
939
|
+
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
940
|
+
Create a diff scan from repository files.
|
|
941
|
+
|
|
942
|
+
**Usage:**
|
|
943
|
+
|
|
944
|
+
.. code-block:: python
|
|
945
|
+
|
|
946
|
+
from socketdev import socketdev
|
|
947
|
+
socket = socketdev(token="REPLACE_ME")
|
|
948
|
+
files = ["/path/to/package.json"]
|
|
949
|
+
params = {"branch": "main", "commit": "abc123"}
|
|
950
|
+
print(socket.diffscans.create_from_repo("org_slug", "repo_slug", files, params))
|
|
951
|
+
|
|
952
|
+
**PARAMETERS:**
|
|
953
|
+
|
|
954
|
+
- **org_slug (str)** – The organization name
|
|
955
|
+
- **repo_slug (str)** – The repository name
|
|
956
|
+
- **files (list)** – List of file paths to scan
|
|
957
|
+
- **params (dict, optional)** – Optional parameters for the scan
|
|
958
|
+
|
|
959
|
+
diffscans.gfm(org_slug, diff_scan_id)
|
|
960
|
+
"""""""""""""""""""""""""""""""""""""
|
|
961
|
+
Get GitHub Flavored Markdown comments for a diff scan.
|
|
962
|
+
|
|
963
|
+
**Usage:**
|
|
964
|
+
|
|
965
|
+
.. code-block:: python
|
|
966
|
+
|
|
967
|
+
from socketdev import socketdev
|
|
968
|
+
socket = socketdev(token="REPLACE_ME")
|
|
969
|
+
print(socket.diffscans.gfm("org_slug", "diff_scan_id"))
|
|
970
|
+
|
|
971
|
+
**PARAMETERS:**
|
|
972
|
+
|
|
973
|
+
- **org_slug (str)** – The organization name
|
|
974
|
+
- **diff_scan_id (str)** – The ID of the diff scan
|
|
975
|
+
|
|
976
|
+
diffscans.delete(org_slug, diff_scan_id)
|
|
977
|
+
""""""""""""""""""""""""""""""""""""""""
|
|
978
|
+
Delete a specific diff scan.
|
|
979
|
+
|
|
980
|
+
**Usage:**
|
|
981
|
+
|
|
982
|
+
.. code-block:: python
|
|
983
|
+
|
|
984
|
+
from socketdev import socketdev
|
|
985
|
+
socket = socketdev(token="REPLACE_ME")
|
|
986
|
+
print(socket.diffscans.delete("org_slug", "diff_scan_id"))
|
|
987
|
+
|
|
988
|
+
**PARAMETERS:**
|
|
989
|
+
|
|
990
|
+
- **org_slug (str)** – The organization name
|
|
991
|
+
- **diff_scan_id (str)** – The ID of the diff scan to delete
|
|
992
|
+
|
|
993
|
+
threatfeed.get(org_slug=None, \*\*kwargs)
|
|
994
|
+
"""""""""""""""""""""""""""""""""""""""""""
|
|
995
|
+
Get threat feed items for an organization or globally.
|
|
996
|
+
|
|
997
|
+
**Usage:**
|
|
998
|
+
|
|
999
|
+
.. code-block:: python
|
|
1000
|
+
|
|
1001
|
+
from socketdev import socketdev
|
|
1002
|
+
socket = socketdev(token="REPLACE_ME")
|
|
1003
|
+
|
|
1004
|
+
# Get org-specific threat feed
|
|
1005
|
+
print(socket.threatfeed.get("org_slug", per_page=50, sort="created_at"))
|
|
1006
|
+
|
|
1007
|
+
# Get global threat feed (deprecated)
|
|
1008
|
+
print(socket.threatfeed.get())
|
|
1009
|
+
|
|
1010
|
+
**PARAMETERS:**
|
|
1011
|
+
|
|
1012
|
+
- **org_slug (str, optional)** – The organization name (recommended for new implementations)
|
|
1013
|
+
- **kwargs** – Query parameters like per_page, page_cursor, sort, etc.
|
|
1014
|
+
|
|
1015
|
+
apitokens.create(org_slug, \*\*kwargs)
|
|
1016
|
+
""""""""""""""""""""""""""""""""""""""
|
|
1017
|
+
Create a new API token for an organization.
|
|
1018
|
+
|
|
1019
|
+
**Usage:**
|
|
1020
|
+
|
|
1021
|
+
.. code-block:: python
|
|
1022
|
+
|
|
1023
|
+
from socketdev import socketdev
|
|
1024
|
+
socket = socketdev(token="REPLACE_ME")
|
|
1025
|
+
token_config = {
|
|
1026
|
+
"name": "My API Token",
|
|
1027
|
+
"permissions": ["read", "write"],
|
|
1028
|
+
"expires_at": "2024-12-31T23:59:59Z"
|
|
1029
|
+
}
|
|
1030
|
+
print(socket.apitokens.create("org_slug", **token_config))
|
|
1031
|
+
|
|
1032
|
+
**PARAMETERS:**
|
|
1033
|
+
|
|
1034
|
+
- **org_slug (str)** – The organization name
|
|
1035
|
+
- **kwargs** – Token configuration parameters
|
|
1036
|
+
|
|
1037
|
+
apitokens.update(org_slug, \*\*kwargs)
|
|
1038
|
+
""""""""""""""""""""""""""""""""""""""
|
|
1039
|
+
Update an existing API token.
|
|
1040
|
+
|
|
1041
|
+
**Usage:**
|
|
1042
|
+
|
|
1043
|
+
.. code-block:: python
|
|
1044
|
+
|
|
1045
|
+
from socketdev import socketdev
|
|
1046
|
+
socket = socketdev(token="REPLACE_ME")
|
|
1047
|
+
update_params = {
|
|
1048
|
+
"token_id": "token_123",
|
|
1049
|
+
"name": "Updated Token Name",
|
|
1050
|
+
"permissions": ["read"]
|
|
1051
|
+
}
|
|
1052
|
+
print(socket.apitokens.update("org_slug", **update_params))
|
|
1053
|
+
|
|
1054
|
+
**PARAMETERS:**
|
|
1055
|
+
|
|
1056
|
+
- **org_slug (str)** – The organization name
|
|
1057
|
+
- **kwargs** – Token update parameters
|
|
1058
|
+
|
|
1059
|
+
auditlog.get(org_slug, \*\*kwargs)
|
|
1060
|
+
""""""""""""""""""""""""""""""""""""
|
|
1061
|
+
Get audit log entries for an organization.
|
|
1062
|
+
|
|
1063
|
+
**Usage:**
|
|
1064
|
+
|
|
1065
|
+
.. code-block:: python
|
|
1066
|
+
|
|
1067
|
+
from socketdev import socketdev
|
|
1068
|
+
socket = socketdev(token="REPLACE_ME")
|
|
1069
|
+
print(socket.auditlog.get("org_slug", limit=100, cursor="abc123"))
|
|
1070
|
+
|
|
1071
|
+
**PARAMETERS:**
|
|
1072
|
+
|
|
1073
|
+
- **org_slug (str)** – The organization name
|
|
1074
|
+
- **kwargs** – Query parameters like limit, cursor, etc.
|
|
1075
|
+
|
|
1076
|
+
analytics.get_org(filter, \*\*kwargs)
|
|
1077
|
+
"""""""""""""""""""""""""""""""""""""""
|
|
1078
|
+
Get organization analytics (deprecated - use Historical module instead).
|
|
1079
|
+
|
|
1080
|
+
**Usage:**
|
|
1081
|
+
|
|
1082
|
+
.. code-block:: python
|
|
1083
|
+
|
|
1084
|
+
from socketdev import socketdev
|
|
1085
|
+
socket = socketdev(token="REPLACE_ME")
|
|
1086
|
+
# DEPRECATED: Use socket.historical.list() or socket.historical.trend() instead
|
|
1087
|
+
print(socket.analytics.get_org("alerts", start_date="2024-01-01"))
|
|
1088
|
+
|
|
1089
|
+
**PARAMETERS:**
|
|
1090
|
+
|
|
1091
|
+
- **filter (str)** – Analytics filter type
|
|
1092
|
+
- **kwargs** – Additional query parameters
|
|
1093
|
+
|
|
1094
|
+
analytics.get_repo(name, filter, \*\*kwargs)
|
|
1095
|
+
""""""""""""""""""""""""""""""""""""""""""""""
|
|
1096
|
+
Get repository analytics (deprecated - use Historical module instead).
|
|
1097
|
+
|
|
1098
|
+
**Usage:**
|
|
1099
|
+
|
|
1100
|
+
.. code-block:: python
|
|
1101
|
+
|
|
1102
|
+
from socketdev import socketdev
|
|
1103
|
+
socket = socketdev(token="REPLACE_ME")
|
|
1104
|
+
# DEPRECATED: Use socket.historical.list() or socket.historical.trend() instead
|
|
1105
|
+
print(socket.analytics.get_repo("repo_name", "alerts", start_date="2024-01-01"))
|
|
1106
|
+
|
|
1107
|
+
**PARAMETERS:**
|
|
1108
|
+
|
|
1109
|
+
- **name (str)** – Repository name
|
|
1110
|
+
- **filter (str)** – Analytics filter type
|
|
1111
|
+
- **kwargs** – Additional query parameters
|
|
1112
|
+
|
|
1113
|
+
alerttypes.get(alert_types=None, language="en-US", \*\*kwargs)
|
|
1114
|
+
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
1115
|
+
Get alert types metadata.
|
|
1116
|
+
|
|
1117
|
+
**Usage:**
|
|
1118
|
+
|
|
1119
|
+
.. code-block:: python
|
|
1120
|
+
|
|
1121
|
+
from socketdev import socketdev
|
|
1122
|
+
socket = socketdev(token="REPLACE_ME")
|
|
1123
|
+
|
|
1124
|
+
# Get metadata for specific alert types
|
|
1125
|
+
alert_list = ["supply_chain_risk", "license_risk"]
|
|
1126
|
+
print(socket.alerttypes.get(alert_list, language="en-US"))
|
|
1127
|
+
|
|
1128
|
+
# Get all alert types metadata
|
|
1129
|
+
print(socket.alerttypes.get())
|
|
1130
|
+
|
|
1131
|
+
**PARAMETERS:**
|
|
1132
|
+
|
|
1133
|
+
- **alert_types (list, optional)** – List of alert type strings to get metadata for
|
|
1134
|
+
- **language (str)** – Language for alert metadata (default: en-US)
|
|
1135
|
+
- **kwargs** – Additional query parameters
|
|
1136
|
+
|
|
1137
|
+
triage.list_alert_triage(org_slug, query_params=None)
|
|
1138
|
+
"""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
1139
|
+
Get list of triaged alerts for an organization.
|
|
1140
|
+
|
|
1141
|
+
**Usage:**
|
|
1142
|
+
|
|
1143
|
+
.. code-block:: python
|
|
1144
|
+
|
|
1145
|
+
from socketdev import socketdev
|
|
1146
|
+
socket = socketdev(token="REPLACE_ME")
|
|
1147
|
+
query_params = {"status": "triaged", "limit": 50}
|
|
1148
|
+
print(socket.triage.list_alert_triage("org_slug", query_params))
|
|
1149
|
+
|
|
1150
|
+
**PARAMETERS:**
|
|
1151
|
+
|
|
1152
|
+
- **org_slug (str)** – The organization name
|
|
1153
|
+
- **query_params (dict, optional)** – Optional query parameters for filtering
|
|
1154
|
+
|
|
1155
|
+
openapi.get()
|
|
1156
|
+
"""""""""""""
|
|
1157
|
+
Retrieve the OpenAPI specification for the Socket API.
|
|
1158
|
+
|
|
1159
|
+
**Usage:**
|
|
1160
|
+
|
|
1161
|
+
.. code-block:: python
|
|
1162
|
+
|
|
1163
|
+
from socketdev import socketdev
|
|
1164
|
+
socket = socketdev(token="REPLACE_ME")
|
|
1165
|
+
print(socket.openapi.get())
|
|
1166
|
+
|
|
1167
|
+
**PARAMETERS:**
|
|
1168
|
+
|
|
1169
|
+
None required.
|
|
@@ -1,35 +1,37 @@
|
|
|
1
|
-
socketdev/__init__.py,sha256=
|
|
1
|
+
socketdev/__init__.py,sha256=wcxhpItn-ZkKQYJSsmkHKDaGdtCbWPMvb_delK2xbdU,2811
|
|
2
2
|
socketdev/exceptions.py,sha256=SNU1EgswGwnxI_Zmm325ruP6CFg5C4MsS1qxXWwBJqs,1120
|
|
3
3
|
socketdev/log.py,sha256=AgEcsPN3y9U-fze8pTFvLigVvNob2vmNC-TkOOQkkeQ,90
|
|
4
|
-
socketdev/version.py,sha256=
|
|
5
|
-
socketdev/
|
|
6
|
-
socketdev/
|
|
4
|
+
socketdev/version.py,sha256=3kxZhPRWwAKER8BleEtUBQTUGwcBGPmrbjLu-HEi-hI,22
|
|
5
|
+
socketdev/alerttypes/__init__.py,sha256=W-m2D9VxbepSAUELJPmWmX40zksGZbQcSzwQ1kjlB1k,1169
|
|
6
|
+
socketdev/analytics/__init__.py,sha256=kQGeO67TraqvfmYjfpYCvcNRtxW2a6x5EefEl6Jnca8,2223
|
|
7
|
+
socketdev/apitokens/__init__.py,sha256=Z6W9Jkh4gdDeJBivfcONZuz7jRKZtxWLTi1n9gkbYVE,4222
|
|
8
|
+
socketdev/auditlog/__init__.py,sha256=vjcVtOK6oujqC6-RW5Hrvmth5BqFkLdinbeyqtycOpA,881
|
|
7
9
|
socketdev/core/api.py,sha256=xymEv2szAwZXDsTI4nRC_zcqoSVAenQ-TceNuHfkwbE,5773
|
|
8
10
|
socketdev/core/classes.py,sha256=fyDlolgnkpHFb1dMHa2SA0czCS1I6Tr3SuYb1a67-dY,3756
|
|
9
|
-
socketdev/core/dedupe.py,sha256=
|
|
11
|
+
socketdev/core/dedupe.py,sha256=pe3w51nEPoCXC6GeGaqjusTNCW3WuYAElEU2Wq4j88w,5003
|
|
10
12
|
socketdev/core/issues.py,sha256=jIfi6h1Y-d38OgxSFhlgC74TLvY6IfUcWhQfLq8FFPo,68147
|
|
11
|
-
socketdev/dependencies/__init__.py,sha256=
|
|
12
|
-
socketdev/diffscans/__init__.py,sha256=
|
|
13
|
+
socketdev/dependencies/__init__.py,sha256=zdAb0lMYF8tTHFWa9kGwz5dv4_Sp1UpzQseg_4_qBfY,2170
|
|
14
|
+
socketdev/diffscans/__init__.py,sha256=xeAJn0RPr4LsNTi4q8pyOPPpd_ujIup9cftXd_rNamw,5141
|
|
13
15
|
socketdev/export/__init__.py,sha256=cDZ3Z0UTazpapiTjhHKgaJxXHh2vVruKhlWnJB-YcQU,2674
|
|
14
|
-
socketdev/fullscans/__init__.py,sha256=
|
|
16
|
+
socketdev/fullscans/__init__.py,sha256=UcF89uN2GM6sTmcBBQoZ56RcqJtCMtU1u5qz8aVcDH0,29282
|
|
15
17
|
socketdev/historical/__init__.py,sha256=EZ053u9L4dJgUMDjDNlUWVbbVk9OOguYrP9djejklj0,2786
|
|
16
18
|
socketdev/labels/__init__.py,sha256=Ep19ZraKqi_a-3-eAOWGhPNQsgwGRY9N28Oyxlxrz-g,5128
|
|
17
19
|
socketdev/licensemetadata/__init__.py,sha256=pDcvpkc08QtMqhsnKP1Cfjvs3m-MRPYUK-uLh8aRkrU,815
|
|
18
20
|
socketdev/npm/__init__.py,sha256=FvU8z6dY3EsBNLBsKwQKT5soNb6ous1o63aphmbBHh4,906
|
|
19
21
|
socketdev/openapi/__init__.py,sha256=7Avxgz8RYqC5TCSQCKvmnvzsa2lgV_1y--8eMsy9xYc,500
|
|
20
22
|
socketdev/org/__init__.py,sha256=2e9fe9jF8V_zb2V-qtmkQZUzJv6qbfpbb1p4Hdgsx9A,903
|
|
21
|
-
socketdev/purl/__init__.py,sha256=
|
|
23
|
+
socketdev/purl/__init__.py,sha256=_ybmj-taH2eArwMPwYX-dO3UA4xoK-TMSgEEvI9Adzg,1345
|
|
22
24
|
socketdev/quota/__init__.py,sha256=IblVMP3M7HwXtHs2wnr72GlcNIQtykOKsZKLSehEC8c,487
|
|
23
|
-
socketdev/report/__init__.py,sha256=
|
|
25
|
+
socketdev/report/__init__.py,sha256=L1EuvUnatxWAwQdLiTQwdRNIVglWYoyWqSISuZB0RTE,3454
|
|
24
26
|
socketdev/repos/__init__.py,sha256=dM8GrjIiHUBsPJeBRKLm9QJDRCgx5F-N2iN7GDCHTIg,5603
|
|
25
27
|
socketdev/repositories/__init__.py,sha256=0SP-rCSfxWa9DrPkDKXac8SHqmVHFqgqUHDs-5eg8IE,790
|
|
26
28
|
socketdev/sbom/__init__.py,sha256=LpesXKZhgF5OeNWls10YgxsCNamFW-F8UOy4yI11hrY,2341
|
|
27
29
|
socketdev/settings/__init__.py,sha256=CCRAnFWOvm7Hi4LY0gbFqsOFHNDlWK3FHei0Edcv_-8,6268
|
|
28
|
-
socketdev/threatfeed/__init__.py,sha256=
|
|
30
|
+
socketdev/threatfeed/__init__.py,sha256=2SsJYKByXBkb2C1fGopwxejkr7mky0kggFKIunyV7Nk,1119
|
|
29
31
|
socketdev/tools/__init__.py,sha256=ROvpEULLXTKby9DMsVFPlAlysjwfop1NhRqSrFUWprY,1969
|
|
30
32
|
socketdev/triage/__init__.py,sha256=-h599vThVetfRSOAs1e4IUoMjcXS8xOsUfub41XPiX4,1559
|
|
31
|
-
socketdev/utils/__init__.py,sha256=
|
|
32
|
-
socketdev-3.0.
|
|
33
|
-
socketdev-3.0.
|
|
34
|
-
socketdev-3.0.
|
|
35
|
-
socketdev-3.0.
|
|
33
|
+
socketdev/utils/__init__.py,sha256=zTqwQL-UH6xp-ZjMMqPT4Q1p4XlLTZAC-siLKRo-Lfo,12008
|
|
34
|
+
socketdev-3.0.5.dist-info/METADATA,sha256=xC8GX2Wqjhzlp73VVRn0jWEPXkpuOUwMr0wa1zt9H38,34359
|
|
35
|
+
socketdev-3.0.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
36
|
+
socketdev-3.0.5.dist-info/licenses/LICENSE,sha256=mC0II_UuE-_gCG9XqOLNyrV3crnROzMpdAetGnMrhpw,1068
|
|
37
|
+
socketdev-3.0.5.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|