File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed
Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -9,16 +9,22 @@ def update_casbin_policies(conn: Connection, file_path: str):
99 Update Casbin policies from a JSON file and insert into the casbin_rule table.
1010 Warning : This will delete all the existing policies
1111 """
12- with open (file_path ) as f :
13- data = json .load (f )
12+ try :
13+ with open (file_path ) as f :
14+ data = json .load (f )
15+ except FileNotFoundError :
16+ raise ValueError (f'Policy file not found: { file_path } ' )
1417
1518 # Clear all existing policies
1619 conn .execute (text ("DELETE FROM casbin_rule WHERE ptype = 'p'" ))
1720
1821 for policy in data .get ("permissions" , []):
19- role = policy ["role" ]
20- resource = policy ["resource" ]
21- actions = policy ["actions" ]
22+ try :
23+ role = policy ["role" ]
24+ resource = policy ["resource" ]
25+ actions = policy ["actions" ]
26+ except KeyError as e :
27+ raise ValueError (f'Missing required field in policy: { str (e )} ' )
2228
2329 for action in actions :
2430 conn .execute (
You can’t perform that action at this time.
0 commit comments