Skip to content

Commit 01c6a05

Browse files
committed
refactor!: rename batch_check to client_batch_check
BREAKING CHANGE: Usage of the existing batch_check should now use client_batch_check instead, additionally the existing BatchCheckResponse has been renamed to ClientBatchCheckClientResponse.
1 parent 7af8409 commit 01c6a05

6 files changed

Lines changed: 89 additions & 20 deletions

File tree

openfga_sdk/client/client.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
ClientCheckRequest,
2323
construct_check_request,
2424
)
25+
from openfga_sdk.client.models.client_batch_check_response import ClientBatchCheckClientResponse
2526
from openfga_sdk.client.models.expand_request import ClientExpandRequest
2627
from openfga_sdk.client.models.list_objects_request import ClientListObjectsRequest
2728
from openfga_sdk.client.models.list_relations_request import ClientListRelationsRequest
@@ -115,7 +116,7 @@ def options_to_transaction_info(options: dict[str, int | str] = None):
115116
return WriteTransactionOpts()
116117

117118

118-
def _check_allowed(response: BatchCheckResponse):
119+
def _check_allowed(response: ClientBatchCheckClientResponse):
119120
"""
120121
Helper function to return whether the response is check is allowed
121122
"""
@@ -571,7 +572,7 @@ async def check(self, body: ClientCheckRequest, options: dict[str, str] = None):
571572
api_response = await self._api.check(body=req_body, **kwargs)
572573
return api_response
573574

