1
- import json
2
1
import os
3
2
import threading
4
3
from typing import Dict , Optional
10
9
11
10
from .base import BaseClient
12
11
from .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 ,
22
21
)
23
22
24
23
@@ -202,7 +201,7 @@ def update_policy_from_file(self, filepath: str, endpoint: str) -> bool:
202
201
bool: True if the policy was successfully updated.
203
202
"""
204
203
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" )
206
205
207
206
with open (filepath , "r" , encoding = "utf-8" ) as file :
208
207
policy_str = file .read ()
@@ -300,7 +299,7 @@ def policy_to_file(
300
299
policy_raw = policy .get ("result" , {}).get ("raw" , "" )
301
300
302
301
if not policy_raw :
303
- raise PolicyNotFoundError ("Policy content is empty" )
302
+ raise PolicyNotFoundError ("resource_not_found" , " Policy content is empty" )
304
303
305
304
full_path = os .path .join (path or "" , filename )
306
305
@@ -309,7 +308,7 @@ def policy_to_file(
309
308
file .write (policy_raw )
310
309
return True
311
310
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
313
312
314
313
def get_policy (self , policy_name : str ) -> dict :
315
314
"""
@@ -395,7 +394,7 @@ def check_permission(
395
394
396
395
if rule_name not in rules :
397
396
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 } '"
399
398
)
400
399
401
400
url = f"{ self .root_url } /{ package_path } /{ rule_name } "
0 commit comments