Skip to content

Commit 0614f83

Browse files
obarreraOrlando Barrera IIOrlando Barrera II
authored
Orlando/add new endpoints (#2)
* added the sbom report output in a dict format * added sbom function --------- Co-authored-by: Orlando Barrera II <[email protected]> Co-authored-by: Orlando Barrera II <[email protected]>
1 parent d79033b commit 0614f83

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ venv
55
.DS_Store
66
*.zip
77
*.pyc
8+
test.py

socketdev/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import logging
22
import requests
33
import base64
4+
45
from socketdev.dependencies import Dependencies
56
from socketdev.npm import NPM
67
from socketdev.openapi import OpenAPI
78
from socketdev.org import Orgs
89
from socketdev.quota import Quota
910
from socketdev.report import Report
11+
from socketdev.sbom import Sbom
1012
from socketdev.repositories import Repositories
1113
from socketdev.settings import Settings
1214
from socketdev.socket_classes import Dependency, Org, Response
@@ -86,5 +88,6 @@ def __init__(self, token: str):
8688
self.org = Orgs()
8789
self.quota = Quota()
8890
self.report = Report()
91+
self.sbom = Sbom()
8992
self.repositories = Repositories()
9093
self.settings = Settings()

socketdev/sbom/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import socketdev
2+
import json
3+
4+
class Sbom:
5+
@staticmethod
6+
def get_sbom_data(report_id: str) -> list:
7+
path = f"sbom/view/{report_id}"
8+
response = socketdev.do_request(path=path)
9+
if response.status_code == 200:
10+
sbom = []
11+
sbom_dict = {}
12+
data = response.text
13+
data.strip('"')
14+
data.strip()
15+
for line in data.split("\n"):
16+
if line != '"' and line != "" and line is not None:
17+
item = json.loads(line)
18+
sbom.append(item)
19+
for key, val in enumerate(sbom):
20+
sbom_dict[val['id']] = val
21+
else:
22+
sbom_dict = {}
23+
return sbom_dict

0 commit comments

Comments
 (0)