Skip to content

fix issue #32 #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
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
37 changes: 23 additions & 14 deletions opa_client/opa.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,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 @@ -61,7 +61,9 @@ def _init_session(self) -> requests.Session:
session.mount("https://", adapter)

if self.ssl:
session.verify = self.cert
session.verify = self.ssl
if self.cert:
session.cert = self.cert

return session

Expand Down Expand Up @@ -201,7 +203,9 @@ 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("file_not_found",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 @@ -299,7 +303,9 @@ def policy_to_file(
policy_raw = policy.get("result", {}).get("raw", "")

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

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

Expand All @@ -308,7 +314,9 @@ def policy_to_file(
file.write(policy_raw)
return True
except OSError as e:
raise PathNotFoundError("path_not_found", 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 @@ -394,7 +402,8 @@ def check_permission(

if rule_name not in rules:
raise CheckPermissionError(
"resource_not_found", 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
8 changes: 2 additions & 6 deletions opa_client/opa_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ def __init__(
headers: Optional[dict] = None,
timeout: float = 1.5,
):
if not isinstance(port, int):
raise TypeError("The port must be an integer")

self.host = host.strip()
self.port = port
self.version = version
Expand Down Expand Up @@ -221,9 +218,8 @@ async def update_policy_from_string(
) as response:
if response.status == 200:
return True
else:
error = await response.json()
raise RegoParseError(error.get("code"), error.get("message"))
error = await response.json()
raise RegoParseError(error.get("code"), error.get("message"))

async def update_policy_from_file(
self, filepath: str, endpoint: str
Expand Down
Loading