Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
100 lines (84 loc) · 3.58 KB

File metadata and controls

100 lines (84 loc) · 3.58 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from urllib.parse import urlencode
from dataclasses import dataclass, asdict
from typing import Optional
import logging
log = logging.getLogger("socketdev")
@dataclass
class ExportQueryParams:
author: Optional[str] = None
project_group: Optional[str] = None
project_name: Optional[str] = None
project_version: Optional[str] = None
project_id: Optional[str] = None
def to_query_params(self) -> str:
# Filter out None values and convert to query string
params = {k: v for k, v in asdict(self).items() if v is not None}
if not params:
return ""
return "?" + urlencode(params)
class Export:
def __init__(self, api):
self.api = api
def cdx_bom(
self, org_slug: str, id: str, query_params: Optional[ExportQueryParams] = None, use_types: bool = False
) -> dict:
"""
Export a Socket SBOM as a CycloneDX SBOM
:param org_slug: String - The slug of the organization
:param id: String - The id of either a full scan or an sbom report
:param query_params: Optional[ExportQueryParams] - Query parameters for filtering
:param use_types: Optional[bool] - Whether to return typed responses
:return: dict
"""
path = f"orgs/{org_slug}/export/cdx/{id}"
if query_params:
path += query_params.to_query_params()
response = self.api.do_request(path=path)
if response.status_code == 200:
return response.json()
# TODO: Add typed response when types are defined
log.error(f"Error exporting CDX BOM: {response.status_code}")
log.error(response.text)
return {}
def spdx_bom(
self, org_slug: str, id: str, query_params: Optional[ExportQueryParams] = None, use_types: bool = False
) -> dict:
"""
Export a Socket SBOM as an SPDX SBOM
:param org_slug: String - The slug of the organization
:param id: String - The id of either a full scan or an sbom report
:param query_params: Optional[ExportQueryParams] - Query parameters for filtering
:param use_types: Optional[bool] - Whether to return typed responses
:return: dict
"""
path = f"orgs/{org_slug}/export/spdx/{id}"
if query_params:
path += query_params.to_query_params()
response = self.api.do_request(path=path)
if response.status_code == 200:
return response.json()
# TODO: Add typed response when types are defined
log.error(f"Error exporting SPDX BOM: {response.status_code}")
log.error(response.text)
return {}
def openvex_bom(
self, org_slug: str, id: str, query_params: Optional[ExportQueryParams] = None, use_types: bool = False
) -> dict:
"""
Export a Socket SBOM as an OpenVEX SBOM
:param org_slug: String - The slug of the organization
:param id: String - The id of either a full scan or an sbom report
:param query_params: Optional[ExportQueryParams] - Query parameters for filtering
:param use_types: Optional[bool] - Whether to return typed responses
:return: dict
"""
path = f"orgs/{org_slug}/export/openvex/{id}"
if query_params:
path += query_params.to_query_params()
response = self.api.do_request(path=path)
if response.status_code == 200:
return response.json()
# TODO: Add typed response when types are defined
log.error(f"Error exporting OpenVEX BOM: {response.status_code}")
log.error(response.text)
return {}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.