Skip to content

Commit 8ff3a17

Browse files
committed
Add org slug param with org-scoped routing, deprecation warning
Signed-off-by: lelia <2418071+lelia@users.noreply.github.com>
1 parent ed38c65 commit 8ff3a17

3 files changed

Lines changed: 38 additions & 17 deletions

File tree

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ dist
1616
*.egg-info
1717
*.cpython-312.pyc
1818
example-socket-export.py
19-
__pycache__/
19+
__pycache__/
20+
.coverage
21+
.coverage.*
22+
htmlcov/

README.rst

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,35 @@ Supported Functions
2828
-------------------
2929

3030

31-
purl.post(license, components)
32-
""""""""""""""""""""""""""""""
33-
Retrieve the package information for a purl post
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.
3436

3537
**Usage:**
3638

3739
.. code-block:: python
3840
39-
from socketdev import socketdev
40-
socket = socketdev(token="REPLACE_ME")
41-
license = "true"
42-
components = [
43-
{
41+
from socketdev import socketdev
42+
socket = socketdev(token="REPLACE_ME")
43+
org_slug = "your-org-slug"
44+
license = "true"
45+
components = [
46+
{
4447
"purl": "pkg:pypi/pyonepassword@5.0.0"
4548
},
4649
{
47-
"purl": "pkg:pypi/socketsecurity"
48-
}
49-
]
50-
print(socket.purl.post(license, components))
50+
"purl": "pkg:pypi/socketsecurity"
51+
}
52+
]
53+
print(socket.purl.post(license, components, org_slug=org_slug))
5154
5255
**PARAMETERS:**
5356

54-
- **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-
- **components (array{dict})** - The components list of packages urls
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
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.
5660

5761
export.cdx_bom(org_slug, id, query_params)
5862
""""""""""""""""""""""""""""""""""""""""""

socketdev/purl/__init__.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import urllib.parse
3+
import warnings
34
from socketdev.log import log
45
from ..core.dedupe import Dedupe
56

@@ -8,8 +9,21 @@ class Purl:
89
def __init__(self, api):
910
self.api = api
1011

11-
def post(self, license: str = "false", components: list = None, **kwargs) -> list:
12-
path = "purl?"
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?"
1327
if components is None:
1428
components = []
1529
purls = {"components": components}

0 commit comments

Comments
 (0)