1
1
from urllib .parse import urlencode
2
2
from dataclasses import dataclass , asdict
3
3
from typing import Optional
4
+ import logging
5
+
6
+ log = logging .getLogger ("socketdev" )
4
7
5
8
6
9
@dataclass
@@ -23,40 +26,50 @@ class Export:
23
26
def __init__ (self , api ):
24
27
self .api = api
25
28
26
- def cdx_bom (self , org_slug : str , id : str , query_params : Optional [ExportQueryParams ] = None ) -> dict :
29
+ def cdx_bom (
30
+ self , org_slug : str , id : str , query_params : Optional [ExportQueryParams ] = None , use_types : bool = False
31
+ ) -> dict :
27
32
"""
28
33
Export a Socket SBOM as a CycloneDX SBOM
29
34
:param org_slug: String - The slug of the organization
30
35
:param id: String - The id of either a full scan or an sbom report
31
36
:param query_params: Optional[ExportQueryParams] - Query parameters for filtering
32
- :return:
37
+ :param use_types: Optional[bool] - Whether to return typed responses
38
+ :return: dict
33
39
"""
34
40
path = f"orgs/{ org_slug } /export/cdx/{ id } "
35
41
if query_params :
36
42
path += query_params .to_query_params ()
37
43
response = self .api .do_request (path = path )
38
- try :
39
- sbom = response .json ()
40
- sbom ["success" ] = True
41
- except Exception as error :
42
- sbom = {"success" : False , "message" : str (error )}
43
- return sbom
44
-
45
- def spdx_bom (self , org_slug : str , id : str , query_params : Optional [ExportQueryParams ] = None ) -> dict :
44
+
45
+ if response .status_code == 200 :
46
+ return response .json ()
47
+ # TODO: Add typed response when types are defined
48
+
49
+ log .error (f"Error exporting CDX BOM: { response .status_code } " )
50
+ print (response .text )
51
+ return {}
52
+
53
+ def spdx_bom (
54
+ self , org_slug : str , id : str , query_params : Optional [ExportQueryParams ] = None , use_types : bool = False
55
+ ) -> dict :
46
56
"""
47
57
Export a Socket SBOM as an SPDX SBOM
48
58
:param org_slug: String - The slug of the organization
49
59
:param id: String - The id of either a full scan or an sbom report
50
60
:param query_params: Optional[ExportQueryParams] - Query parameters for filtering
51
- :return:
61
+ :param use_types: Optional[bool] - Whether to return typed responses
62
+ :return: dict
52
63
"""
53
64
path = f"orgs/{ org_slug } /export/spdx/{ id } "
54
65
if query_params :
55
66
path += query_params .to_query_params ()
56
67
response = self .api .do_request (path = path )
57
- try :
58
- sbom = response .json ()
59
- sbom ["success" ] = True
60
- except Exception as error :
61
- sbom = {"success" : False , "message" : str (error )}
62
- return sbom
68
+
69
+ if response .status_code == 200 :
70
+ return response .json ()
71
+ # TODO: Add typed response when types are defined
72
+
73
+ log .error (f"Error exporting SPDX BOM: { response .status_code } " )
74
+ print (response .text )
75
+ return {}
0 commit comments