socketdev 3.6.1__tar.gz → 3.6.2__tar.gz
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-3.6.1 → socketdev-3.6.2}/.github/actions/setup-sfw/action.yml +1 -1
- {socketdev-3.6.1 → socketdev-3.6.2}/.github/workflows/api-drift-check.yml +1 -1
- {socketdev-3.6.1 → socketdev-3.6.2}/.github/workflows/package-check.yml +1 -1
- {socketdev-3.6.1 → socketdev-3.6.2}/.github/workflows/pr-preview.yml +2 -2
- {socketdev-3.6.1 → socketdev-3.6.2}/.github/workflows/release.yml +2 -2
- {socketdev-3.6.1 → socketdev-3.6.2}/CHANGELOG.md +29 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/PKG-INFO +12 -2
- {socketdev-3.6.1 → socketdev-3.6.2}/README.rst +11 -1
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/__init__.py +5 -9
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/core/api.py +7 -1
- socketdev-3.6.2/socketdev/core/retired_token.py +34 -0
- socketdev-3.6.2/socketdev/core/token_selection.py +19 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/fullscans/__init__.py +61 -4
- socketdev-3.6.2/socketdev/version.py +1 -0
- socketdev-3.6.2/tests/support/socket_api_fixture.py +121 -0
- socketdev-3.6.2/tests/unit/test_full_scan_cached_polling_http.py +182 -0
- socketdev-3.6.2/tests/unit/test_retired_token.py +85 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/tests/unit/test_socket_purl_type.py +29 -21
- {socketdev-3.6.1 → socketdev-3.6.2}/uv.lock +33 -33
- socketdev-3.6.1/socketdev/version.py +0 -1
- {socketdev-3.6.1 → socketdev-3.6.2}/.gitattributes +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/.github/CODEOWNERS +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/.github/PULL_REQUEST_TEMPLATE/bug-fix.md +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/.github/PULL_REQUEST_TEMPLATE/feature.md +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/.github/PULL_REQUEST_TEMPLATE/improvement.md +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/.github/actions/setup-hatch/action.yml +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/.github/dependabot.yml +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/.github/workflows/dependency-review.yml +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/.github/workflows/version-check.yml +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/.gitignore +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/.hooks/sync_version.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/.python-version +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/CONTRIBUTING.md +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/LICENSE +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/pyproject.toml +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/scripts/build.sh +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/scripts/check_api_enum_drift.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/scripts/deploy-test-pypi.sh +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/alertfullscansearch/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/alerts/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/alerttypes/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/analytics/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/apitokens/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/auditlog/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/basics/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/core/classes.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/core/dedupe.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/core/enums.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/core/issues.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/dependencies/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/diffscans/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/exceptions.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/export/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/fixes/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/historical/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/labels/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/licensemetadata/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/log.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/npm/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/openapi/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/org/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/purl/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/quota/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/report/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/repos/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/repositories/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/sbom/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/settings/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/supportedfiles/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/telemetry/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/threatfeed/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/tools/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/triage/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/uploadmanifests/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/utils/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/socketdev/webhooks/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/tests/README.md +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/tests/conftest.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/tests/integration/test_all_endpoints.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/tests/integration/test_comprehensive_integration.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/tests/integration/test_diffscans_integration.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/tests/integration/test_new_endpoints.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/tests/run_tests.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/tests/unit/__init__.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/tests/unit/test_all_endpoints_unit.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/tests/unit/test_dedupe.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/tests/unit/test_enum_forward_compat.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/tests/unit/test_exceptions.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/tests/unit/test_issues_did_you_mean_props.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/tests/unit/test_socket_alert_category.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/tests/unit/test_socket_sdk_unit.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/tests/unit/test_upload_manifests.py +0 -0
- {socketdev-3.6.1 → socketdev-3.6.2}/tests/unit/test_working_endpoints_unit.py +0 -0
|
@@ -24,7 +24,7 @@ runs:
|
|
|
24
24
|
using: "composite"
|
|
25
25
|
steps:
|
|
26
26
|
- if: ${{ inputs.python == 'true' || inputs.uv == 'true' }}
|
|
27
|
-
uses: actions/setup-python@
|
|
27
|
+
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
|
|
28
28
|
with:
|
|
29
29
|
python-version: "3.12"
|
|
30
30
|
|
|
@@ -92,7 +92,7 @@ jobs:
|
|
|
92
92
|
fetch-depth: 0
|
|
93
93
|
persist-credentials: false
|
|
94
94
|
|
|
95
|
-
- uses: actions/setup-python@
|
|
95
|
+
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
|
|
96
96
|
with:
|
|
97
97
|
python-version: "3.12"
|
|
98
98
|
|
|
@@ -150,7 +150,7 @@ jobs:
|
|
|
150
150
|
path: dist
|
|
151
151
|
|
|
152
152
|
- name: Publish to TestPyPI
|
|
153
|
-
uses: pypa/gh-action-pypi-publish@
|
|
153
|
+
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
|
|
154
154
|
with:
|
|
155
155
|
repository-url: https://test.pypi.org/legacy/
|
|
156
156
|
verbose: true
|
|
@@ -14,7 +14,7 @@ jobs:
|
|
|
14
14
|
with:
|
|
15
15
|
fetch-depth: 0
|
|
16
16
|
persist-credentials: false
|
|
17
|
-
- uses: actions/setup-python@
|
|
17
|
+
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
|
|
18
18
|
with:
|
|
19
19
|
python-version: '3.13'
|
|
20
20
|
|
|
@@ -53,7 +53,7 @@ jobs:
|
|
|
53
53
|
|
|
54
54
|
- name: Publish to PyPI
|
|
55
55
|
if: steps.version_check.outputs.pypi_exists != 'true'
|
|
56
|
-
uses: pypa/gh-action-pypi-publish@
|
|
56
|
+
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
|
|
57
57
|
|
|
58
58
|
- name: Verify package is installable
|
|
59
59
|
id: verify_package
|
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.6.2
|
|
4
|
+
|
|
5
|
+
### Fixed: reject retired API credentials before use
|
|
6
|
+
|
|
7
|
+
- The SDK rejects the retired API credential before storing or encoding it.
|
|
8
|
+
|
|
9
|
+
### Fixed: full-scan reads wait for analysis to finish
|
|
10
|
+
|
|
11
|
+
- `fullscans.stream()` now requests cached results (`?cached=true`) and polls
|
|
12
|
+
while the API answers `202 Processing`, instead of treating the first `202`
|
|
13
|
+
as a failed result. Polling backs off from 5s to 10s between attempts and
|
|
14
|
+
stops when the budget runs out, raising `APITimeout`.
|
|
15
|
+
- The polling budget defaults to the SDK's configured `timeout`. Callers can
|
|
16
|
+
tune it with the new keyword-only arguments `poll_timeout_seconds`,
|
|
17
|
+
`poll_initial_interval_seconds` and `poll_max_interval_seconds`. Each
|
|
18
|
+
request is bounded by the configured `timeout` or the remaining budget,
|
|
19
|
+
whichever is shorter, and polling stops early once the next attempt could
|
|
20
|
+
not start before the budget runs out.
|
|
21
|
+
- Transient failures (HTTP 408/502/503/504, timeouts, dropped connections) are
|
|
22
|
+
retried within the budget. Authorization, not-found and quota errors still
|
|
23
|
+
raise immediately.
|
|
24
|
+
- Invalid polling settings (zero, negative, non-finite, booleans, or an
|
|
25
|
+
initial interval above the maximum) raise `ValueError` before any request is
|
|
26
|
+
sent.
|
|
27
|
+
- The organization slug and full scan ID are now URL-encoded in the request
|
|
28
|
+
path.
|
|
29
|
+
- `API.do_request()` accepts an optional keyword-only `request_timeout` that
|
|
30
|
+
overrides the configured timeout for a single call.
|
|
31
|
+
|
|
3
32
|
## 3.6.1
|
|
4
33
|
|
|
5
34
|
### Security: patched releases of certifi, uv and virtualenv
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: socketdev
|
|
3
|
-
Version: 3.6.
|
|
3
|
+
Version: 3.6.2
|
|
4
4
|
Summary: Socket Security Python SDK
|
|
5
5
|
Project-URL: Homepage, https://github.com/SocketDev/socket-sdk-python
|
|
6
6
|
Author-email: Douglas Coburn <douglas@socket.dev>
|
|
@@ -342,7 +342,11 @@ Stream a diff between two full scans. Returns a scan diff.
|
|
|
342
342
|
|
|
343
343
|
fullscans.stream(org_slug, full_scan_id, use_types=False)
|
|
344
344
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
345
|
-
Stream all SBOM artifacts for a full scan.
|
|
345
|
+
Stream all SBOM artifacts for a full scan. If the scan is still being analyzed, the SDK polls
|
|
346
|
+
cached results until they are ready, backing off from 5 to 10 seconds between attempts, and
|
|
347
|
+
raises ``APITimeout`` if they are not ready within the polling budget. Transient failures
|
|
348
|
+
(HTTP 408/502/503/504, timeouts, dropped connections) are retried within the budget; other
|
|
349
|
+
errors raise immediately.
|
|
346
350
|
|
|
347
351
|
**Usage:**
|
|
348
352
|
|
|
@@ -355,11 +359,17 @@ Stream all SBOM artifacts for a full scan.
|
|
|
355
359
|
# With typed response
|
|
356
360
|
print(socket.fullscans.stream("org_slug", "full_scan_id", use_types=True))
|
|
357
361
|
|
|
362
|
+
# Wait up to 10 minutes for analysis to finish
|
|
363
|
+
print(socket.fullscans.stream("org_slug", "full_scan_id", poll_timeout_seconds=600))
|
|
364
|
+
|
|
358
365
|
**PARAMETERS:**
|
|
359
366
|
|
|
360
367
|
- **org_slug (str)** - The organization name
|
|
361
368
|
- **full_scan_id (str)** - The ID of the full scan
|
|
362
369
|
- **use_types (bool)** - Whether to return typed response objects (default: False)
|
|
370
|
+
- **poll_timeout_seconds (float)** - Keyword-only. Total time to wait for results (default: the SDK's configured ``timeout``)
|
|
371
|
+
- **poll_initial_interval_seconds (float)** - Keyword-only. Wait before the first retry (default: 5.0)
|
|
372
|
+
- **poll_max_interval_seconds (float)** - Keyword-only. Longest wait between retries (default: 10.0)
|
|
363
373
|
|
|
364
374
|
fullscans.metadata(org_slug, full_scan_id, use_types=False)
|
|
365
375
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
@@ -291,7 +291,11 @@ Stream a diff between two full scans. Returns a scan diff.
|
|
|
291
291
|
|
|
292
292
|
fullscans.stream(org_slug, full_scan_id, use_types=False)
|
|
293
293
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
294
|
-
Stream all SBOM artifacts for a full scan.
|
|
294
|
+
Stream all SBOM artifacts for a full scan. If the scan is still being analyzed, the SDK polls
|
|
295
|
+
cached results until they are ready, backing off from 5 to 10 seconds between attempts, and
|
|
296
|
+
raises ``APITimeout`` if they are not ready within the polling budget. Transient failures
|
|
297
|
+
(HTTP 408/502/503/504, timeouts, dropped connections) are retried within the budget; other
|
|
298
|
+
errors raise immediately.
|
|
295
299
|
|
|
296
300
|
**Usage:**
|
|
297
301
|
|
|
@@ -304,11 +308,17 @@ Stream all SBOM artifacts for a full scan.
|
|
|
304
308
|
# With typed response
|
|
305
309
|
print(socket.fullscans.stream("org_slug", "full_scan_id", use_types=True))
|
|
306
310
|
|
|
311
|
+
# Wait up to 10 minutes for analysis to finish
|
|
312
|
+
print(socket.fullscans.stream("org_slug", "full_scan_id", poll_timeout_seconds=600))
|
|
313
|
+
|
|
307
314
|
**PARAMETERS:**
|
|
308
315
|
|
|
309
316
|
- **org_slug (str)** - The organization name
|
|
310
317
|
- **full_scan_id (str)** - The ID of the full scan
|
|
311
318
|
- **use_types (bool)** - Whether to return typed response objects (default: False)
|
|
319
|
+
- **poll_timeout_seconds (float)** - Keyword-only. Total time to wait for results (default: the SDK's configured ``timeout``)
|
|
320
|
+
- **poll_initial_interval_seconds (float)** - Keyword-only. Wait before the first retry (default: 5.0)
|
|
321
|
+
- **poll_max_interval_seconds (float)** - Keyword-only. Longest wait between retries (default: 10.0)
|
|
312
322
|
|
|
313
323
|
fullscans.metadata(org_slug, full_scan_id, use_types=False)
|
|
314
324
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import os
|
|
2
2
|
from socketdev.core.api import API
|
|
3
|
+
from socketdev.core.retired_token import reject_retired_token
|
|
4
|
+
from socketdev.core.token_selection import select_token
|
|
3
5
|
from socketdev.dependencies import Dependencies
|
|
4
6
|
from socketdev.diffscans import DiffScans
|
|
5
7
|
from socketdev.export import Export
|
|
@@ -53,21 +55,15 @@ request_timeout = 1200
|
|
|
53
55
|
|
|
54
56
|
class socketdev:
|
|
55
57
|
def __init__(self, token: Optional[str] = None, timeout: int = 1200, allow_unverified: bool = False, user_agent: Optional[str] = None):
|
|
56
|
-
|
|
57
|
-
if token is None:
|
|
58
|
-
token = (
|
|
59
|
-
os.getenv("SOCKET_SECURITY_API_TOKEN") or
|
|
60
|
-
os.getenv("SOCKET_SECURITY_API_KEY") or
|
|
61
|
-
os.getenv("SOCKET_API_KEY") or
|
|
62
|
-
os.getenv("SOCKET_API_TOKEN")
|
|
63
|
-
)
|
|
64
|
-
|
|
58
|
+
token = select_token(token, os.environ)
|
|
65
59
|
if token is None:
|
|
66
60
|
raise ValueError(
|
|
67
61
|
"API token is required. Provide it as a parameter or set one of these environment variables: "
|
|
68
62
|
"SOCKET_SECURITY_API_TOKEN, SOCKET_SECURITY_API_KEY, SOCKET_API_KEY, SOCKET_API_TOKEN"
|
|
69
63
|
)
|
|
70
64
|
|
|
65
|
+
reject_retired_token(token)
|
|
66
|
+
|
|
71
67
|
self.api = API()
|
|
72
68
|
self.token = token + ":"
|
|
73
69
|
self.api.encode_key(self.token)
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import base64
|
|
2
|
+
from typing import Optional
|
|
2
3
|
from socketdev.log import log
|
|
4
|
+
from socketdev.core.retired_token import reject_retired_basic_auth_token
|
|
3
5
|
|
|
4
6
|
import requests
|
|
5
7
|
from socketdev.core.classes import Response
|
|
@@ -29,6 +31,7 @@ class API:
|
|
|
29
31
|
self.user_agent = None
|
|
30
32
|
|
|
31
33
|
def encode_key(self, token: str):
|
|
34
|
+
reject_retired_basic_auth_token(token)
|
|
32
35
|
self.encoded_key = base64.b64encode(token.encode()).decode("ascii")
|
|
33
36
|
|
|
34
37
|
def set_timeout(self, timeout: int):
|
|
@@ -47,6 +50,8 @@ class API:
|
|
|
47
50
|
payload: [dict, str] = None,
|
|
48
51
|
files: list = None,
|
|
49
52
|
method: str = "GET",
|
|
53
|
+
*,
|
|
54
|
+
request_timeout: Optional[float] = None,
|
|
50
55
|
) -> Response:
|
|
51
56
|
if self.encoded_key is None or self.encoded_key == "":
|
|
52
57
|
raise APIKeyMissing
|
|
@@ -68,7 +73,8 @@ class API:
|
|
|
68
73
|
|
|
69
74
|
response = requests.request(
|
|
70
75
|
method.upper(), url, headers=headers, data=payload, files=files,
|
|
71
|
-
timeout=self.request_timeout
|
|
76
|
+
timeout=self.request_timeout if request_timeout is None else request_timeout,
|
|
77
|
+
verify=not self.allow_unverified
|
|
72
78
|
)
|
|
73
79
|
request_duration = time.time() - start_time
|
|
74
80
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import hashlib
|
|
2
|
+
import hmac
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
RETIRED_TOKEN_SHA256 = "9cab58b24140ee12c08e265729d246f9200f8ef9b1d884f90c06c4e6b69adf18"
|
|
6
|
+
RETIRED_TOKEN_ERROR = (
|
|
7
|
+
"This API token has been retired. Create a new API token in Socket "
|
|
8
|
+
"and update your configuration."
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# Fingerprint identifies a retired credential; it is not a password verifier.
|
|
13
|
+
def _matches_retired_digest(token: Optional[str], digest: str) -> bool:
|
|
14
|
+
if token is None:
|
|
15
|
+
return False
|
|
16
|
+
token_digest = hashlib.sha256(token.strip().encode("utf-8")).hexdigest()
|
|
17
|
+
return hmac.compare_digest(token_digest, digest)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _reject_retired_token(token: Optional[str], digest: str) -> None:
|
|
21
|
+
if _matches_retired_digest(token, digest):
|
|
22
|
+
raise ValueError(RETIRED_TOKEN_ERROR)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _reject_basic_auth_token(token: str, digest: str) -> None:
|
|
26
|
+
_reject_retired_token(token.partition(":")[0], digest)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def reject_retired_token(token: Optional[str]) -> None:
|
|
30
|
+
_reject_retired_token(token, RETIRED_TOKEN_SHA256)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def reject_retired_basic_auth_token(token: str) -> None:
|
|
34
|
+
_reject_basic_auth_token(token, RETIRED_TOKEN_SHA256)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from typing import Mapping, Optional
|
|
2
|
+
|
|
3
|
+
TOKEN_ENVIRONMENT_VARIABLES = (
|
|
4
|
+
"SOCKET_SECURITY_API_TOKEN",
|
|
5
|
+
"SOCKET_SECURITY_API_KEY",
|
|
6
|
+
"SOCKET_API_KEY",
|
|
7
|
+
"SOCKET_API_TOKEN",
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def select_token(
|
|
12
|
+
explicit_token: Optional[str], environment: Mapping[str, str]
|
|
13
|
+
) -> Optional[str]:
|
|
14
|
+
if explicit_token is not None:
|
|
15
|
+
return explicit_token
|
|
16
|
+
return next(
|
|
17
|
+
(environment[name] for name in TOKEN_ENVIRONMENT_VARIABLES if environment.get(name)),
|
|
18
|
+
None,
|
|
19
|
+
)
|
|
@@ -4,9 +4,12 @@ from enum import Enum
|
|
|
4
4
|
from typing import Any, Dict, List, Optional, Union
|
|
5
5
|
from dataclasses import dataclass, asdict, field
|
|
6
6
|
import urllib.parse
|
|
7
|
+
import math
|
|
8
|
+
import time
|
|
7
9
|
from ..core.dedupe import Dedupe
|
|
8
10
|
from ..core.enums import unknown_enum_value
|
|
9
11
|
from ..utils import IntegrationType, Utils
|
|
12
|
+
from ..exceptions import APIFailure, APITimeout
|
|
10
13
|
|
|
11
14
|
log = logging.getLogger("socketdev")
|
|
12
15
|
|
|
@@ -960,15 +963,65 @@ class FullScans:
|
|
|
960
963
|
)
|
|
961
964
|
return {}
|
|
962
965
|
|
|
963
|
-
def stream(
|
|
964
|
-
|
|
965
|
-
|
|
966
|
+
def stream(
|
|
967
|
+
self,
|
|
968
|
+
org_slug: str,
|
|
969
|
+
full_scan_id: str,
|
|
970
|
+
use_types: bool = False,
|
|
971
|
+
*,
|
|
972
|
+
poll_timeout_seconds: Optional[float] = None,
|
|
973
|
+
poll_initial_interval_seconds: float = 5.0,
|
|
974
|
+
poll_max_interval_seconds: float = 10.0,
|
|
975
|
+
) -> Union[dict, FullScanStreamResponse]:
|
|
976
|
+
request_timeout = self.api.request_timeout
|
|
977
|
+
timeout = request_timeout if poll_timeout_seconds is None else poll_timeout_seconds
|
|
978
|
+
values = (timeout, poll_initial_interval_seconds, poll_max_interval_seconds, request_timeout)
|
|
979
|
+
if any(
|
|
980
|
+
isinstance(value, bool)
|
|
981
|
+
or not isinstance(value, (int, float))
|
|
982
|
+
or not math.isfinite(value)
|
|
983
|
+
or value <= 0
|
|
984
|
+
for value in values
|
|
985
|
+
):
|
|
986
|
+
raise ValueError("Full scan polling timeout and intervals must be positive finite numbers")
|
|
987
|
+
if poll_initial_interval_seconds > poll_max_interval_seconds:
|
|
988
|
+
raise ValueError("Initial polling interval must not exceed maximum polling interval")
|
|
989
|
+
|
|
990
|
+
path = (
|
|
991
|
+
"orgs/" + urllib.parse.quote(org_slug, safe="") + "/full-scans/"
|
|
992
|
+
+ urllib.parse.quote(full_scan_id, safe="") + "?cached=true"
|
|
993
|
+
)
|
|
994
|
+
deadline = time.monotonic() + timeout
|
|
995
|
+
interval = poll_initial_interval_seconds
|
|
996
|
+
while True:
|
|
997
|
+
retry_error = None
|
|
998
|
+
try:
|
|
999
|
+
response = self.api.do_request(
|
|
1000
|
+
path=path,
|
|
1001
|
+
method="GET",
|
|
1002
|
+
request_timeout=min(float(request_timeout), max(deadline - time.monotonic(), 0.001)),
|
|
1003
|
+
)
|
|
1004
|
+
except APIFailure as error:
|
|
1005
|
+
if not error.is_transient_error():
|
|
1006
|
+
raise
|
|
1007
|
+
retry_error = error
|
|
1008
|
+
else:
|
|
1009
|
+
if response.status_code != 202:
|
|
1010
|
+
break
|
|
1011
|
+
response.close()
|
|
1012
|
+
# Give up now if the next attempt could not start before the deadline,
|
|
1013
|
+
# rather than sleeping out the rest of the budget and never polling again.
|
|
1014
|
+
if deadline - time.monotonic() <= interval:
|
|
1015
|
+
raise APITimeout("Timed out waiting for full scan results") from retry_error
|
|
1016
|
+
time.sleep(interval)
|
|
1017
|
+
interval = min(poll_max_interval_seconds, interval * 1.5)
|
|
966
1018
|
|
|
967
1019
|
if response.status_code == 200:
|
|
968
1020
|
try:
|
|
969
1021
|
stream_str = []
|
|
970
1022
|
artifacts = {}
|
|
971
1023
|
result = response.text
|
|
1024
|
+
response.close()
|
|
972
1025
|
result = result.strip('"').strip()
|
|
973
1026
|
for line in result.split("\n"):
|
|
974
1027
|
if line != '"' and line != "" and line is not None:
|
|
@@ -993,6 +1046,7 @@ class FullScans:
|
|
|
993
1046
|
return artifacts
|
|
994
1047
|
|
|
995
1048
|
except Exception as e:
|
|
1049
|
+
response.close()
|
|
996
1050
|
error_message = f"Error parsing stream response: {str(e)}"
|
|
997
1051
|
log.error(error_message)
|
|
998
1052
|
if use_types:
|
|
@@ -1001,7 +1055,10 @@ class FullScans:
|
|
|
1001
1055
|
)
|
|
1002
1056
|
return {}
|
|
1003
1057
|
|
|
1004
|
-
|
|
1058
|
+
try:
|
|
1059
|
+
error_message = response.json().get("error", {}).get("message", "Unknown error")
|
|
1060
|
+
finally:
|
|
1061
|
+
response.close()
|
|
1005
1062
|
log.error(f"Error streaming full scan: {response.status_code}, message: {error_message}")
|
|
1006
1063
|
if use_types:
|
|
1007
1064
|
return FullScanStreamResponse.from_dict(
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "3.6.2"
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"""Reusable localhost HTTP fixture for real Socket SDK transport tests."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import threading
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
|
9
|
+
from typing import Callable, Dict, List, Optional, Tuple
|
|
10
|
+
from urllib.parse import parse_qs, urlsplit
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass
|
|
14
|
+
class SocketRequest:
|
|
15
|
+
method: str
|
|
16
|
+
path: str
|
|
17
|
+
query: Dict[str, List[str]]
|
|
18
|
+
headers: Dict[str, str]
|
|
19
|
+
body: bytes
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass
|
|
23
|
+
class SocketResponse:
|
|
24
|
+
status: int
|
|
25
|
+
payload: object
|
|
26
|
+
raw_body: Optional[bytes] = None
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
Route = Callable[[SocketRequest], SocketResponse]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class SocketApiFixture:
|
|
33
|
+
def __init__(self) -> None:
|
|
34
|
+
self.requests: List[SocketRequest] = []
|
|
35
|
+
self._routes: Dict[Tuple[str, str], Route] = {}
|
|
36
|
+
self._server: Optional[ThreadingHTTPServer] = None
|
|
37
|
+
self._thread: Optional[threading.Thread] = None
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def base_url(self) -> str:
|
|
41
|
+
if self._server is None:
|
|
42
|
+
raise RuntimeError("Socket API fixture is not running")
|
|
43
|
+
host, port = self._server.server_address
|
|
44
|
+
return f"http://{host}:{port}/v0"
|
|
45
|
+
|
|
46
|
+
def route(
|
|
47
|
+
self,
|
|
48
|
+
method: str,
|
|
49
|
+
path: str,
|
|
50
|
+
response: SocketResponse | Route,
|
|
51
|
+
) -> None:
|
|
52
|
+
if callable(response):
|
|
53
|
+
handler = response
|
|
54
|
+
else:
|
|
55
|
+
|
|
56
|
+
def handler(_request: SocketRequest) -> SocketResponse:
|
|
57
|
+
return response
|
|
58
|
+
|
|
59
|
+
self._routes[(method.upper(), path)] = handler
|
|
60
|
+
|
|
61
|
+
def start(self) -> None:
|
|
62
|
+
fixture = self
|
|
63
|
+
|
|
64
|
+
class Handler(BaseHTTPRequestHandler):
|
|
65
|
+
def do_GET(self) -> None:
|
|
66
|
+
self._dispatch()
|
|
67
|
+
|
|
68
|
+
def do_POST(self) -> None:
|
|
69
|
+
self._dispatch()
|
|
70
|
+
|
|
71
|
+
def _dispatch(self) -> None:
|
|
72
|
+
parsed = urlsplit(self.path)
|
|
73
|
+
length = int(self.headers.get("Content-Length", "0"))
|
|
74
|
+
request = SocketRequest(
|
|
75
|
+
method=self.command,
|
|
76
|
+
path=parsed.path.removeprefix("/v0/"),
|
|
77
|
+
query=parse_qs(parsed.query, keep_blank_values=True),
|
|
78
|
+
headers=dict(self.headers.items()),
|
|
79
|
+
body=self.rfile.read(length),
|
|
80
|
+
)
|
|
81
|
+
fixture.requests.append(request)
|
|
82
|
+
route = fixture._routes.get((request.method, request.path))
|
|
83
|
+
if route is None and request.path == "organizations":
|
|
84
|
+
response = SocketResponse(
|
|
85
|
+
200,
|
|
86
|
+
{"organizations": {"org-fixture": {"slug": "fixture-org"}}},
|
|
87
|
+
)
|
|
88
|
+
elif route is None:
|
|
89
|
+
response = SocketResponse(404, {"error": {"message": "Not found"}})
|
|
90
|
+
else:
|
|
91
|
+
response = route(request)
|
|
92
|
+
body = response.raw_body
|
|
93
|
+
if body is None:
|
|
94
|
+
body = json.dumps(response.payload).encode("utf-8")
|
|
95
|
+
self.send_response(response.status)
|
|
96
|
+
self.send_header("Content-Type", "application/json")
|
|
97
|
+
self.send_header("Content-Length", str(len(body)))
|
|
98
|
+
self.end_headers()
|
|
99
|
+
self.wfile.write(body)
|
|
100
|
+
|
|
101
|
+
def log_message(self, _format: str, *args: object) -> None:
|
|
102
|
+
return
|
|
103
|
+
|
|
104
|
+
self._server = ThreadingHTTPServer(("127.0.0.1", 0), Handler)
|
|
105
|
+
self._thread = threading.Thread(target=self._server.serve_forever, daemon=True)
|
|
106
|
+
self._thread.start()
|
|
107
|
+
|
|
108
|
+
def close(self) -> None:
|
|
109
|
+
if self._server is not None:
|
|
110
|
+
self._server.shutdown()
|
|
111
|
+
self._server.server_close()
|
|
112
|
+
self._server = None
|
|
113
|
+
if self._thread is not None:
|
|
114
|
+
self._thread.join(timeout=2)
|
|
115
|
+
self._thread = None
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def socket_api_fixture() -> SocketApiFixture:
|
|
119
|
+
fixture = SocketApiFixture()
|
|
120
|
+
fixture.start()
|
|
121
|
+
return fixture
|