socketdev 3.0.33__tar.gz → 3.1.1__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.0.33 → socketdev-3.1.1}/.github/workflows/version-check.yml +49 -10
- {socketdev-3.0.33 → socketdev-3.1.1}/.gitignore +4 -1
- socketdev-3.1.1/.hooks/sync_version.py +172 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/PKG-INFO +10 -6
- {socketdev-3.0.33 → socketdev-3.1.1}/README.rst +8 -4
- {socketdev-3.0.33 → socketdev-3.1.1}/pyproject.toml +2 -2
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/core/issues.py +1 -1
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/purl/__init__.py +16 -2
- socketdev-3.1.1/socketdev/version.py +1 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/tests/integration/test_all_endpoints.py +14 -10
- {socketdev-3.0.33 → socketdev-3.1.1}/tests/integration/test_comprehensive_integration.py +9 -5
- {socketdev-3.0.33 → socketdev-3.1.1}/tests/unit/test_all_endpoints_unit.py +32 -15
- socketdev-3.1.1/tests/unit/test_issues_did_you_mean_props.py +28 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/tests/unit/test_socket_sdk_unit.py +3 -3
- {socketdev-3.0.33 → socketdev-3.1.1}/tests/unit/test_working_endpoints_unit.py +4 -4
- {socketdev-3.0.33 → socketdev-3.1.1}/uv.lock +1 -1
- socketdev-3.0.33/.hooks/sync_version.py +0 -95
- socketdev-3.0.33/socketdev/version.py +0 -1
- {socketdev-3.0.33 → socketdev-3.1.1}/.github/CODEOWNERS +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/.github/PULL_REQUEST_TEMPLATE/bug-fix.md +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/.github/PULL_REQUEST_TEMPLATE/feature.md +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/.github/PULL_REQUEST_TEMPLATE/improvement.md +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/.github/workflows/pr-preview.yml +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/.github/workflows/release.yml +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/.python-version +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/LICENSE +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/scripts/build.sh +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/scripts/deploy-test-pypi.sh +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/alertfullscansearch/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/alerts/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/alerttypes/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/analytics/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/apitokens/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/auditlog/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/basics/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/core/api.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/core/classes.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/core/dedupe.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/dependencies/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/diffscans/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/exceptions.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/export/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/fixes/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/fullscans/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/historical/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/labels/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/licensemetadata/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/log.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/npm/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/openapi/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/org/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/quota/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/report/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/repos/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/repositories/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/sbom/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/settings/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/supportedfiles/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/telemetry/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/threatfeed/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/tools/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/triage/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/uploadmanifests/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/utils/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/socketdev/webhooks/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/tests/README.md +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/tests/conftest.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/tests/integration/test_diffscans_integration.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/tests/integration/test_new_endpoints.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/tests/run_tests.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/tests/unit/__init__.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/tests/unit/test_dedupe.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/tests/unit/test_socket_alert_category.py +0 -0
- {socketdev-3.0.33 → socketdev-3.1.1}/tests/unit/test_upload_manifests.py +0 -0
|
@@ -4,8 +4,8 @@ on:
|
|
|
4
4
|
types: [opened, synchronize, ready_for_review]
|
|
5
5
|
paths:
|
|
6
6
|
- 'socketdev/**'
|
|
7
|
-
- 'setup.py'
|
|
8
7
|
- 'pyproject.toml'
|
|
8
|
+
- 'uv.lock'
|
|
9
9
|
|
|
10
10
|
permissions:
|
|
11
11
|
contents: read
|
|
@@ -33,16 +33,55 @@ jobs:
|
|
|
33
33
|
MAIN_VERSION=$(grep -o "__version__.*" socketdev/version.py | awk '{print $3}' | tr -d '"' | tr -d "'")
|
|
34
34
|
echo "MAIN_VERSION=$MAIN_VERSION" >> $GITHUB_ENV
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
export PR_VERSION
|
|
37
|
+
export MAIN_VERSION
|
|
38
|
+
|
|
39
|
+
# Compare against both main and latest published PyPI release.
|
|
40
|
+
python3 <<'PY'
|
|
41
|
+
import json
|
|
42
|
+
import os
|
|
43
|
+
import urllib.request
|
|
38
44
|
from packaging import version
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
|
|
46
|
+
pr_ver = version.parse(os.environ["PR_VERSION"])
|
|
47
|
+
main_ver = version.parse(os.environ["MAIN_VERSION"])
|
|
48
|
+
|
|
49
|
+
with urllib.request.urlopen("https://pypi.org/pypi/socketdev/json") as response:
|
|
50
|
+
pypi_data = json.load(response)
|
|
51
|
+
|
|
52
|
+
published_versions = []
|
|
53
|
+
for raw in pypi_data.get("releases", {}).keys():
|
|
54
|
+
parsed = version.parse(raw)
|
|
55
|
+
if not parsed.is_prerelease and not parsed.is_devrelease:
|
|
56
|
+
published_versions.append(parsed)
|
|
57
|
+
|
|
58
|
+
pypi_ver = max(published_versions) if published_versions else version.parse("0.0.0")
|
|
59
|
+
required_floor = max(main_ver, pypi_ver)
|
|
60
|
+
|
|
61
|
+
if pr_ver <= required_floor:
|
|
62
|
+
print(
|
|
63
|
+
f"❌ Version must be greater than main and PyPI! "
|
|
64
|
+
f"Main: {main_ver}, PyPI: {pypi_ver}, PR: {pr_ver}"
|
|
65
|
+
)
|
|
66
|
+
raise SystemExit(1)
|
|
67
|
+
|
|
68
|
+
print(
|
|
69
|
+
f"✅ Version properly incremented. "
|
|
70
|
+
f"Main: {main_ver}, PyPI: {pypi_ver}, PR: {pr_ver}"
|
|
71
|
+
)
|
|
72
|
+
PY
|
|
73
|
+
|
|
74
|
+
- name: Require uv.lock update when pyproject changes
|
|
75
|
+
run: |
|
|
76
|
+
CHANGED_FILES="$(git diff --name-only origin/main...HEAD)"
|
|
77
|
+
|
|
78
|
+
if echo "$CHANGED_FILES" | grep -qx 'pyproject.toml'; then
|
|
79
|
+
if ! echo "$CHANGED_FILES" | grep -qx 'uv.lock'; then
|
|
80
|
+
echo "❌ pyproject.toml changed, but uv.lock was not updated."
|
|
81
|
+
echo "Run 'uv lock' and commit uv.lock with the version bump."
|
|
82
|
+
exit 1
|
|
83
|
+
fi
|
|
84
|
+
fi
|
|
46
85
|
|
|
47
86
|
- name: Manage PR Comment
|
|
48
87
|
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
import subprocess
|
|
3
|
+
import pathlib
|
|
4
|
+
import re
|
|
5
|
+
import sys
|
|
6
|
+
import urllib.request
|
|
7
|
+
import json
|
|
8
|
+
|
|
9
|
+
VERSION_FILE = pathlib.Path("socketdev/version.py")
|
|
10
|
+
PYPROJECT_FILE = pathlib.Path("pyproject.toml")
|
|
11
|
+
UV_LOCK_FILE = pathlib.Path("uv.lock")
|
|
12
|
+
|
|
13
|
+
VERSION_PATTERN = re.compile(r"__version__\s*=\s*['\"]([^'\"]+)['\"]")
|
|
14
|
+
PYPROJECT_PATTERN = re.compile(r'^version\s*=\s*".*"$', re.MULTILINE)
|
|
15
|
+
STABLE_VERSION_PATTERN = re.compile(r"^\d+\.\d+\.\d+$")
|
|
16
|
+
PYPI_PROD_API = "https://pypi.org/pypi/socketdev/json"
|
|
17
|
+
PYPI_TEST_API = "https://test.pypi.org/pypi/socketdev/json"
|
|
18
|
+
|
|
19
|
+
def read_version_from_version_file(path: pathlib.Path) -> str:
|
|
20
|
+
content = path.read_text()
|
|
21
|
+
match = VERSION_PATTERN.search(content)
|
|
22
|
+
if not match:
|
|
23
|
+
print(f"❌ Could not find __version__ in {path}")
|
|
24
|
+
sys.exit(1)
|
|
25
|
+
return match.group(1)
|
|
26
|
+
|
|
27
|
+
def read_version_from_git(path: str) -> str:
|
|
28
|
+
try:
|
|
29
|
+
output = subprocess.check_output(["git", "show", f"HEAD:{path}"], text=True)
|
|
30
|
+
match = VERSION_PATTERN.search(output)
|
|
31
|
+
if not match:
|
|
32
|
+
return None
|
|
33
|
+
return match.group(1)
|
|
34
|
+
except subprocess.CalledProcessError:
|
|
35
|
+
return None
|
|
36
|
+
|
|
37
|
+
def bump_patch_version(version: str) -> str:
|
|
38
|
+
if ".dev" in version:
|
|
39
|
+
version = version.split(".dev")[0]
|
|
40
|
+
parts = version.split(".")
|
|
41
|
+
parts[-1] = str(int(parts[-1]) + 1)
|
|
42
|
+
return ".".join(parts)
|
|
43
|
+
|
|
44
|
+
def parse_stable_version(version: str):
|
|
45
|
+
if not STABLE_VERSION_PATTERN.fullmatch(version):
|
|
46
|
+
return None
|
|
47
|
+
return tuple(int(part) for part in version.split("."))
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def format_stable_version(version_parts) -> str:
|
|
51
|
+
return ".".join(str(part) for part in version_parts)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def fetch_existing_versions(api_url: str) -> set:
|
|
55
|
+
try:
|
|
56
|
+
with urllib.request.urlopen(api_url) as response:
|
|
57
|
+
data = json.load(response)
|
|
58
|
+
return set(data.get("releases", {}).keys())
|
|
59
|
+
except Exception as e:
|
|
60
|
+
print(f"⚠️ Warning: Failed to fetch versions from {api_url}: {e}")
|
|
61
|
+
return set()
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def fetch_latest_stable_pypi_version():
|
|
65
|
+
versions = fetch_existing_versions(PYPI_PROD_API)
|
|
66
|
+
stable_versions = []
|
|
67
|
+
for ver in versions:
|
|
68
|
+
parsed = parse_stable_version(ver)
|
|
69
|
+
if parsed is not None:
|
|
70
|
+
stable_versions.append(parsed)
|
|
71
|
+
if not stable_versions:
|
|
72
|
+
return None
|
|
73
|
+
return max(stable_versions)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def find_next_available_dev_version(base_version: str) -> str:
|
|
77
|
+
existing_versions = fetch_existing_versions(PYPI_TEST_API)
|
|
78
|
+
for i in range(1, 100):
|
|
79
|
+
candidate = f"{base_version}.dev{i}"
|
|
80
|
+
if candidate not in existing_versions:
|
|
81
|
+
return candidate
|
|
82
|
+
print("❌ Could not find available .devN slot after 100 attempts.")
|
|
83
|
+
sys.exit(1)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def find_next_stable_patch_version(current_version: str) -> str:
|
|
87
|
+
current_stable = current_version.split(".dev")[0] if ".dev" in current_version else current_version
|
|
88
|
+
current_parts = parse_stable_version(current_stable)
|
|
89
|
+
if current_parts is None:
|
|
90
|
+
print(f"❌ Unsupported version format for stable bump: {current_version}")
|
|
91
|
+
sys.exit(1)
|
|
92
|
+
|
|
93
|
+
latest_pypi_parts = fetch_latest_stable_pypi_version()
|
|
94
|
+
base_parts = max([current_parts, latest_pypi_parts] if latest_pypi_parts else [current_parts])
|
|
95
|
+
next_parts = (base_parts[0], base_parts[1], base_parts[2] + 1)
|
|
96
|
+
return format_stable_version(next_parts)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def inject_version(version: str):
|
|
100
|
+
print(f"🔁 Updating version to: {version}")
|
|
101
|
+
|
|
102
|
+
# Update version.py
|
|
103
|
+
VERSION_FILE.write_text(f'__version__ = "{version}"\n')
|
|
104
|
+
|
|
105
|
+
# Update pyproject.toml if it has a version field (it shouldn't with hatch, but just in case)
|
|
106
|
+
pyproject = PYPROJECT_FILE.read_text()
|
|
107
|
+
if PYPROJECT_PATTERN.search(pyproject):
|
|
108
|
+
new_pyproject = PYPROJECT_PATTERN.sub(f'version = "{version}"', pyproject)
|
|
109
|
+
PYPROJECT_FILE.write_text(new_pyproject)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def run_uv_lock() -> bool:
|
|
113
|
+
before = UV_LOCK_FILE.read_bytes() if UV_LOCK_FILE.exists() else b""
|
|
114
|
+
try:
|
|
115
|
+
subprocess.run(["uv", "lock"], check=True, text=True)
|
|
116
|
+
except FileNotFoundError:
|
|
117
|
+
print("❌ `uv` is required but was not found in PATH.")
|
|
118
|
+
sys.exit(1)
|
|
119
|
+
except subprocess.CalledProcessError:
|
|
120
|
+
print("❌ `uv lock` failed. Please run it manually and fix any errors.")
|
|
121
|
+
sys.exit(1)
|
|
122
|
+
|
|
123
|
+
after = UV_LOCK_FILE.read_bytes() if UV_LOCK_FILE.exists() else b""
|
|
124
|
+
return before != after
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def main():
|
|
128
|
+
dev_mode = "--dev" in sys.argv
|
|
129
|
+
current_version = read_version_from_version_file(VERSION_FILE)
|
|
130
|
+
previous_version = read_version_from_git("socketdev/version.py")
|
|
131
|
+
|
|
132
|
+
print(f"Current: {current_version}, Previous: {previous_version}")
|
|
133
|
+
|
|
134
|
+
if current_version == previous_version:
|
|
135
|
+
if dev_mode:
|
|
136
|
+
base_version = current_version.split(".dev")[0] if ".dev" in current_version else current_version
|
|
137
|
+
new_version = find_next_available_dev_version(base_version)
|
|
138
|
+
inject_version(new_version)
|
|
139
|
+
uv_lock_changed = run_uv_lock()
|
|
140
|
+
lock_hint = " and uv.lock" if uv_lock_changed else ""
|
|
141
|
+
print(f"⚠️ Version was unchanged — auto-bumped. Please git add{lock_hint} + commit again.")
|
|
142
|
+
sys.exit(0)
|
|
143
|
+
else:
|
|
144
|
+
new_version = find_next_stable_patch_version(current_version)
|
|
145
|
+
inject_version(new_version)
|
|
146
|
+
uv_lock_changed = run_uv_lock()
|
|
147
|
+
lock_hint = " and uv.lock" if uv_lock_changed else ""
|
|
148
|
+
print(f"⚠️ Version was unchanged — auto-bumped to {new_version}. Please git add{lock_hint} + commit again.")
|
|
149
|
+
sys.exit(1)
|
|
150
|
+
else:
|
|
151
|
+
if not dev_mode:
|
|
152
|
+
current_parts = parse_stable_version(current_version)
|
|
153
|
+
latest_pypi_parts = fetch_latest_stable_pypi_version()
|
|
154
|
+
if current_parts is not None and latest_pypi_parts is not None and current_parts <= latest_pypi_parts:
|
|
155
|
+
next_parts = (latest_pypi_parts[0], latest_pypi_parts[1], latest_pypi_parts[2] + 1)
|
|
156
|
+
new_version = format_stable_version(next_parts)
|
|
157
|
+
inject_version(new_version)
|
|
158
|
+
uv_lock_changed = run_uv_lock()
|
|
159
|
+
lock_hint = " and uv.lock" if uv_lock_changed else ""
|
|
160
|
+
print(f"⚠️ Version {current_version} is already published on PyPI — auto-bumped to {new_version}. Please git add{lock_hint} + commit again.")
|
|
161
|
+
sys.exit(1)
|
|
162
|
+
|
|
163
|
+
uv_lock_changed = run_uv_lock()
|
|
164
|
+
if uv_lock_changed:
|
|
165
|
+
print("⚠️ Version already bumped, but uv.lock was out of date and has been updated. Please git add uv.lock + commit again.")
|
|
166
|
+
sys.exit(1)
|
|
167
|
+
|
|
168
|
+
print("✅ Version already bumped and uv.lock is up to date — proceeding.")
|
|
169
|
+
sys.exit(0)
|
|
170
|
+
|
|
171
|
+
if __name__ == "__main__":
|
|
172
|
+
main()
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: socketdev
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.1.1
|
|
4
4
|
Summary: Socket Security Python SDK
|
|
5
|
-
Project-URL: Homepage, https://github.com/
|
|
5
|
+
Project-URL: Homepage, https://github.com/SocketDev/socket-sdk-python
|
|
6
6
|
Author-email: Douglas Coburn <douglas@socket.dev>
|
|
7
7
|
Maintainer-email: Douglas Coburn <douglas@socket.dev>
|
|
8
8
|
License: MIT License
|
|
@@ -78,9 +78,11 @@ Supported Functions
|
|
|
78
78
|
-------------------
|
|
79
79
|
|
|
80
80
|
|
|
81
|
-
purl.post(license, components)
|
|
82
|
-
""""""""""""""""""""""""""""""
|
|
83
|
-
Retrieve
|
|
81
|
+
purl.post(license, components, org_slug=None)
|
|
82
|
+
"""""""""""""""""""""""""""""""""""""""""""""
|
|
83
|
+
Retrieve package information for one or more PURLs. Pass ``org_slug`` to use the
|
|
84
|
+
current org-scoped endpoint. Omitting ``org_slug`` keeps the legacy deprecated
|
|
85
|
+
endpoint for backwards compatibility.
|
|
84
86
|
|
|
85
87
|
**Usage:**
|
|
86
88
|
|
|
@@ -88,6 +90,7 @@ Retrieve the package information for a purl post
|
|
|
88
90
|
|
|
89
91
|
from socketdev import socketdev
|
|
90
92
|
socket = socketdev(token="REPLACE_ME")
|
|
93
|
+
org_slug = "your-org-slug"
|
|
91
94
|
license = "true"
|
|
92
95
|
components = [
|
|
93
96
|
{
|
|
@@ -97,12 +100,13 @@ Retrieve the package information for a purl post
|
|
|
97
100
|
"purl": "pkg:pypi/socketsecurity"
|
|
98
101
|
}
|
|
99
102
|
]
|
|
100
|
-
print(socket.purl.post(license, components))
|
|
103
|
+
print(socket.purl.post(license, components, org_slug=org_slug))
|
|
101
104
|
|
|
102
105
|
**PARAMETERS:**
|
|
103
106
|
|
|
104
107
|
- **license (str)** - The license parameter if enabled will show alerts and license information. If disabled will only show the basic package metadata and scores. Default is true
|
|
105
108
|
- **components (array{dict})** - The components list of packages urls
|
|
109
|
+
- **org_slug (str, optional)** - Organization slug for the supported org-scoped PURL endpoint. If omitted, the SDK uses the deprecated legacy endpoint for backwards compatibility.
|
|
106
110
|
|
|
107
111
|
export.cdx_bom(org_slug, id, query_params)
|
|
108
112
|
""""""""""""""""""""""""""""""""""""""""""
|
|
@@ -28,9 +28,11 @@ Supported Functions
|
|
|
28
28
|
-------------------
|
|
29
29
|
|
|
30
30
|
|
|
31
|
-
purl.post(license, components)
|
|
32
|
-
""""""""""""""""""""""""""""""
|
|
33
|
-
Retrieve
|
|
31
|
+
purl.post(license, components, org_slug=None)
|
|
32
|
+
"""""""""""""""""""""""""""""""""""""""""""""
|
|
33
|
+
Retrieve package information for one or more PURLs. Pass ``org_slug`` to use the
|
|
34
|
+
current org-scoped endpoint. Omitting ``org_slug`` keeps the legacy deprecated
|
|
35
|
+
endpoint for backwards compatibility.
|
|
34
36
|
|
|
35
37
|
**Usage:**
|
|
36
38
|
|
|
@@ -38,6 +40,7 @@ Retrieve the package information for a purl post
|
|
|
38
40
|
|
|
39
41
|
from socketdev import socketdev
|
|
40
42
|
socket = socketdev(token="REPLACE_ME")
|
|
43
|
+
org_slug = "your-org-slug"
|
|
41
44
|
license = "true"
|
|
42
45
|
components = [
|
|
43
46
|
{
|
|
@@ -47,12 +50,13 @@ Retrieve the package information for a purl post
|
|
|
47
50
|
"purl": "pkg:pypi/socketsecurity"
|
|
48
51
|
}
|
|
49
52
|
]
|
|
50
|
-
print(socket.purl.post(license, components))
|
|
53
|
+
print(socket.purl.post(license, components, org_slug=org_slug))
|
|
51
54
|
|
|
52
55
|
**PARAMETERS:**
|
|
53
56
|
|
|
54
57
|
- **license (str)** - The license parameter if enabled will show alerts and license information. If disabled will only show the basic package metadata and scores. Default is true
|
|
55
58
|
- **components (array{dict})** - The components list of packages urls
|
|
59
|
+
- **org_slug (str, optional)** - Organization slug for the supported org-scoped PURL endpoint. If omitted, the SDK uses the deprecated legacy endpoint for backwards compatibility.
|
|
56
60
|
|
|
57
61
|
export.cdx_bom(org_slug, id, query_params)
|
|
58
62
|
""""""""""""""""""""""""""""""""""""""""""
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "socketdev"
|
|
7
|
-
version = "3.
|
|
7
|
+
version = "3.1.1"
|
|
8
8
|
requires-python = ">= 3.9"
|
|
9
9
|
dependencies = [
|
|
10
10
|
'requests',
|
|
@@ -50,7 +50,7 @@ test = [
|
|
|
50
50
|
]
|
|
51
51
|
|
|
52
52
|
[project.urls]
|
|
53
|
-
Homepage = "https://github.com/
|
|
53
|
+
Homepage = "https://github.com/SocketDev/socket-sdk-python"
|
|
54
54
|
|
|
55
55
|
[tool.ruff]
|
|
56
56
|
# Exclude a variety of commonly ignored directories.
|
|
@@ -463,7 +463,7 @@ class didYouMean:
|
|
|
463
463
|
|
|
464
464
|
def __init__(self):
|
|
465
465
|
self.description = "Package name is similar to other popular packages and may not be the package you want."
|
|
466
|
-
self.props = {"alternatePackage": "Alternate package", "
|
|
466
|
+
self.props = {"alternatePackage": "Alternate package", "detectedAt": "Detected at"}
|
|
467
467
|
self.suggestion = "Use care when consuming similarly named packages and ensure that you did not intend to consume a different package. Malicious packages often publish using similar names as existing popular packages."
|
|
468
468
|
self.title = "Possible typosquat attack"
|
|
469
469
|
self.emoji = "\ud83e\uddd0"
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import urllib.parse
|
|
3
|
+
import warnings
|
|
3
4
|
from socketdev.log import log
|
|
4
5
|
from ..core.dedupe import Dedupe
|
|
5
6
|
|
|
@@ -8,8 +9,21 @@ class Purl:
|
|
|
8
9
|
def __init__(self, api):
|
|
9
10
|
self.api = api
|
|
10
11
|
|
|
11
|
-
def post(
|
|
12
|
-
|
|
12
|
+
def post(
|
|
13
|
+
self,
|
|
14
|
+
license: str = "false",
|
|
15
|
+
components: list = None,
|
|
16
|
+
org_slug: str = None,
|
|
17
|
+
**kwargs,
|
|
18
|
+
) -> list:
|
|
19
|
+
if org_slug is None:
|
|
20
|
+
warnings.warn(
|
|
21
|
+
"Calling purl.post() without org_slug uses the deprecated POST /v0/purl endpoint. "
|
|
22
|
+
"Pass org_slug to migrate to POST /v0/orgs/{org_slug}/purl.",
|
|
23
|
+
DeprecationWarning,
|
|
24
|
+
stacklevel=2,
|
|
25
|
+
)
|
|
26
|
+
path = f"orgs/{org_slug}/purl?" if org_slug else "purl?"
|
|
13
27
|
if components is None:
|
|
14
28
|
components = []
|
|
15
29
|
purls = {"components": components}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "3.1.1"
|
|
@@ -181,13 +181,13 @@ class TestAllEndpointsMocked(unittest.TestCase):
|
|
|
181
181
|
def test_npm_issues_mocked(self):
|
|
182
182
|
"""Test npm issues endpoint."""
|
|
183
183
|
self._mock_success_response([{"type": "security", "severity": "high"}])
|
|
184
|
-
result = self.sdk.npm.issues("lodash", "4.
|
|
184
|
+
result = self.sdk.npm.issues("lodash", "4.18.1")
|
|
185
185
|
self.assertIsInstance(result, list)
|
|
186
186
|
|
|
187
187
|
def test_npm_score_mocked(self):
|
|
188
188
|
"""Test npm score endpoint."""
|
|
189
189
|
self._mock_success_response([{"category": "security", "value": 85}])
|
|
190
|
-
result = self.sdk.npm.score("lodash", "4.
|
|
190
|
+
result = self.sdk.npm.score("lodash", "4.18.1")
|
|
191
191
|
self.assertIsInstance(result, list)
|
|
192
192
|
|
|
193
193
|
# OpenAPI endpoints
|
|
@@ -206,9 +206,13 @@ class TestAllEndpointsMocked(unittest.TestCase):
|
|
|
206
206
|
|
|
207
207
|
# PURL endpoints
|
|
208
208
|
def test_purl_post_mocked(self):
|
|
209
|
-
"""Test purl post endpoint."""
|
|
210
|
-
|
|
211
|
-
|
|
209
|
+
"""Test org-scoped purl post endpoint."""
|
|
210
|
+
mock_response = Mock()
|
|
211
|
+
mock_response.status_code = 200
|
|
212
|
+
mock_response.headers = {'content-type': 'application/x-ndjson'}
|
|
213
|
+
mock_response.text = '{"inputPurl": "pkg:npm/lodash@4.18.1", "purl": "pkg:npm/lodash@4.18.1", "type": "npm", "name": "lodash", "version": "4.18.1", "valid": true, "alerts": []}'
|
|
214
|
+
self.mock_requests.request.return_value = mock_response
|
|
215
|
+
result = self.sdk.purl.post("false", [{"purl": "pkg:npm/lodash@4.18.1"}], org_slug="test-org")
|
|
212
216
|
self.assertIsInstance(result, list)
|
|
213
217
|
|
|
214
218
|
# Quota endpoints
|
|
@@ -372,7 +376,7 @@ class TestAllEndpointsIntegration(unittest.TestCase):
|
|
|
372
376
|
test_package = {
|
|
373
377
|
"name": "test-integration-package",
|
|
374
378
|
"version": "1.0.0",
|
|
375
|
-
"dependencies": {"lodash": "4.
|
|
379
|
+
"dependencies": {"lodash": "4.18.1"}
|
|
376
380
|
}
|
|
377
381
|
with open(cls.package_json_path, 'w') as f:
|
|
378
382
|
json.dump(test_package, f, indent=2)
|
|
@@ -414,20 +418,20 @@ class TestAllEndpointsIntegration(unittest.TestCase):
|
|
|
414
418
|
# NPM endpoints (should work for public packages)
|
|
415
419
|
def test_npm_issues_integration(self):
|
|
416
420
|
"""Test npm issues endpoint."""
|
|
417
|
-
result = self._try_endpoint(self.sdk.npm.issues, "lodash", "4.
|
|
421
|
+
result = self._try_endpoint(self.sdk.npm.issues, "lodash", "4.18.1")
|
|
418
422
|
if result:
|
|
419
423
|
self.assertIsInstance(result, list)
|
|
420
424
|
|
|
421
425
|
def test_npm_score_integration(self):
|
|
422
426
|
"""Test npm score endpoint."""
|
|
423
|
-
result = self._try_endpoint(self.sdk.npm.score, "lodash", "4.
|
|
427
|
+
result = self._try_endpoint(self.sdk.npm.score, "lodash", "4.18.1")
|
|
424
428
|
if result:
|
|
425
429
|
self.assertIsInstance(result, list)
|
|
426
430
|
|
|
427
431
|
# PURL endpoints
|
|
428
432
|
def test_purl_post_integration(self):
|
|
429
433
|
"""Test purl post endpoint."""
|
|
430
|
-
components = [{"purl": "pkg:npm/lodash@4.
|
|
434
|
+
components = [{"purl": "pkg:npm/lodash@4.18.1"}]
|
|
431
435
|
result = self._try_endpoint(self.sdk.purl.post, "false", components)
|
|
432
436
|
if result:
|
|
433
437
|
self.assertIsInstance(result, list)
|
|
@@ -515,7 +519,7 @@ class TestAllEndpointsIntegration(unittest.TestCase):
|
|
|
515
519
|
"""Test dependencies get endpoint."""
|
|
516
520
|
result = self._try_endpoint(
|
|
517
521
|
self.sdk.dependencies.get,
|
|
518
|
-
self.org_slug, "npm", "lodash", "4.
|
|
522
|
+
self.org_slug, "npm", "lodash", "4.18.1"
|
|
519
523
|
)
|
|
520
524
|
if result:
|
|
521
525
|
self.assertIsInstance(result, dict)
|
|
@@ -53,7 +53,7 @@ class TestSocketSDKIntegration(unittest.TestCase):
|
|
|
53
53
|
"name": "test-integration-project",
|
|
54
54
|
"version": "1.0.0",
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"lodash": "4.
|
|
56
|
+
"lodash": "4.18.1"
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -264,7 +264,7 @@ class TestSocketSDKIntegration(unittest.TestCase):
|
|
|
264
264
|
"""Test NPM-related endpoints."""
|
|
265
265
|
# Test getting package issues - this should work for most packages
|
|
266
266
|
try:
|
|
267
|
-
issues = self.sdk.npm.issues("lodash", "4.
|
|
267
|
+
issues = self.sdk.npm.issues("lodash", "4.18.1")
|
|
268
268
|
self.assertIsInstance(issues, dict)
|
|
269
269
|
except Exception as e:
|
|
270
270
|
print(f"NPM issues endpoint not available: {e}")
|
|
@@ -281,9 +281,13 @@ class TestSocketSDKIntegration(unittest.TestCase):
|
|
|
281
281
|
"""Test PURL (Package URL) functionality."""
|
|
282
282
|
try:
|
|
283
283
|
# Test with a common npm package
|
|
284
|
-
purl = "pkg:npm/lodash@4.
|
|
285
|
-
result = self.sdk.purl.post(
|
|
286
|
-
|
|
284
|
+
purl = "pkg:npm/lodash@4.18.1"
|
|
285
|
+
result = self.sdk.purl.post(
|
|
286
|
+
license="false",
|
|
287
|
+
components=[{"purl": purl}],
|
|
288
|
+
org_slug=self.org_slug,
|
|
289
|
+
)
|
|
290
|
+
self.assertIsInstance(result, list)
|
|
287
291
|
except Exception as e:
|
|
288
292
|
print(f"PURL endpoint not available: {e}")
|
|
289
293
|
|
|
@@ -44,11 +44,11 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
44
44
|
# Dependencies endpoints
|
|
45
45
|
def test_dependencies_post_unit(self):
|
|
46
46
|
"""Test dependencies post with proper file handling."""
|
|
47
|
-
expected_data = {"packages": [{"name": "lodash", "version": "4.
|
|
47
|
+
expected_data = {"packages": [{"name": "lodash", "version": "4.18.1"}]}
|
|
48
48
|
self._mock_response(expected_data)
|
|
49
49
|
|
|
50
50
|
with tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False) as f:
|
|
51
|
-
json.dump({"name": "test-package", "dependencies": {"lodash": "4.
|
|
51
|
+
json.dump({"name": "test-package", "dependencies": {"lodash": "4.18.1"}}, f)
|
|
52
52
|
f.flush()
|
|
53
53
|
|
|
54
54
|
try:
|
|
@@ -72,12 +72,12 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
72
72
|
expected_data = {"dependencies": [{"name": "sub-dependency", "version": "1.0.0"}]}
|
|
73
73
|
self._mock_response(expected_data)
|
|
74
74
|
|
|
75
|
-
result = self.sdk.dependencies.get("test-org", "npm", "lodash", "4.
|
|
75
|
+
result = self.sdk.dependencies.get("test-org", "npm", "lodash", "4.18.1")
|
|
76
76
|
|
|
77
77
|
self.assertEqual(result, expected_data)
|
|
78
78
|
call_args = self.mock_requests.request.call_args
|
|
79
79
|
self.assertEqual(call_args[0][0], "GET")
|
|
80
|
-
self.assertIn("/orgs/test-org/dependencies/npm/lodash/4.
|
|
80
|
+
self.assertIn("/orgs/test-org/dependencies/npm/lodash/4.18.1", call_args[0][1])
|
|
81
81
|
|
|
82
82
|
# DiffScans endpoints
|
|
83
83
|
def test_diffscans_list_unit(self):
|
|
@@ -305,24 +305,24 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
305
305
|
expected_data = [{"type": "security", "severity": "high", "title": "Test issue"}]
|
|
306
306
|
self._mock_response(expected_data)
|
|
307
307
|
|
|
308
|
-
result = self.sdk.npm.issues("lodash", "4.
|
|
308
|
+
result = self.sdk.npm.issues("lodash", "4.18.1")
|
|
309
309
|
|
|
310
310
|
self.assertEqual(result, expected_data)
|
|
311
311
|
call_args = self.mock_requests.request.call_args
|
|
312
312
|
self.assertEqual(call_args[0][0], "GET")
|
|
313
|
-
self.assertIn("/npm/lodash/4.
|
|
313
|
+
self.assertIn("/npm/lodash/4.18.1/issues", call_args[0][1])
|
|
314
314
|
|
|
315
315
|
def test_npm_score_unit(self):
|
|
316
316
|
"""Test npm score endpoint."""
|
|
317
317
|
expected_data = [{"category": "security", "value": 85}]
|
|
318
318
|
self._mock_response(expected_data)
|
|
319
319
|
|
|
320
|
-
result = self.sdk.npm.score("lodash", "4.
|
|
320
|
+
result = self.sdk.npm.score("lodash", "4.18.1")
|
|
321
321
|
|
|
322
322
|
self.assertEqual(result, expected_data)
|
|
323
323
|
call_args = self.mock_requests.request.call_args
|
|
324
324
|
self.assertEqual(call_args[0][0], "GET")
|
|
325
|
-
self.assertIn("/npm/lodash/4.
|
|
325
|
+
self.assertIn("/npm/lodash/4.18.1/score", call_args[0][1])
|
|
326
326
|
|
|
327
327
|
# OpenAPI endpoints
|
|
328
328
|
def test_openapi_get_unit(self):
|
|
@@ -352,14 +352,14 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
352
352
|
|
|
353
353
|
# PURL endpoints
|
|
354
354
|
def test_purl_post_unit(self):
|
|
355
|
-
"""Test PURL validation endpoint."""
|
|
355
|
+
"""Test org-scoped PURL validation endpoint."""
|
|
356
356
|
# Expected final result after deduplication - should match what the dedupe function produces
|
|
357
357
|
expected_data = [{
|
|
358
|
-
"inputPurl": "pkg:npm/lodash@4.
|
|
359
|
-
"purl": "pkg:npm/lodash@4.
|
|
358
|
+
"inputPurl": "pkg:npm/lodash@4.18.1",
|
|
359
|
+
"purl": "pkg:npm/lodash@4.18.1",
|
|
360
360
|
"type": "npm",
|
|
361
361
|
"name": "lodash",
|
|
362
|
-
"version": "4.
|
|
362
|
+
"version": "4.18.1",
|
|
363
363
|
"valid": True,
|
|
364
364
|
"alerts": [],
|
|
365
365
|
"releases": ["npm"]
|
|
@@ -367,7 +367,7 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
367
367
|
|
|
368
368
|
# Mock the NDJSON response that would come from the actual API
|
|
369
369
|
# This simulates what the API returns: newline-delimited JSON with SocketArtifact objects
|
|
370
|
-
mock_ndjson_response = '{"inputPurl": "pkg:npm/lodash@4.
|
|
370
|
+
mock_ndjson_response = '{"inputPurl": "pkg:npm/lodash@4.18.1", "purl": "pkg:npm/lodash@4.18.1", "type": "npm", "name": "lodash", "version": "4.18.1", "valid": true, "alerts": []}'
|
|
371
371
|
|
|
372
372
|
# Mock the response with NDJSON format
|
|
373
373
|
mock_response = Mock()
|
|
@@ -376,13 +376,30 @@ class TestAllEndpointsUnit(unittest.TestCase):
|
|
|
376
376
|
mock_response.text = mock_ndjson_response
|
|
377
377
|
self.mock_requests.request.return_value = mock_response
|
|
378
378
|
|
|
379
|
-
components = [{"purl": "pkg:npm/lodash@4.
|
|
380
|
-
result = self.sdk.purl.post("false", components)
|
|
379
|
+
components = [{"purl": "pkg:npm/lodash@4.18.1"}]
|
|
380
|
+
result = self.sdk.purl.post("false", components, org_slug="test-org")
|
|
381
381
|
|
|
382
382
|
self.assertEqual(result, expected_data)
|
|
383
|
+
call_args = self.mock_requests.request.call_args
|
|
384
|
+
self.assertEqual(call_args[0][0], "POST")
|
|
385
|
+
self.assertIn("/orgs/test-org/purl", call_args[0][1])
|
|
386
|
+
|
|
387
|
+
def test_purl_post_unit_legacy_path(self):
|
|
388
|
+
"""Test legacy PURL validation endpoint remains available for compatibility."""
|
|
389
|
+
mock_ndjson_response = '{"inputPurl": "pkg:npm/lodash@4.18.1", "purl": "pkg:npm/lodash@4.18.1", "type": "npm", "name": "lodash", "version": "4.18.1", "valid": true, "alerts": []}'
|
|
390
|
+
|
|
391
|
+
mock_response = Mock()
|
|
392
|
+
mock_response.status_code = 200
|
|
393
|
+
mock_response.headers = {'content-type': 'application/x-ndjson'}
|
|
394
|
+
mock_response.text = mock_ndjson_response
|
|
395
|
+
self.mock_requests.request.return_value = mock_response
|
|
396
|
+
|
|
397
|
+
self.sdk.purl.post("false", [{"purl": "pkg:npm/lodash@4.18.1"}])
|
|
398
|
+
|
|
383
399
|
call_args = self.mock_requests.request.call_args
|
|
384
400
|
self.assertEqual(call_args[0][0], "POST")
|
|
385
401
|
self.assertIn("/purl", call_args[0][1])
|
|
402
|
+
self.assertNotIn("/orgs/", call_args[0][1])
|
|
386
403
|
|
|
387
404
|
# Quota endpoints
|
|
388
405
|
def test_quota_get_unit(self):
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""Contract test for the didYouMean alert-type class's props.
|
|
2
|
+
|
|
3
|
+
The OpenAPI schema (`socket-sdk-js/openapi.json` around line 9298) declares
|
|
4
|
+
that the API emits `didYouMean` alerts with ``props: { alternatePackage,
|
|
5
|
+
detectedAt }``. The Python SDK previously declared four props
|
|
6
|
+
(``alternatePackage``, ``downloads``, ``downloadsRatio``, ``editDistance``);
|
|
7
|
+
the latter three are no longer in the API schema and were dead keys at
|
|
8
|
+
runtime — and ``detectedAt`` was missing.
|
|
9
|
+
|
|
10
|
+
Tracks CUS2-5. Sibling of CUS2-4.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import unittest
|
|
14
|
+
|
|
15
|
+
from socketdev.core.issues import didYouMean
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class TestDidYouMeanProps(unittest.TestCase):
|
|
19
|
+
def test_props_match_openapi_schema(self):
|
|
20
|
+
"""API emits props { alternatePackage, detectedAt } (openapi.json:9298)."""
|
|
21
|
+
issue = didYouMean()
|
|
22
|
+
self.assertEqual(set(issue.props.keys()), {"alternatePackage", "detectedAt"})
|
|
23
|
+
|
|
24
|
+
def test_props_label_strings_are_non_empty(self):
|
|
25
|
+
"""Every props key must have a non-empty human-readable label."""
|
|
26
|
+
issue = didYouMean()
|
|
27
|
+
for key, label in issue.props.items():
|
|
28
|
+
self.assertTrue(label, f"props[{key!r}] label should not be empty")
|
|
@@ -110,13 +110,13 @@ class TestSocketSDKUnit(unittest.TestCase):
|
|
|
110
110
|
type=SocketPURL_Type.NPM,
|
|
111
111
|
name="lodash",
|
|
112
112
|
namespace=None,
|
|
113
|
-
release="4.
|
|
113
|
+
release="4.18.1"
|
|
114
114
|
)
|
|
115
115
|
|
|
116
116
|
self.assertEqual(purl.type, SocketPURL_Type.NPM)
|
|
117
117
|
self.assertEqual(purl.name, "lodash")
|
|
118
118
|
self.assertIsNone(purl.namespace)
|
|
119
|
-
self.assertEqual(purl.release, "4.
|
|
119
|
+
self.assertEqual(purl.release, "4.18.1")
|
|
120
120
|
|
|
121
121
|
def test_integration_types(self):
|
|
122
122
|
"""Test that all integration types are available."""
|
|
@@ -223,7 +223,7 @@ class TestSocketSDKFileHandling(unittest.TestCase):
|
|
|
223
223
|
"name": "test-package",
|
|
224
224
|
"version": "1.0.0",
|
|
225
225
|
"dependencies": {
|
|
226
|
-
"lodash": "4.
|
|
226
|
+
"lodash": "4.18.1"
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
229
|
|
|
@@ -50,24 +50,24 @@ class TestWorkingEndpointsUnit(unittest.TestCase):
|
|
|
50
50
|
expected_data = [{"type": "security", "severity": "high"}]
|
|
51
51
|
self._mock_response(expected_data)
|
|
52
52
|
|
|
53
|
-
result = self.sdk.npm.issues("lodash", "4.
|
|
53
|
+
result = self.sdk.npm.issues("lodash", "4.18.1")
|
|
54
54
|
|
|
55
55
|
self.assertEqual(result, expected_data)
|
|
56
56
|
call_args = self.mock_requests.request.call_args
|
|
57
57
|
self.assertEqual(call_args[0][0], "GET")
|
|
58
|
-
self.assertIn("/npm/lodash/4.
|
|
58
|
+
self.assertIn("/npm/lodash/4.18.1/issues", call_args[0][1])
|
|
59
59
|
|
|
60
60
|
def test_npm_score_unit(self):
|
|
61
61
|
"""Test NPM score endpoint - WORKING."""
|
|
62
62
|
expected_data = [{"category": "security", "value": 85}]
|
|
63
63
|
self._mock_response(expected_data)
|
|
64
64
|
|
|
65
|
-
result = self.sdk.npm.score("lodash", "4.
|
|
65
|
+
result = self.sdk.npm.score("lodash", "4.18.1")
|
|
66
66
|
|
|
67
67
|
self.assertEqual(result, expected_data)
|
|
68
68
|
call_args = self.mock_requests.request.call_args
|
|
69
69
|
self.assertEqual(call_args[0][0], "GET")
|
|
70
|
-
self.assertIn("/npm/lodash/4.
|
|
70
|
+
self.assertIn("/npm/lodash/4.18.1/score", call_args[0][1])
|
|
71
71
|
|
|
72
72
|
def test_openapi_get_unit(self):
|
|
73
73
|
"""Test OpenAPI specification retrieval - WORKING."""
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
import subprocess
|
|
3
|
-
import pathlib
|
|
4
|
-
import re
|
|
5
|
-
import sys
|
|
6
|
-
import urllib.request
|
|
7
|
-
import json
|
|
8
|
-
|
|
9
|
-
VERSION_FILE = pathlib.Path("socketdev/version.py")
|
|
10
|
-
PYPROJECT_FILE = pathlib.Path("pyproject.toml")
|
|
11
|
-
|
|
12
|
-
VERSION_PATTERN = re.compile(r"__version__\s*=\s*['\"]([^'\"]+)['\"]")
|
|
13
|
-
PYPROJECT_PATTERN = re.compile(r'^version\s*=\s*".*"$', re.MULTILINE)
|
|
14
|
-
PYPI_API = "https://test.pypi.org/pypi/socketdev/json"
|
|
15
|
-
|
|
16
|
-
def read_version_from_version_file(path: pathlib.Path) -> str:
|
|
17
|
-
content = path.read_text()
|
|
18
|
-
match = VERSION_PATTERN.search(content)
|
|
19
|
-
if not match:
|
|
20
|
-
print(f"❌ Could not find __version__ in {path}")
|
|
21
|
-
sys.exit(1)
|
|
22
|
-
return match.group(1)
|
|
23
|
-
|
|
24
|
-
def read_version_from_git(path: str) -> str:
|
|
25
|
-
try:
|
|
26
|
-
output = subprocess.check_output(["git", "show", f"HEAD:{path}"], text=True)
|
|
27
|
-
match = VERSION_PATTERN.search(output)
|
|
28
|
-
if not match:
|
|
29
|
-
return None
|
|
30
|
-
return match.group(1)
|
|
31
|
-
except subprocess.CalledProcessError:
|
|
32
|
-
return None
|
|
33
|
-
|
|
34
|
-
def bump_patch_version(version: str) -> str:
|
|
35
|
-
if ".dev" in version:
|
|
36
|
-
version = version.split(".dev")[0]
|
|
37
|
-
parts = version.split(".")
|
|
38
|
-
parts[-1] = str(int(parts[-1]) + 1)
|
|
39
|
-
return ".".join(parts)
|
|
40
|
-
|
|
41
|
-
def fetch_existing_versions() -> set:
|
|
42
|
-
try:
|
|
43
|
-
with urllib.request.urlopen(PYPI_API) as response:
|
|
44
|
-
data = json.load(response)
|
|
45
|
-
return set(data.get("releases", {}).keys())
|
|
46
|
-
except Exception as e:
|
|
47
|
-
print(f"⚠️ Warning: Failed to fetch existing versions from Test PyPI: {e}")
|
|
48
|
-
return set()
|
|
49
|
-
|
|
50
|
-
def find_next_available_dev_version(base_version: str) -> str:
|
|
51
|
-
existing_versions = fetch_existing_versions()
|
|
52
|
-
for i in range(1, 100):
|
|
53
|
-
candidate = f"{base_version}.dev{i}"
|
|
54
|
-
if candidate not in existing_versions:
|
|
55
|
-
return candidate
|
|
56
|
-
print("❌ Could not find available .devN slot after 100 attempts.")
|
|
57
|
-
sys.exit(1)
|
|
58
|
-
|
|
59
|
-
def inject_version(version: str):
|
|
60
|
-
print(f"🔁 Updating version to: {version}")
|
|
61
|
-
|
|
62
|
-
# Update version.py
|
|
63
|
-
VERSION_FILE.write_text(f'__version__ = "{version}"\n')
|
|
64
|
-
|
|
65
|
-
# Update pyproject.toml if it has a version field (it shouldn't with hatch, but just in case)
|
|
66
|
-
pyproject = PYPROJECT_FILE.read_text()
|
|
67
|
-
if PYPROJECT_PATTERN.search(pyproject):
|
|
68
|
-
new_pyproject = PYPROJECT_PATTERN.sub(f'version = "{version}"', pyproject)
|
|
69
|
-
PYPROJECT_FILE.write_text(new_pyproject)
|
|
70
|
-
|
|
71
|
-
def main():
|
|
72
|
-
dev_mode = "--dev" in sys.argv
|
|
73
|
-
current_version = read_version_from_version_file(VERSION_FILE)
|
|
74
|
-
previous_version = read_version_from_git("socketdev/version.py")
|
|
75
|
-
|
|
76
|
-
print(f"Current: {current_version}, Previous: {previous_version}")
|
|
77
|
-
|
|
78
|
-
if current_version == previous_version:
|
|
79
|
-
if dev_mode:
|
|
80
|
-
base_version = current_version.split(".dev")[0] if ".dev" in current_version else current_version
|
|
81
|
-
new_version = find_next_available_dev_version(base_version)
|
|
82
|
-
inject_version(new_version)
|
|
83
|
-
print("⚠️ Version was unchanged — auto-bumped. Please git add + commit again.")
|
|
84
|
-
sys.exit(0)
|
|
85
|
-
else:
|
|
86
|
-
new_version = bump_patch_version(current_version)
|
|
87
|
-
inject_version(new_version)
|
|
88
|
-
print("⚠️ Version was unchanged — auto-bumped. Please git add + commit again.")
|
|
89
|
-
sys.exit(1)
|
|
90
|
-
else:
|
|
91
|
-
print("✅ Version already bumped — proceeding.")
|
|
92
|
-
sys.exit(0)
|
|
93
|
-
|
|
94
|
-
if __name__ == "__main__":
|
|
95
|
-
main()
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "3.0.33"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|