88
99logger = logging .getLogger (__name__ )
1010
11+
1112class CodeInsightClient :
1213 """Client for the code insight API."""
1314
14- def __init__ (self ,
15- base_url : str ,
16- api_token : str ,
17- timeout : int = 60 ,
18- verify_ssl : bool = True ,
19- experimental : bool = False
20- ):
21-
15+ def __init__ (
16+ self ,
17+ base_url : str ,
18+ api_token : str ,
19+ timeout : int = 60 ,
20+ verify_ssl : bool = True ,
21+ experimental : bool = False ,
22+ ):
2223 self .base_url = base_url
2324 self .api_url = f"{ base_url } /codeinsight/api"
2425 self .__api_token = api_token
2526 self .__api_headers = {
26- ' Content-Type' : ' application/json' ,
27+ " Content-Type" : " application/json" ,
2728 "Authorization" : "Bearer %s" % self .__api_token ,
2829 "User-Agent" : "codeinsight_sdk_python" ,
2930 }
3031 self .__timeout = timeout
3132 self .__verify_ssl = verify_ssl
3233 self .experimental_enabled = experimental
3334
34- def request (self , method , url_part : str , params : dict = None , body : any = None , data : any = None , content_type : str = None ):
35+ def request (
36+ self ,
37+ method ,
38+ url_part : str ,
39+ params : dict = None ,
40+ body : any = None ,
41+ data : any = None ,
42+ content_type : str = None ,
43+ ):
3544 url = f"{ self .api_url } /{ url_part } "
3645
3746 # Iterate over params and remove any that are None (Empty)
38- if ( params ) :
47+ if params :
3948 for k , v in list (params .items ()):
4049 if v is None :
4150 del params [k ]
4251
4352 # Update headers if content_type is specified
4453 headers = self .__api_headers
4554 if content_type :
46- headers ['Content-Type' ] = content_type
47-
48- response = requests .request (method , url ,
49- headers = self .__api_headers , params = params , json = body , data = data ,
50- timeout = self .__timeout , verify = self .__verify_ssl )
55+ headers ["Content-Type" ] = content_type
56+
57+ response = requests .request (
58+ method ,
59+ url ,
60+ headers = self .__api_headers ,
61+ params = params ,
62+ json = body ,
63+ data = data ,
64+ timeout = self .__timeout ,
65+ verify = self .__verify_ssl ,
66+ )
5167
5268 if not response .ok :
53- logger .error (f"Error: { response .status_code } - { response .reason } " , exc_info = True )
69+ logger .error (
70+ f"Error: { response .status_code } - { response .reason } " , exc_info = True
71+ )
5472 logger .error (response .text )
55- raise CodeInsightError (response )
73+ raise CodeInsightError (response )
5674
5775 return response
5876
@@ -75,10 +93,8 @@ def experimental(self) -> ExperimentalHandler:
7593 else :
7694 return ExperimentalHandler (self )
7795
78-
7996 # Coming soon...?
8097
81-
8298 def vulnerabilites (self ):
8399 raise NotImplementedError
84100
@@ -105,4 +121,3 @@ def jobs(self):
105121
106122 def components (self ):
107123 raise NotImplementedError
108-
0 commit comments