Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## 3.6.4

### Removed: SDK calls that requested paths the API does not route

These calls failed with a 404 on every request, whatever the token.

- `apitokens.update()` no longer takes `token_id`. It always calls
`POST orgs/{org_slug}/api-tokens/update`, which reads the token to update from
the request body. Pass exactly one of `uuid`, `id`, `token` or `hash` in the
keyword arguments.
- `dependencies.get()` no longer takes `org_slug`, `ecosystem`, `package` and
`version`. Its signature is `get(limit=50, offset=0)`, as the README documents,
and it always searches. Positional arguments now set `limit` and `offset`;
they used to be bound to the removed parameters and ignored.
- The `repositories` module and `socketdev(...).repositories` are removed. Its
only method, `list()`, requested `GET repos`. Use `repos.get(org_slug)` to list
repositories.

## 3.6.3

### Fixed: `settings.integration_events()` requested the wrong path
Expand Down
37 changes: 6 additions & 31 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -681,18 +681,6 @@ Create a new project health report with the provided files

- **files (list)** - List of file paths of manifest files

Deprecated: repositories.get()
""""""""""""""""""""""""""""""
Get a list of information about the tracked repositories

**Usage:**

.. code-block:: python

from socketdev import socketdev
socket = socketdev(token="REPLACE_ME")
print(socket.repositories.get())

Deprecated: sbom.view(report_id)
""""""""""""""""""""""""""""""""
Retrieve the information for a SBOM Report
Expand Down Expand Up @@ -1107,16 +1095,18 @@ Update an existing API token.
from socketdev import socketdev
socket = socketdev(token="REPLACE_ME")
update_params = {
"token_id": "token_123",
"uuid": "token_uuid",
"name": "Updated Token Name",
"permissions": ["read"]
"scopes": ["full-scans:create"]
}
print(socket.apitokens.update("org_slug", **update_params))

**PARAMETERS:**

- **org_slug (str)** – The organization name
- **kwargs** – Token update parameters
- **kwargs** – Token update parameters, sent as the request body. Identify the token
with exactly one of ``uuid``, ``id``, ``token`` or ``hash``. See the
`API reference <https://docs.socket.dev/reference>`_ for the other fields.

