Skip to content

Commit 909e411

Browse files
obarreraOrlando Barrera II
andauthored
Added the Purl API endpoint (#4)
* Added the Purl API endpoint * Updated Readme * Updated Purl, Sbom --------- Co-authored-by: Orlando Barrera II <[email protected]>
1 parent 75994c2 commit 909e411

File tree

4 files changed

+82
-2
lines changed

4 files changed

+82
-2
lines changed

README.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,45 @@ Retrieve the Socket Organization Settings
215215
from socketdev import SocketDev
216216
socket = SocketDev("REPLACE_ME")
217217
print(socket.settings.get())
218+
219+
sbom.view(report_id)
220+
""""""""""""""""""""""
221+
Retrieve the information for a SBOM Report
222+
223+
**Usage:**
224+
225+
.. code-block::
226+
227+
from socketdev import SocketDev
228+
socket = SocketDev("REPLACE_ME")
229+
print(socket.sbom.view("report_id"))
230+
231+
**PARAMETERS:**
232+
233+
- **report_id (str)** - The report ID of the report to view
234+
235+
purl.post(license, components)
236+
""""""""""""""""""""""
237+
Retrieve the package information for a purl post
238+
239+
**Usage:**
240+
241+
.. code-block::
242+
243+
from socketdev import SocketDev
244+
socket = SocketDev("REPLACE_ME")
245+
license = "true"
246+
components = [
247+
{
248+
"purl": "pkg:pypi/[email protected]"
249+
},
250+
{
251+
"purl": "pkg:pypi/socketsecurity"
252+
}
253+
]
254+
print(socket.purl.post(license, components))
255+
256+
**PARAMETERS:**
257+
258+
- **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
259+
- **components (array{dict})** - The components list of packages urls

socketdev/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from socketdev.quota import Quota
1010
from socketdev.report import Report
1111
from socketdev.sbom import Sbom
12+
from socketdev.purl import Purl
1213
from socketdev.repositories import Repositories
1314
from socketdev.settings import Settings
1415
from socketdev.socket_classes import Dependency, Org, Response
@@ -89,5 +90,6 @@ def __init__(self, token: str):
8990
self.quota = Quota()
9091
self.report = Report()
9192
self.sbom = Sbom()
93+
self.purl = Purl()
9294
self.repositories = Repositories()
9395
self.settings = Settings()

socketdev/purl/__init__.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import socketdev
2+
from urllib.parse import urlencode
3+
import json
4+
5+
class Purl:
6+
@staticmethod
7+
def post(license: str="true", components: list=[]) -> dict:
8+
path = "purl?" + "license="+license
9+
components = {"components":components}
10+
components = json.dumps(components)
11+
12+
response = socketdev.do_request(
13+
path=path,
14+
payload=components,
15+
method="POST"
16+
)
17+
if response.status_code == 200:
18+
purl = []
19+
purl_dict = {}
20+
result = response.text
21+
result.strip('"')
22+
result.strip()
23+
for line in result.split("\n"):
24+
if line != '"' and line != "" and line is not None:
25+
item = json.loads(line)
26+
purl.append(item)
27+
for val in purl:
28+
purl_dict[val['id']] = val
29+
else:
30+
purl_dict = {}
31+
print(f"Error posting {components} to the Purl API")
32+
print(response.text)
33+
34+
return purl_dict
35+
36+

socketdev/sbom/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class Sbom:
55
@staticmethod
6-
def get_sbom_data(report_id: str) -> list:
6+
def view(report_id: str) -> list:
77
path = f"sbom/view/{report_id}"
88
response = socketdev.do_request(path=path)
99
if response.status_code == 200:
@@ -16,7 +16,7 @@ def get_sbom_data(report_id: str) -> list:
1616
if line != '"' and line != "" and line is not None:
1717
item = json.loads(line)
1818
sbom.append(item)
19-
for key, val in enumerate(sbom):
19+
for val in sbom:
2020
sbom_dict[val['id']] = val
2121
else:
2222
sbom_dict = {}

0 commit comments

Comments
 (0)