Skip to content

Commit 92feebf

Browse files
authored
Merge pull request #34 from Turall/issue-#31
fix issue #31
2 parents 0498262 + d967b1b commit 92feebf

File tree

5 files changed

+48
-27
lines changed

5 files changed

+48
-27
lines changed

README.md

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -354,31 +354,7 @@ await client.delete_data('users')
354354

355355
#### Check Permission (Policy Evaluation)
356356

357-
You can evaluate policies with input data using `check_permission`.
358-
359-
- **Synchronous**:
360-
361-
```python
362-
input_data = {"user": "admin"}
363-
policy_name = 'example_policy'
364-
rule_name = 'allow'
365-
366-
result = client.check_permission(input_data, policy_name, rule_name)
367-
print(result)
368-
```
369-
370-
- **Asynchronous**:
371-
372-
```python
373-
input_data = {"user": "admin"}
374-
policy_name = 'example_policy'
375-
rule_name = 'allow'
376-
377-
result = await client.check_permission(input_data, policy_name, rule_name)
378-
print(result)
379-
```
380-
381-
Queries a package rule with the given input data
357+
Evaluate a rule from a known package path. This is the **recommended method** for evaluating OPA decisions.
382358

383359
```python
384360

@@ -422,6 +398,39 @@ print(await client.query_rule(input_data=check_data, package_path="play", rule_n
422398

423399
```
424400

401+
You can evaluate policies with input data using `check_permission`.
402+
### ⚠️ Deprecated: `check_permission()`
403+
404+
This method introspects the policy AST to construct a query path dynamically. It introduces unnecessary overhead and is **not recommended** for production use.
405+
406+
- **Synchronous**:
407+
408+
```python
409+
input_data = {"user": "admin"}
410+
policy_name = 'example_policy'
411+
rule_name = 'allow'
412+
413+
result = client.check_permission(input_data, policy_name, rule_name)
414+
print(result)
415+
```
416+
> 🔥 Prefer `query_rule()` instead for better performance and maintainability.
417+
418+
### ⚠️ Deprecated: `check_permission()`
419+
420+
- **Asynchronous**:
421+
422+
```python
423+
input_data = {"user": "admin"}
424+
policy_name = 'example_policy'
425+
rule_name = 'allow'
426+
427+
result = await client.check_permission(input_data, policy_name, rule_name)
428+
print(result)
429+
```
430+
> 🔥 Prefer `query_rule()` instead for better performance and maintainability.
431+
432+
433+
425434
### Ad-hoc Queries
426435

427436
Execute ad-hoc queries directly:

opa_client/opa.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import threading
3+
import warnings
34
from typing import Dict, Optional
45
from urllib.parse import urlencode
56

@@ -391,6 +392,11 @@ def check_permission(
391392
Returns:
392393
dict: The result of the permission check.
393394
"""
395+
warnings.warn(
396+
"check_permission is deprecated and will be removed in a future release. Use `query_rule` instead.",
397+
DeprecationWarning,
398+
stacklevel=2
399+
)
394400
policy = self.get_policy(policy_name)
395401
ast = policy.get("result", {}).get("ast", {})
396402
package_path = "/".join(

opa_client/opa_async.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import asyncio
2-
import json
2+
import warnings
33
import os
44
import ssl
55
from typing import Dict, Optional, Union
@@ -422,6 +422,11 @@ async def check_permission(
422422
Returns:
423423
dict: The result of the permission check.
424424
"""
425+
warnings.warn(
426+
"check_permission is deprecated and will be removed in a future release. Use `query_rule` instead.",
427+
DeprecationWarning,
428+
stacklevel=2
429+
)
425430
policy = await self.get_policy(policy_name)
426431
ast = policy.get("result", {}).get("ast", {})
427432
package_path = "/".join(

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ python = "^3.9"
2525
requests = "^2.32.3"
2626
aiohttp = {extras = ["speedups"], version = "^3.10.9"}
2727
aiofiles = "^24.1.0"
28+
urllib3 = "^2.5.0"
2829

2930
[tool.poetry.group.dev.dependencies]
3031
pytest = "^8.3.3"

0 commit comments

Comments
 (0)