auditlog.get(org_slug, \*\*kwargs)
""""""""""""""""""""""""""""""""""""
Expand Down Expand Up @@ -1582,13 +1572,7 @@ A few rows need a note:
- ``fullscans.finalize_tier1()``, ``uploadmanifests.upload_manifest_files()`` and
``sbom.view()`` call endpoints the API reference does not list. Their scopes are
given in the table.
- Three calls request a path the API has no route for, so they fail with a 404
(``APIResourceNotFound``) whatever the token: ``apitokens.update()`` when
``token_id`` is passed, ``dependencies.get()`` when ``org_slug``, ``ecosystem``,
``package`` and ``version`` are all passed, and ``repositories.list()``. Call
``apitokens.update()`` without ``token_id``, and use ``repos.get()`` to list
repositories.
- ``dependencies.get()`` otherwise calls ``POST dependencies/search``. That endpoint
- ``dependencies.get()`` calls ``POST dependencies/search``. That endpoint
accepts any valid token, but it returns only results from repositories the token can
read under ``dependencies:list``. Depending on how the organization restricts
repository access, a token without that scope gets an empty result instead of a 403,
Expand Down Expand Up @@ -1629,9 +1613,6 @@ A few rows need a note:
* - ``apitokens.update()``
- ``POST orgs/{org_slug}/api-tokens/update``
- ``api-tokens:create``
* - ``apitokens.update(token_id=...)``
- ``PUT orgs/{org_slug}/api-tokens/{token_id}``
- no such route; the call fails
* - ``apitokens.rotate()``
- ``POST orgs/{org_slug}/api-tokens/rotate``
- ``api-tokens:rotate``
Expand All @@ -1650,9 +1631,6 @@ A few rows need a note:
* - ``dependencies.get()``
- ``POST dependencies/search``
- none; ``dependencies:list`` to get results (see the note above)
* - ``dependencies.get(org_slug, ecosystem, package, version)``
- ``GET orgs/{org_slug}/dependencies/{ecosystem}/{package}/{version}``
- no such route; the call fails
* - ``diffscans.list()``
- ``GET orgs/{org_slug}/diff-scans``
- ``diff-scans:list``
Expand Down Expand Up @@ -1812,9 +1790,6 @@ A few rows need a note:
* - ``repos.delete()``
- ``DELETE orgs/{org_slug}/repos/{repo_slug}``
- ``repo:delete``
* - ``repositories.list()``
- ``GET repos``
- no such route; the call fails
* - ``sbom.view()``
- ``GET sbom/view/{id}``
- ``report:read`` (not in the API reference)
Expand Down
2 changes: 0 additions & 2 deletions socketdev/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from socketdev.quota import Quota
from socketdev.report import Report
from socketdev.repos import Repos
from socketdev.repositories import Repositories
from socketdev.sbom import Sbom
from socketdev.settings import Settings
from socketdev.triage import Triage
Expand Down Expand Up @@ -83,7 +82,6 @@ def __init__(self, token: Optional[str] = None, timeout: int = 1200, allow_unver
self.quota = Quota(self.api)
self.report = Report(self.api)
self.repos = Repos(self.api)
self.repositories = Repositories(self.api)
self.sbom = Sbom(self.api)
self.settings = Settings(self.api)
self.triage = Triage(self.api)
Expand Down
25 changes: 8 additions & 17 deletions socketdev/apitokens/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,22 @@ def list(self, org_slug: str, **kwargs) -> dict:
log.error(response.text)
return {}

def update(self, org_slug: str, token_id: str = None, **kwargs) -> dict:
def update(self, org_slug: str, **kwargs) -> dict:
"""
Update an API token.

Args:
org_slug: Organization slug
token_id: Token ID to update (optional, can be in kwargs)
**kwargs: Token update parameters

**kwargs: Token update parameters. The API reads the token to update
from the request body, so include exactly one of ``uuid``, ``id``,
``token`` or ``hash``.

Returns:
dict: API response containing the updated token details
"""
# Extract token_id from kwargs if not provided as parameter
if token_id is None and 'token_id' in kwargs:
token_id = kwargs.pop('token_id')

if token_id:
path = f"orgs/{org_slug}/api-tokens/{token_id}"
method = "PUT"
else:
path = f"orgs/{org_slug}/api-tokens/update"
method = "POST"

path = f"orgs/{org_slug}/api-tokens/update"
payload = json.dumps(kwargs) if kwargs else "{}"
response = self.api.do_request(path=path, method=method, payload=payload)
response = self.api.do_request(path=path, method="POST", payload=payload)
if response.status_code == 200:
return response.json()
log.error(f"Error updating API token: {response.status_code}")
Expand Down
25 changes: 11 additions & 14 deletions socketdev/dependencies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,17 @@ def post(self, files: list, params: dict, use_lazy_loading: bool = True, workspa
log.error(response.text)
return result

def get(self, org_slug: str = None, ecosystem: str = None, package: str = None, version: str = None, **kwargs) -> dict:
# If all specific parameters are provided, use the specific dependency endpoint
if org_slug and ecosystem and package and version:
path = f"orgs/{org_slug}/dependencies/{ecosystem}/{package}/{version}"
response = self.api.do_request(path=path, method="GET")
else:
# Otherwise use the search endpoint
limit = kwargs.get('limit', 50)
offset = kwargs.get('offset', 0)
path = "dependencies/search"
payload = {"limit": limit, "offset": offset}
payload_str = json.dumps(payload)
response = self.api.do_request(path=path, method="POST", payload=payload_str)

def get(self, limit: int = 50, offset: int = 0) -> dict:
"""Search the dependencies of the token's organization.

Args:
limit: Maximum number of dependencies to return
offset: Number of dependencies to skip
"""
path = "dependencies/search"
payload = json.dumps({"limit": limit, "offset": offset})
response = self.api.do_request(path=path, method="POST", payload=payload)

if response.status_code == 200:
result = response.json()
else:
Expand Down
31 changes: 0 additions & 31 deletions socketdev/repositories/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion socketdev/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.6.3"
__version__ = "3.6.4"
9 changes: 3 additions & 6 deletions tests/integration/test_all_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_dependencies_post_mocked(self):
def test_dependencies_get_mocked(self):
"""Test dependencies get endpoint."""
self._mock_success_response({"dependencies": []})
result = self.sdk.dependencies.get("test-org", "npm", "test-package", "1.0.0")
result = self.sdk.dependencies.get(limit=10, offset=0)
self.assertIn("dependencies", result)

# DiffScans endpoints
Expand Down Expand Up @@ -307,7 +307,7 @@ def test_apitokens_create_mocked(self):
def test_apitokens_update_mocked(self):
"""Test apitokens update endpoint."""
self._mock_success_response({"id": "token-123", "name": "updated-token"})
result = self.sdk.apitokens.update("test-org", token_id="token-123", name="updated-token")
result = self.sdk.apitokens.update("test-org", uuid="token-123", name="updated-token")
self.assertEqual(result["name"], "updated-token")

def test_apitokens_list_mocked(self):
Expand Down Expand Up @@ -517,10 +517,7 @@ def test_auditlog_get_integration(self):
# Dependencies endpoint
def test_dependencies_get_integration(self):
"""Test dependencies get endpoint."""
result = self._try_endpoint(
self.sdk.dependencies.get,
self.org_slug, "npm", "lodash", "4.18.1"
)
result = self._try_endpoint(self.sdk.dependencies.get)
if result:
self.assertIsInstance(result, dict)

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_comprehensive_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def test_new_endpoints_basic(self):
def test_dependencies_endpoint(self):
"""Test dependencies endpoint."""
try:
deps = self.sdk.dependencies.get(self.org_slug)
deps = self.sdk.dependencies.get()
self.assertIsInstance(deps, dict)
except Exception as e:
print(f"Dependencies endpoint not available: {e}")
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/test_new_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,15 @@ def test_apitokens_update_mocked(self):

result = self.sdk.apitokens.update(
org_slug="test-org",
token_id="token123",
uuid="token123",
name="updated-token"
)

self.assertEqual(result["name"], "updated-token")
self.mock_api.do_request.assert_called_once_with(
path="orgs/test-org/api-tokens/update",
method="POST",
payload='{"token_id": "token123", "name": "updated-token"}'
payload='{"uuid": "token123", "name": "updated-token"}'
)

def test_analytics_deprecation_warning(self):
Expand Down Expand Up @@ -282,7 +282,7 @@ def test_all_endpoints_have_api_reference(self):
endpoints = [
'dependencies', 'export', 'fullscans', 'historical',
'npm', 'openapi', 'org', 'purl', 'quota', 'report', 'repos',
'repositories', 'sbom', 'settings', 'triage', 'labels',
'sbom', 'settings', 'triage', 'labels',
'licensemetadata', 'diffscans', 'threatfeed', 'apitokens',
'auditlog', 'analytics', 'alerttypes'
]
Expand All @@ -302,7 +302,7 @@ def test_sdk_components_initialization(self):
components = [
sdk.dependencies, sdk.export, sdk.fullscans, sdk.historical,
sdk.npm, sdk.openapi, sdk.org, sdk.purl, sdk.quota,
sdk.report, sdk.repos, sdk.repositories, sdk.sbom,
sdk.report, sdk.repos, sdk.sbom,
sdk.settings, sdk.triage, sdk.utils, sdk.labels,
sdk.licensemetadata, sdk.diffscans, sdk.threatfeed,
sdk.apitokens, sdk.auditlog, sdk.analytics, sdk.alerttypes
Expand Down
28 changes: 18 additions & 10 deletions tests/unit/test_all_endpoints_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,23 @@ def test_dependencies_post_unit(self):
os.unlink(f.name)

def test_dependencies_get_unit(self):
"""Test dependencies get with all parameters."""
"""Test dependencies get sends limit and offset to the search endpoint."""
expected_data = {"dependencies": [{"name": "sub-dependency", "version": "1.0.0"}]}
self._mock_response(expected_data)
result = self.sdk.dependencies.get("test-org", "npm", "lodash", "4.18.1")

result = self.sdk.dependencies.get(10, 20)

self.assertEqual(result, expected_data)
call_args = self.mock_requests.request.call_args
self.assertEqual(call_args[0][0], "GET")
self.assertIn("/orgs/test-org/dependencies/npm/lodash/4.18.1", call_args[0][1])
self.assertEqual(call_args[0][0], "POST")
self.assertTrue(call_args[0][1].endswith("/dependencies/search"))
self.assertEqual(json.loads(call_args[1]["data"]), {"limit": 10, "offset": 20})

def test_dependencies_get_rejects_package_arguments(self):
"""The API has no per-package dependency route, so get() takes no package."""
with self.assertRaises(TypeError):
self.sdk.dependencies.get(org_slug="test-org", ecosystem="npm", package="lodash", version="4.18.1")
self.mock_requests.request.assert_not_called()

# DiffScans endpoints
def test_diffscans_list_unit(self):
Expand Down Expand Up @@ -843,12 +850,13 @@ def test_apitokens_update_unit(self):
expected_data = {"id": "token-123", "name": "updated-token"}
self._mock_response(expected_data)

result = self.sdk.apitokens.update("test-org", token_id="token-123", name="updated-token")
result = self.sdk.apitokens.update("test-org", uuid="token-123", name="updated-token")

self.assertEqual(result, expected_data)
call_args = self.mock_requests.request.call_args
self.assertEqual(call_args[0][0], "PUT")
self.assertIn("/orgs/test-org/api-tokens/token-123", call_args[0][1])
self.assertEqual(call_args[0][0], "POST")
self.assertTrue(call_args[0][1].endswith("/orgs/test-org/api-tokens/update"))
self.assertEqual(json.loads(call_args[1]["data"]), {"uuid": "token-123", "name": "updated-token"})

def test_apitokens_list_unit(self):
"""Test API token listing."""
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_socket_sdk_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_sdk_initialization(self):
expected_components = [
'api', 'dependencies', 'export', 'fullscans', 'historical',
'npm', 'openapi', 'org', 'purl', 'quota', 'report', 'repos',
'repositories', 'sbom', 'settings', 'triage', 'utils', 'labels',
'sbom', 'settings', 'triage', 'utils', 'labels',
'licensemetadata', 'diffscans', 'threatfeed', 'apitokens',
'auditlog', 'analytics', 'alerttypes'
]
Expand Down
Loading