Skip to content

Commit ec8940a

Browse files
authored
Add workspace param support (#68)
* Add workspace to FullScanParams for API support Signed-off-by: lelia <lelia@socket.dev> * Add test to verify that workspace is included in query string on FullScanParams Signed-off-by: lelia <lelia@socket.dev> * Update README to document workspace parameter Signed-off-by: lelia <lelia@socket.dev> * Increment version number Signed-off-by: lelia <lelia@socket.dev> * Update tests to use generic data Signed-off-by: lelia <lelia@socket.dev> * Bump version again Signed-off-by: lelia <lelia@socket.dev> * Update pyproject classifiers Signed-off-by: lelia <lelia@socket.dev> * Pin python and virutalenv versions for workflows Signed-off-by: lelia <lelia@socket.dev> --------- Signed-off-by: lelia <lelia@socket.dev>
1 parent 7e0ee56 commit ec8940a

File tree

7 files changed

+43
-5
lines changed

7 files changed

+43
-5
lines changed

.github/workflows/pr-preview.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ jobs:
1616
fetch-depth: 0
1717
- uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3
1818
with:
19-
python-version: '3.x'
19+
python-version: '3.13'
2020

2121
# Install all dependencies from pyproject.toml
2222
- name: Install dependencies
2323
run: |
2424
python -m pip install --upgrade pip
25+
pip install "virtualenv<20.36"
2526
pip install hatchling==1.27.0
2627
pip install hatch==1.14.0
2728

.github/workflows/release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ jobs:
1515
fetch-depth: 0
1616
- uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3
1717
with:
18-
python-version: '3.x'
18+
python-version: '3.13'
1919

2020
# Install all dependencies from pyproject.toml
2121
- name: Install dependencies
2222
run: |
2323
python -m pip install --upgrade pip
24+
pip install "virtualenv<20.36"
2425
pip install hatchling==1.27.0
2526
pip install hatch==1.14.0
2627

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ Create a full scan from a set of package manifest files. Returns a full scan inc
184184
params = FullScanParams(
185185
org_slug="org_name",
186186
repo="TestRepo",
187+
workspace="my-workspace",
187188
branch="main",
188189
commit_message="Test Commit Message",
189190
commit_hash="abc123def456",
@@ -223,6 +224,8 @@ Create a full scan from a set of package manifest files. Returns a full scan inc
223224
+------------------------+------------+-------------------------------------------------------------------------------+
224225
| tmp | False | Boolean temporary flag |
225226
+------------------------+------------+-------------------------------------------------------------------------------+
227+
| workspace | False | The workspace of the repository to associate the full-scan with. |
228+
+------------------------+------------+-------------------------------------------------------------------------------+
226229
| integration_type | False | IntegrationType enum value (e.g., "api", "github") |
227230
+------------------------+------------+-------------------------------------------------------------------------------+
228231
| integration_org_slug | False | Organization slug for integration |

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "socketdev"
7-
version = "3.0.29"
7+
version = "3.0.31"
88
requires-python = ">= 3.9"
99
dependencies = [
1010
'requests',
@@ -23,7 +23,6 @@ maintainers = [
2323
classifiers = [
2424
"Development Status :: 5 - Production/Stable",
2525
"Intended Audience :: Developers",
26-
"Programming Language :: Python :: 3.9",
2726
"Programming Language :: Python :: 3.10",
2827
"Programming Language :: Python :: 3.11",
2928
"Programming Language :: Python :: 3.12",

socketdev/fullscans/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class FullScanParams:
106106
set_as_pending_head: Optional[bool] = None
107107
tmp: Optional[bool] = None
108108
scan_type: Optional[ScanType] = None
109+
workspace: Optional[str] = None
109110

110111
def __getitem__(self, key):
111112
return getattr(self, key)
@@ -131,6 +132,7 @@ def from_dict(cls, data: dict) -> "FullScanParams":
131132
set_as_pending_head=data.get("set_as_pending_head"),
132133
tmp=data.get("tmp"),
133134
scan_type=ScanType(scan_type) if scan_type is not None else None,
135+
workspace=data.get("workspace"),
134136
)
135137

136138

socketdev/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.0.29"
1+
__version__ = "3.0.31"

tests/unit/test_working_endpoints_unit.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,38 @@ def test_fullscans_post_unit(self):
203203
finally:
204204
os.unlink(f.name)
205205

206+
def test_fullscans_post_with_workspace_unit(self):
207+
"""Test that workspace is included in the query string when set on FullScanParams."""
208+
expected_data = {"id": "new-scan"}
209+
self._mock_response(expected_data, 201)
210+
211+
params = FullScanParams(
212+
repo="test-repo",
213+
org_slug="test-org",
214+
branch="main",
215+
workspace="test-workspace",
216+
)
217+
218+
with tempfile.NamedTemporaryFile(mode='w', suffix='.json', delete=False) as f:
219+
json.dump({"name": "test", "version": "1.0.0"}, f)
220+
f.flush()
221+
222+
try:
223+
with open(f.name, "rb") as file_obj:
224+
files = [("file", ("package.json", file_obj))]
225+
result = self.sdk.fullscans.post(files, params)
226+
227+
self.assertEqual(result, expected_data)
228+
call_args = self.mock_requests.request.call_args
229+
self.assertEqual(call_args[0][0], "POST")
230+
# Confirm workspace landed in the request URL query string
231+
request_url = call_args[0][1]
232+
self.assertIn("workspace=test-workspace", request_url)
233+
self.assertIn("repo=test-repo", request_url)
234+
235+
finally:
236+
os.unlink(f.name)
237+
206238
def test_triage_list_alert_triage_unit(self):
207239
"""Test triage list alerts - WORKING."""
208240
expected_data = {"alerts": []}

0 commit comments

Comments
 (0)