Skip to content

Commit 950000b

Browse files
author
Evan Sims
committed
options.store_id = store_id or options.store_id or self.configuration.store_id
1 parent 827c358 commit 950000b

27 files changed

Lines changed: 3927 additions & 3485 deletions

openfga_sdk/api/open_fga_api.py

Lines changed: 113 additions & 389 deletions
Large diffs are not rendered by default.

openfga_sdk/client/client.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ async def create_store(
140140
body: CreateStoreRequest,
141141
options: CreateStoreRequestOptions | None = None,
142142
) -> CreateStoreResponse | ApiClientResponseProtocol:
143+
options = options or CreateStoreRequestOptions()
143144
response = await self.api.create_store(body, options)
144145

145146
if options.return_response:
@@ -149,10 +150,12 @@ async def create_store(
149150

150151
async def get_store(
151152
self,
152-
store_id: str,
153+
store_id: str | None = None,
153154
options: GetStoreRequestOptions | None = None,
154155
) -> GetStoreResponse | ApiClientResponseProtocol:
155-
response = await self.api.get_store(store_id, options)
156+
options = options or GetStoreRequestOptions()
157+
options.store_id = store_id or options.store_id or self.configuration.store_id
158+
response = await self.api.get_store(options)
156159

157160
if options.return_response:
158161
return response
@@ -161,9 +164,11 @@ async def get_store(
161164

162165
async def delete_store(
163166
self,
164-
store_id: str,
167+
store_id: str | None = None,
165168
options: DeleteStoreRequestOptions | None = None,
166169
) -> None | ApiClientResponseProtocol:
170+
options = options or DeleteStoreRequestOptions()
171+
options.store_id = store_id or options.store_id or self.configuration.store_id
167172
response = await self.api.delete_store(store_id, options)
168173

169174
if options.return_response:

openfga_sdk/common/rest.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,13 @@ def from_options(
147147
if options is None:
148148
return params
149149

150-
if options.page_size:
150+
if hasattr(options, "page_size") and options.page_size is not None:
151151
params.add_parameter("page_size", str(options.page_size))
152152

153-
if options.continuation_token:
153+
if (
154+
hasattr(options, "continuation_token")
155+
and options.continuation_token is not None
156+
):
154157
params.add_parameter("continuation_token", options.continuation_token)
155158

156159
return params

openfga_sdk/oauth2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ async def obtain_token(
100100
}
101101
)
102102

103-
for attempt in range(self.configuration.retry_params.max_retry + 1):
103+
for attempt in range(self.configuration.retry_params.max_retries + 1):
104104
response = await client.request(
105105
method="POST",
106106
url=token_url,
@@ -110,7 +110,7 @@ async def obtain_token(
110110

111111
if 500 <= response.status <= 599 or response.status == 429:
112112
if (
113-
attempt < self.configuration.retry_params.max_retry
113+
attempt < self.configuration.retry_params.max_retries
114114
and response.status != 501
115115
):
116116
await asyncio.sleep(

openfga_sdk/protocols.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,6 @@ def remove_cookie(self, name: str) -> None: ...
291291
def items(self): ...
292292

293293

294-
@runtime_checkable
295-
class OAuth2ClientProtocol(Protocol):
296-
pass
297-
298-
299294
@runtime_checkable
300295
class RestClientResponseProtocol(Protocol):
301296
response: (
@@ -394,6 +389,14 @@ def build_request(
394389
) -> RestClientRequestProtocol: ...
395390

396391

392+
@runtime_checkable
393+
class OAuth2ClientProtocol(Protocol):
394+
def get_authentication_header(
395+
self,
396+
client: RestClientProtocol,
397+
) -> HttpHeaderProtocol: ...
398+
399+
397400
@runtime_checkable
398401
class TelemetryAttributeProtocol(Protocol):
399402
# Duck type for TelemetryAttribute, as NamedTuples cannot inherit from Protocol

openfga_sdk/sync/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
from concurrent.futures import ThreadPoolExecutor
1616

17-
from openfga_sdk.client.configuration import ClientConfiguration
1817
from openfga_sdk.client.models.assertion import ClientAssertion
1918
from openfga_sdk.client.models.batch_check_item import (
2019
ClientBatchCheckItem,
@@ -44,6 +43,7 @@
4443
construct_write_single_response,
4544
)
4645
from openfga_sdk.common.client import OpenFgaClientBase
46+
from openfga_sdk.common.options import WriteTransactionOptions
4747
from openfga_sdk.exceptions import (
4848
AuthenticationError,
4949
FgaValidationException,
@@ -342,7 +342,7 @@ def _write_single_batch(
342342
def _write_batches(
343343
self,
344344
tuple_keys: list[ClientTuple],
345-
transaction: WriteTransactionOpts,
345+
transaction: WriteTransactionOptions,
346346
is_write: bool,
347347
options: dict[str, int | str | dict[str, int | str]] | None = None,
348348
):

openfga_sdk/sync/oauth2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def obtain_token(
100100
}
101101
)
102102

103-
for attempt in range(self.configuration.retry_params.max_retry + 1):
103+
for attempt in range(self.configuration.retry_params.max_retries + 1):
104104
response = client.request(
105105
method="POST",
106106
url=token_url,
@@ -110,7 +110,7 @@ def obtain_token(
110110

111111
if 500 <= response.status <= 599 or response.status == 429:
112112
if (
113-
attempt < self.configuration.retry_params.max_retry
113+
attempt < self.configuration.retry_params.max_retries
114114
and response.status != 501
115115
):
116116
time.sleep(

openfga_sdk/sync/open_fga_api.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ def check_with_http_info(self, body, **kwargs):
342342
attributes=telemetry_attributes,
343343
)
344344

345-
return self.api_client.call_api(
345+
return self.api_client.request(
346346
"/stores/{store_id}/check".replace("{store_id}", store_id),
347347
"POST",
348348
path_params,
@@ -493,7 +493,7 @@ def create_store_with_http_info(self, body, **kwargs):
493493
attributes=telemetry_attributes,
494494
)
495495

496-
return self.api_client.call_api(
496+
return self.api_client.request(
497497
"/stores",
498498
"POST",
499499
path_params,
@@ -625,7 +625,7 @@ def delete_store_with_http_info(self, **kwargs):
625625
attributes=telemetry_attributes,
626626
)
627627

628-
return self.api_client.call_api(
628+
return self.api_client.request(
629629
"/stores/{store_id}".replace("{store_id}", store_id),
630630
"DELETE",
631631
path_params,
@@ -790,7 +790,7 @@ def expand_with_http_info(self, body, **kwargs):
790790
attributes=telemetry_attributes,
791791
)
792792

793-
return self.api_client.call_api(
793+
return self.api_client.request(
794794
"/stores/{store_id}/expand".replace("{store_id}", store_id),
795795
"POST",
796796
path_params,
@@ -931,7 +931,7 @@ def get_store_with_http_info(self, **kwargs):
931931
attributes=telemetry_attributes,
932932
)
933933

934-
return self.api_client.call_api(
934+
return self.api_client.request(
935935
"/stores/{store_id}".replace("{store_id}", store_id),
936936
"GET",
937937
path_params,
@@ -1096,7 +1096,7 @@ def list_objects_with_http_info(self, body, **kwargs):
10961096
attributes=telemetry_attributes,
10971097
)
10981098

1099-
return self.api_client.call_api(
1099+
return self.api_client.request(
11001100
"/stores/{store_id}/list-objects".replace("{store_id}", store_id),
11011101
"POST",
11021102
path_params,
@@ -1245,7 +1245,7 @@ def list_stores_with_http_info(self, **kwargs):
12451245
attributes=telemetry_attributes,
12461246
)
12471247

1248-
return self.api_client.call_api(
1248+
return self.api_client.request(
12491249
"/stores",
12501250
"GET",
12511251
path_params,
@@ -1410,7 +1410,7 @@ def list_users_with_http_info(self, body, **kwargs):
14101410
attributes=telemetry_attributes,
14111411
)
14121412

1413-
return self.api_client.call_api(
1413+
return self.api_client.request(
14141414
"/stores/{store_id}/list-users".replace("{store_id}", store_id),
14151415
"POST",
14161416
path_params,
@@ -1575,7 +1575,7 @@ def read_with_http_info(self, body, **kwargs):
15751575
attributes=telemetry_attributes,
15761576
)
15771577

1578-
return self.api_client.call_api(
1578+
return self.api_client.request(
15791579
"/stores/{store_id}/read".replace("{store_id}", store_id),
15801580
"POST",
15811581
path_params,
@@ -1733,7 +1733,7 @@ def read_assertions_with_http_info(self, authorization_model_id, **kwargs):
17331733
attributes=telemetry_attributes,
17341734
)
17351735

1736-
return self.api_client.call_api(
1736+
return self.api_client.request(
17371737
"/stores/{store_id}/assertions/{authorization_model_id}".replace(
17381738
"{store_id}", store_id
17391739
),
@@ -1891,7 +1891,7 @@ def read_authorization_model_with_http_info(self, id, **kwargs):
18911891
attributes=telemetry_attributes,
18921892
)
18931893

1894-
return self.api_client.call_api(
1894+
return self.api_client.request(
18951895
"/stores/{store_id}/authorization-models/{id}".replace(
18961896
"{store_id}", store_id
18971897
),
@@ -2048,7 +2048,7 @@ def read_authorization_models_with_http_info(self, **kwargs):
20482048
attributes=telemetry_attributes,
20492049
)
20502050

2051-
return self.api_client.call_api(
2051+
return self.api_client.request(
20522052
"/stores/{store_id}/authorization-models".replace("{store_id}", store_id),
20532053
"GET",
20542054
path_params,
@@ -2215,7 +2215,7 @@ def read_changes_with_http_info(self, **kwargs):
22152215
attributes=telemetry_attributes,
22162216
)
22172217

2218-
return self.api_client.call_api(
2218+
return self.api_client.request(
22192219
"/stores/{store_id}/changes".replace("{store_id}", store_id),
22202220
"GET",
22212221
path_params,
@@ -2380,7 +2380,7 @@ def streamed_list_objects_with_http_info(self, body, **kwargs):
23802380
attributes=telemetry_attributes,
23812381
)
23822382

2383-
return self.api_client.call_api(
2383+
return self.api_client.request(
23842384
"/stores/{store_id}/streamed-list-objects".replace("{store_id}", store_id),
23852385
"POST",
23862386
path_params,
@@ -2545,7 +2545,7 @@ def write_with_http_info(self, body, **kwargs):
25452545
attributes=telemetry_attributes,
25462546
)
25472547

2548-
return self.api_client.call_api(
2548+
return self.api_client.request(
25492549
"/stores/{store_id}/write".replace("{store_id}", store_id),
25502550
"POST",
25512551
path_params,
@@ -2720,7 +2720,7 @@ def write_assertions_with_http_info(self, authorization_model_id, body, **kwargs
27202720
attributes=telemetry_attributes,
27212721
)
27222722

2723-
return self.api_client.call_api(
2723+
return self.api_client.request(
27242724
"/stores/{store_id}/assertions/{authorization_model_id}".replace(
27252725
"{store_id}", store_id
27262726
),
@@ -2887,7 +2887,7 @@ def write_authorization_model_with_http_info(self, body, **kwargs):
28872887
attributes=telemetry_attributes,
28882888
)
28892889

2890-
return self.api_client.call_api(
2890+
return self.api_client.request(
28912891
"/stores/{store_id}/authorization-models".replace("{store_id}", store_id),
28922892
"POST",
28932893
path_params,

test/api/open_fga_api_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ async def test_500_error(self, mock_request):
12751275

12761276
configuration = self.configuration
12771277
configuration.store_id = store_id
1278-
configuration.retry_params.max_retry = 0
1278+
configuration.retry_params.max_retries = 0
12791279

12801280
async with openfga_sdk.ApiClient(configuration) as api_client:
12811281

test/client/client_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@
709709
# "page_size": 50,
710710
# "continuation_token": "eyJwayI6IkxBVEVTVF9OU0NPTkZJR19hdXRoMHN0b3JlIiwic2siOiIxem1qbXF3MWZLZExTcUoyN01MdTdqTjh0cWgifQ==",
711711
# "consistency": ConsistencyPreference.MINIMIZE_LATENCY,
712-
# "retry_params": RetryParams(max_retry=3, min_wait_in_ms=1000),
712+
# "retry_params": RetryParams(max_retries=3, min_wait_in_ms=1000),
713713
# },
714714
# )
715715
# self.assertIsInstance(api_response, ReadResponse)

0 commit comments

Comments
 (0)