Skip to content

Commit 0498262

Browse files
authored
Merge pull request #33 from Turall/issue-#32
fix issue #32
2 parents 9a3b0d6 + a091672 commit 0498262

File tree

3 files changed

+928
-605
lines changed

3 files changed

+928
-605
lines changed

opa_client/opa.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99

1010
from .base import BaseClient
1111
from .errors import (
12-
CheckPermissionError,
13-
ConnectionsError,
14-
DeleteDataError,
15-
DeletePolicyError,
16-
FileError,
17-
PathNotFoundError,
18-
PolicyNotFoundError,
19-
RegoParseError,
20-
TypeException,
12+
CheckPermissionError,
13+
ConnectionsError,
14+
DeleteDataError,
15+
DeletePolicyError,
16+
FileError,
17+
PathNotFoundError,
18+
PolicyNotFoundError,
19+
RegoParseError,
20+
TypeException,
2121
)
2222

2323

@@ -61,7 +61,9 @@ def _init_session(self) -> requests.Session:
6161
session.mount("https://", adapter)
6262

6363
if self.ssl:
64-
session.verify = self.cert
64+
session.verify = self.ssl
65+
if self.cert:
66+
session.cert = self.cert
6567

6668
return session
6769

@@ -201,7 +203,9 @@ def update_policy_from_file(self, filepath: str, endpoint: str) -> bool:
201203
bool: True if the policy was successfully updated.
202204
"""
203205
if not os.path.isfile(filepath):
204-
raise FileError("file_not_found",f"'{filepath}' is not a valid file")
206+
raise FileError(
207+
"file_not_found", f"'{filepath}' is not a valid file"
208+
)
205209

206210
with open(filepath, "r", encoding="utf-8") as file:
207211
policy_str = file.read()
@@ -299,7 +303,9 @@ def policy_to_file(
299303
policy_raw = policy.get("result", {}).get("raw", "")
300304

301305
if not policy_raw:
302-
raise PolicyNotFoundError("resource_not_found", "Policy content is empty")
306+
raise PolicyNotFoundError(
307+
"resource_not_found", "Policy content is empty"
308+
)
303309

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

@@ -308,7 +314,9 @@ def policy_to_file(
308314
file.write(policy_raw)
309315
return True
310316
except OSError as e:
311-
raise PathNotFoundError("path_not_found", f"Failed to write to '{full_path}'") from e
317+
raise PathNotFoundError(
318+
"path_not_found", f"Failed to write to '{full_path}'"
319+
) from e
312320

313321
def get_policy(self, policy_name: str) -> dict:
314322
"""
@@ -394,7 +402,8 @@ def check_permission(
394402

395403
if rule_name not in rules:
396404
raise CheckPermissionError(
397-
"resource_not_found", f"Rule '{rule_name}' not found in policy '{policy_name}'"
405+
"resource_not_found",
406+
f"Rule '{rule_name}' not found in policy '{policy_name}'",
398407
)
399408

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

opa_client/opa_async.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ def __init__(
5050
headers: Optional[dict] = None,
5151
timeout: float = 1.5,
5252
):
53-
if not isinstance(port, int):
54-
raise TypeError("The port must be an integer")
55-
5653
self.host = host.strip()
5754
self.port = port
5855
self.version = version
@@ -221,9 +218,8 @@ async def update_policy_from_string(
221218
) as response:
222219
if response.status == 200:
223220
return True
224-
else:
225-
error = await response.json()
226-
raise RegoParseError(error.get("code"), error.get("message"))
221+
error = await response.json()
222+
raise RegoParseError(error.get("code"), error.get("message"))
227223

228224
async def update_policy_from_file(
229225
self, filepath: str, endpoint: str

0 commit comments

Comments
 (0)