1- import json
21import os
32import threading
43from typing import Dict , Optional
109
1110from .base import BaseClient
1211from .errors import (
13- CheckPermissionError ,
14- ConnectionsError ,
15- DeleteDataError ,
16- DeletePolicyError ,
17- FileError ,
18- PathNotFoundError ,
19- PolicyNotFoundError ,
20- RegoParseError ,
21- TypeException ,
12+ CheckPermissionError ,
13+ ConnectionsError ,
14+ DeleteDataError ,
15+ DeletePolicyError ,
16+ FileError ,
17+ PathNotFoundError ,
18+ PolicyNotFoundError ,
19+ RegoParseError ,
20+ TypeException ,
2221)
2322
2423
@@ -202,7 +201,7 @@ def update_policy_from_file(self, filepath: str, endpoint: str) -> bool:
202201 bool: True if the policy was successfully updated.
203202 """
204203 if not os .path .isfile (filepath ):
205- raise FileError (f"'{ filepath } ' is not a valid file" )
204+ raise FileError ("file_not_found" , f"'{ filepath } ' is not a valid file" )
206205
207206 with open (filepath , "r" , encoding = "utf-8" ) as file :
208207 policy_str = file .read ()
@@ -300,7 +299,7 @@ def policy_to_file(
300299 policy_raw = policy .get ("result" , {}).get ("raw" , "" )
301300
302301 if not policy_raw :
303- raise PolicyNotFoundError ("Policy content is empty" )
302+ raise PolicyNotFoundError ("resource_not_found" , " Policy content is empty" )
304303
305304 full_path = os .path .join (path or "" , filename )
306305
@@ -309,7 +308,7 @@ def policy_to_file(
309308 file .write (policy_raw )
310309 return True
311310 except OSError as e :
312- raise PathNotFoundError (f"Failed to write to '{ full_path } '" ) from e
311+ raise PathNotFoundError ("path_not_found" , f"Failed to write to '{ full_path } '" ) from e
313312
314313 def get_policy (self , policy_name : str ) -> dict :
315314 """
@@ -395,7 +394,7 @@ def check_permission(
395394
396395 if rule_name not in rules :
397396 raise CheckPermissionError (
398- f"Rule '{ rule_name } ' not found in policy '{ policy_name } '"
397+ "resource_not_found" , f"Rule '{ rule_name } ' not found in policy '{ policy_name } '"
399398 )
400399
401400 url = f"{ self .root_url } /{ package_path } /{ rule_name } "
0 commit comments