9
9
10
10
from .base import BaseClient
11
11
from .errors import (
12
- CheckPermissionError ,
13
- ConnectionsError ,
14
- DeleteDataError ,
15
- DeletePolicyError ,
16
- FileError ,
17
- PathNotFoundError ,
18
- PolicyNotFoundError ,
19
- RegoParseError ,
20
- TypeException ,
12
+ CheckPermissionError ,
13
+ ConnectionsError ,
14
+ DeleteDataError ,
15
+ DeletePolicyError ,
16
+ FileError ,
17
+ PathNotFoundError ,
18
+ PolicyNotFoundError ,
19
+ RegoParseError ,
20
+ TypeException ,
21
21
)
22
22
23
23
@@ -61,7 +61,9 @@ def _init_session(self) -> requests.Session:
61
61
session .mount ("https://" , adapter )
62
62
63
63
if self .ssl :
64
- session .verify = self .cert
64
+ session .verify = self .ssl
65
+ if self .cert :
66
+ session .cert = self .cert
65
67
66
68
return session
67
69
@@ -201,7 +203,9 @@ def update_policy_from_file(self, filepath: str, endpoint: str) -> bool:
201
203
bool: True if the policy was successfully updated.
202
204
"""
203
205
if not os .path .isfile (filepath ):
204
- raise FileError ("file_not_found" ,f"'{ filepath } ' is not a valid file" )
206
+ raise FileError (
207
+ "file_not_found" , f"'{ filepath } ' is not a valid file"
208
+ )
205
209
206
210
with open (filepath , "r" , encoding = "utf-8" ) as file :
207
211
policy_str = file .read ()
@@ -299,7 +303,9 @@ def policy_to_file(
299
303
policy_raw = policy .get ("result" , {}).get ("raw" , "" )
300
304
301
305
if not policy_raw :
302
- raise PolicyNotFoundError ("resource_not_found" , "Policy content is empty" )
306
+ raise PolicyNotFoundError (
307
+ "resource_not_found" , "Policy content is empty"
308
+ )
303
309
304
310
full_path = os .path .join (path or "" , filename )
305
311
@@ -308,7 +314,9 @@ def policy_to_file(
308
314
file .write (policy_raw )
309
315
return True
310
316
except OSError as e :
311
- raise PathNotFoundError ("path_not_found" , f"Failed to write to '{ full_path } '" ) from e
317
+ raise PathNotFoundError (
318
+ "path_not_found" , f"Failed to write to '{ full_path } '"
319
+ ) from e
312
320
313
321
def get_policy (self , policy_name : str ) -> dict :
314
322
"""
@@ -394,7 +402,8 @@ def check_permission(
394
402
395
403
if rule_name not in rules :
396
404
raise CheckPermissionError (
397
- "resource_not_found" , f"Rule '{ rule_name } ' not found in policy '{ policy_name } '"
405
+ "resource_not_found" ,
406
+ f"Rule '{ rule_name } ' not found in policy '{ policy_name } '" ,
398
407
)
399
408
400
409
url = f"{ self .root_url } /{ package_path } /{ rule_name } "
0 commit comments