Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions opa_client/opa.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import os
import threading
from typing import Dict, Optional
Expand All @@ -10,15 +9,15 @@

from .base import BaseClient
from .errors import (
CheckPermissionError,
ConnectionsError,
DeleteDataError,
DeletePolicyError,
FileError,
PathNotFoundError,
PolicyNotFoundError,
RegoParseError,
TypeException,
CheckPermissionError,
ConnectionsError,
DeleteDataError,
DeletePolicyError,
FileError,
PathNotFoundError,
PolicyNotFoundError,
RegoParseError,
TypeException,
)


Expand Down Expand Up @@ -202,7 +201,7 @@ def update_policy_from_file(self, filepath: str, endpoint: str) -> bool:
bool: True if the policy was successfully updated.
"""
if not os.path.isfile(filepath):
raise FileError(f"'{filepath}' is not a valid file")
raise FileError("file_not_found",f"'{filepath}' is not a valid file")

with open(filepath, "r", encoding="utf-8") as file:
policy_str = file.read()
Expand Down Expand Up @@ -300,7 +299,7 @@ def policy_to_file(
policy_raw = policy.get("result", {}).get("raw", "")

if not policy_raw:
raise PolicyNotFoundError("Policy content is empty")
raise PolicyNotFoundError("resource_not_found", "Policy content is empty")

full_path = os.path.join(path or "", filename)

Expand All @@ -309,7 +308,7 @@ def policy_to_file(
file.write(policy_raw)
return True
except OSError as e:
raise PathNotFoundError(f"Failed to write to '{full_path}'") from e
raise PathNotFoundError("path_not_found", f"Failed to write to '{full_path}'") from e

def get_policy(self, policy_name: str) -> dict:
"""
Expand Down Expand Up @@ -395,7 +394,7 @@ def check_permission(

if rule_name not in rules:
raise CheckPermissionError(
f"Rule '{rule_name}' not found in policy '{policy_name}'"
"resource_not_found", f"Rule '{rule_name}' not found in policy '{policy_name}'"
)

url = f"{self.root_url}/{package_path}/{rule_name}"
Expand Down