574-
async def _single_batch_check(
575+
async def _single_client_batch_check(
575576
self,
576577
body: ClientCheckRequest,
577578
semaphore: asyncio.Semaphore,
@@ -585,7 +586,7 @@ async def _single_batch_check(
585586
await semaphore.acquire()
586587
try:
587588
api_response = await self.check(body, options)
588-
return BatchCheckResponse(
589+
return ClientBatchCheckClientResponse(
589590
allowed=api_response.allowed,
590591
request=body,
591592
response=api_response,
@@ -594,13 +595,13 @@ async def _single_batch_check(
594595
except (AuthenticationError, UnauthorizedException) as err:
595596
raise err
596597
except Exception as err:
597-
return BatchCheckResponse(
598+
return ClientBatchCheckClientResponse(
598599
allowed=False, request=body, response=None, error=err
599600
)
600601
finally:
601602
semaphore.release()
602603

603-
async def batch_check(
604+
async def client_batch_check(
604605
self, body: list[ClientCheckRequest], options: dict[str, str | int] = None
605606
):
606607
"""
@@ -630,7 +631,7 @@ async def batch_check(
630631

631632
sem = asyncio.Semaphore(max_parallel_requests)
632633
batch_check_coros = [
633-
self._single_batch_check(request, sem, options) for request in body
634+
self._single_client_batch_check(request, sem, options) for request in body
634635
]
635636
batch_check_response = await asyncio.gather(*batch_check_coros)
636637

@@ -718,7 +719,7 @@ async def list_relations(
718719
)
719720
for i in body.relations
720721
]
721-
result = await self.batch_check(request_body, options)
722+
result = await self.client_batch_check(request_body, options)
722723
# need to filter with the allowed response
723724
result_iterator = filter(_check_allowed, result)
724725
result_list = list(result_iterator)

openfga_sdk/client/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from openfga_sdk.client.models.assertion import ClientAssertion
1414
from openfga_sdk.client.models.batch_check_response import BatchCheckResponse
1515
from openfga_sdk.client.models.check_request import ClientCheckRequest
16+
from openfga_sdk.client.models.client_batch_check_response import ClientBatchCheckClientResponse
1617
from openfga_sdk.client.models.expand_request import ClientExpandRequest
1718
from openfga_sdk.client.models.list_objects_request import ClientListObjectsRequest
1819
from openfga_sdk.client.models.list_relations_request import ClientListRelationsRequest
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""
2+
Python SDK for OpenFGA
3+
4+
API version: 1.x
5+
Website: https://openfga.dev
6+
Documentation: https://openfga.dev/docs
7+
Support: https://openfga.dev/community
8+
License: [Apache-2.0](https://github.com/openfga/python-sdk/blob/main/LICENSE)
9+
10+
NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT.
11+
"""
12+
13+
from openfga_sdk.client.models.check_request import ClientCheckRequest
14+
from openfga_sdk.models.check_response import CheckResponse
15+
16+
17+
class ClientBatchCheckClientResponse:
18+
"""
19+
ClientBatchCheckClientResponse encapsulates the response for a single batch check
20+
"""
21+
22+
def __init__(
23+
self,
24+
allowed: bool,
25+
request: ClientCheckRequest,
26+
response: CheckResponse,
27+
error: Exception = None,
28+
):
29+
self._allowed = allowed
30+
self._request = request
31+
self._response = response
32+
self._error = error
33+
34+
@property
35+
def allowed(self):
36+
"""
37+
Return whether request is allowed
38+
"""
39+
return self._allowed
40+
41+
@property
42+
def request(self):
43+
"""
44+
Return original request
45+
"""
46+
return self._request
47+
48+
@property
49+
def response(self):
50+
"""
51+
Return original request
52+
"""
53+
return self._response
54+
55+
@property
56+
def error(self):
57+
"""
58+
Return error associated with batch request (if any)
59+
"""
60+
return self._error
61+
62+
def __str__(self):
63+
"""
64+
Return the class string
65+
"""
66+
return f"allowed {self._allowed} request {self._request} error {self._error}"

openfga_sdk/sync/client/client.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
ClientCheckRequest,
2121
construct_check_request,
2222
)
23+
from openfga_sdk.client.models.client_batch_check_response import ClientBatchCheckClientResponse
2324
from openfga_sdk.client.models.expand_request import ClientExpandRequest
2425
from openfga_sdk.client.models.list_objects_request import ClientListObjectsRequest
2526
from openfga_sdk.client.models.list_relations_request import ClientListRelationsRequest
@@ -115,7 +116,7 @@ def options_to_transaction_info(options: dict[str, int | str] = None):
115116
return WriteTransactionOpts()
116117

117118

118-
def _check_allowed(response: BatchCheckResponse):
119+
def _check_allowed(response: ClientBatchCheckClientResponse):
119120
"""
120121
Helper function to return whether the response is check is allowed
121122
"""
@@ -564,7 +565,7 @@ def check(self, body: ClientCheckRequest, options: dict[str, str] = None):
564565
api_response = self._api.check(body=req_body, **kwargs)
565566
return api_response
566567

567-
def _single_batch_check(
568+
def _single_client_batch_check(
568569
self, body: ClientCheckRequest, options: dict[str, str] = None
569570
):
570571
"""
@@ -574,7 +575,7 @@ def _single_batch_check(
574575
"""
575576
try:
576577
api_response = self.check(body, options)
577-
return BatchCheckResponse(
578+
return ClientBatchCheckClientResponse(
578579
allowed=api_response.allowed,
579580
request=body,
580581
response=api_response,
@@ -583,11 +584,11 @@ def _single_batch_check(
583584
except (AuthenticationError, UnauthorizedException) as err:
584585
raise err
585586
except Exception as err:
586-
return BatchCheckResponse(
587+
return ClientBatchCheckClientResponse(
587588
allowed=False, request=body, response=None, error=err
588589
)
589590

590-
def batch_check(
591+
def client_batch_check(
591592
self, body: list[ClientCheckRequest], options: dict[str, str | int] = None
592593
):
593594
"""
@@ -619,7 +620,7 @@ def batch_check(
619620
batch_check_response = []
620621

621622
def single_batch_check(request):
622-
return self._single_batch_check(request, options)
623+
return self._single_client_batch_check(request, options)
623624

624625
with ThreadPoolExecutor(max_workers=max_parallel_requests) as executor:
625626
for response in executor.map(single_batch_check, body):
@@ -709,7 +710,7 @@ def list_relations(
709710
)
710711
for i in body.relations
711712
]
712-
result = self.batch_check(request_body, options)
713+
result = self.client_batch_check(request_body, options)
713714
# need to filter with the allowed response
714715
result_iterator = filter(_check_allowed, result)
715716
result_list = list(result_iterator)

test/client/client_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,7 +1936,7 @@ async def test_batch_check_single_request(self, mock_request):
19361936
configuration = self.configuration
19371937
configuration.store_id = store_id
19381938
async with OpenFgaClient(configuration) as api_client:
1939-
api_response = await api_client.batch_check(
1939+
api_response = await api_client.client_batch_check(
19401940
body=[body],
19411941
options={"authorization_model_id": "01GXSA8YR785C4FYS3C0RTG7B1"},
19421942
)
@@ -1996,7 +1996,7 @@ async def test_batch_check_multiple_request(self, mock_request):
19961996
configuration = self.configuration
19971997
configuration.store_id = store_id
19981998
async with OpenFgaClient(configuration) as api_client:
1999-
api_response = await api_client.batch_check(
1999+
api_response = await api_client.client_batch_check(
20002000
body=[body1, body2, body3],
20012001
options={
20022002
"authorization_model_id": "01GXSA8YR785C4FYS3C0RTG7B1",
@@ -2105,7 +2105,7 @@ async def test_batch_check_multiple_request_fail(self, mock_request):
21052105
configuration = self.configuration
21062106
configuration.store_id = store_id
21072107
async with OpenFgaClient(configuration) as api_client:
2108-
api_response = await api_client.batch_check(
2108+
api_response = await api_client.client_batch_check(
21092109
body=[body1, body2, body3],
21102110
options={
21112111
"authorization_model_id": "01GXSA8YR785C4FYS3C0RTG7B1",

test/sync/client/client_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,7 +1935,7 @@ def test_batch_check_single_request(self, mock_request):
19351935
configuration = self.configuration
19361936
configuration.store_id = store_id
19371937
with OpenFgaClient(configuration) as api_client:
1938-
api_response = api_client.batch_check(
1938+
api_response = api_client.client_batch_check(
19391939
body=[body],
19401940
options={
19411941
"authorization_model_id": "01GXSA8YR785C4FYS3C0RTG7B1",
@@ -1999,7 +1999,7 @@ def test_batch_check_multiple_request(self, mock_request):
19991999
configuration = self.configuration
20002000
configuration.store_id = store_id
20012001
with OpenFgaClient(configuration) as api_client:
2002-
api_response = api_client.batch_check(
2002+
api_response = api_client.client_batch_check(
20032003
body=[body1, body2, body3],
20042004
options={
20052005
"authorization_model_id": "01GXSA8YR785C4FYS3C0RTG7B1",
@@ -2108,7 +2108,7 @@ def test_batch_check_multiple_request_fail(self, mock_request):
21082108
configuration = self.configuration
21092109
configuration.store_id = store_id
21102110
with OpenFgaClient(configuration) as api_client:
2111-
api_response = api_client.batch_check(
2111+
api_response = api_client.client_batch_check(
21122112
body=[body1, body2, body3],
21132113
options={
21142114
"authorization_model_id": "01GXSA8YR785C4FYS3C0RTG7B1",

0 commit comments

Comments
 (0)