11from urllib .parse import urlencode
22from dataclasses import dataclass , asdict
33from typing import Optional
4+ import logging
5+
6+ log = logging .getLogger ("socketdev" )
47
58
69@dataclass
@@ -23,40 +26,50 @@ class Export:
2326 def __init__ (self , api ):
2427 self .api = api
2528
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 :
2732 """
2833 Export a Socket SBOM as a CycloneDX SBOM
2934 :param org_slug: String - The slug of the organization
3035 :param id: String - The id of either a full scan or an sbom report
3136 :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
3339 """
3440 path = f"orgs/{ org_slug } /export/cdx/{ id } "
3541 if query_params :
3642 path += query_params .to_query_params ()
3743 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 :
4656 """
4757 Export a Socket SBOM as an SPDX SBOM
4858 :param org_slug: String - The slug of the organization
4959 :param id: String - The id of either a full scan or an sbom report
5060 :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
5263 """
5364 path = f"orgs/{ org_slug } /export/spdx/{ id } "
5465 if query_params :
5566 path += query_params .to_query_params ()
5667 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