Skip to content

Commit 28353fa

Browse files
committed
feat(openfgaapi): add BatchCheck API
1 parent 01c6a05 commit 28353fa

17 files changed

Lines changed: 1380 additions & 0 deletions

.openapi-generator/FILES

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ docs/Assertion.md
1919
docs/AssertionTupleKey.md
2020
docs/AuthErrorCode.md
2121
docs/AuthorizationModel.md
22+
docs/BatchCheckItem.md
23+
docs/BatchCheckRequest.md
24+
docs/BatchCheckResponse.md
25+
docs/BatchCheckSingleResult.md
26+
docs/CheckError.md
2227
docs/CheckRequest.md
2328
docs/CheckRequestTupleKey.md
2429
docs/CheckResponse.md
@@ -119,8 +124,12 @@ openfga_sdk/client/client.py
119124
openfga_sdk/client/configuration.py
120125
openfga_sdk/client/models/__init__.py
121126
openfga_sdk/client/models/assertion.py
127+
openfga_sdk/client/models/batch_check_item.py
128+
openfga_sdk/client/models/batch_check_request.py
122129
openfga_sdk/client/models/batch_check_response.py
130+
openfga_sdk/client/models/batch_check_single_response.py
123131
openfga_sdk/client/models/check_request.py
132+
openfga_sdk/client/models/client_batch_check_response.py
124133
openfga_sdk/client/models/expand_request.py
125134
openfga_sdk/client/models/list_objects_request.py
126135
openfga_sdk/client/models/list_relations_request.py
@@ -142,6 +151,11 @@ openfga_sdk/models/assertion.py
142151
openfga_sdk/models/assertion_tuple_key.py
143152
openfga_sdk/models/auth_error_code.py
144153
openfga_sdk/models/authorization_model.py
154+
openfga_sdk/models/batch_check_item.py
155+
openfga_sdk/models/batch_check_request.py
156+
openfga_sdk/models/batch_check_response.py
157+
openfga_sdk/models/batch_check_single_result.py
158+
openfga_sdk/models/check_error.py
145159
openfga_sdk/models/check_request.py
146160
openfga_sdk/models/check_request_tuple_key.py
147161
openfga_sdk/models/check_response.py

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,7 @@ async def main():
10431043

10441044
Class | Method | HTTP request | Description
10451045
------------ | ------------- | ------------- | -------------
1046+
*OpenFgaApi* | [**batch_check**](https://github.com/openfga/python-sdk/blob/main/docs/OpenFgaApi.md#batch_check) | **POST** /stores/{store_id}/batch-check | Send a list of `check` operations in a single request
10461047
*OpenFgaApi* | [**check**](https://github.com/openfga/python-sdk/blob/main/docs/OpenFgaApi.md#check) | **POST** /stores/{store_id}/check | Check whether a user is authorized to access an object
10471048
*OpenFgaApi* | [**create_store**](https://github.com/openfga/python-sdk/blob/main/docs/OpenFgaApi.md#create_store) | **POST** /stores | Create a store
10481049
*OpenFgaApi* | [**delete_store**](https://github.com/openfga/python-sdk/blob/main/docs/OpenFgaApi.md#delete_store) | **DELETE** /stores/{store_id} | Delete a store
@@ -1072,6 +1073,11 @@ Class | Method | HTTP request | Description
10721073
- [AssertionTupleKey](https://github.com/openfga/python-sdk/blob/main/docs/AssertionTupleKey.md)
10731074
- [AuthErrorCode](https://github.com/openfga/python-sdk/blob/main/docs/AuthErrorCode.md)
10741075
- [AuthorizationModel](https://github.com/openfga/python-sdk/blob/main/docs/AuthorizationModel.md)
1076+
- [BatchCheckItem](https://github.com/openfga/python-sdk/blob/main/docs/BatchCheckItem.md)
1077+
- [BatchCheckRequest](https://github.com/openfga/python-sdk/blob/main/docs/BatchCheckRequest.md)
1078+
- [BatchCheckResponse](https://github.com/openfga/python-sdk/blob/main/docs/BatchCheckResponse.md)
1079+
- [BatchCheckSingleResult](https://github.com/openfga/python-sdk/blob/main/docs/BatchCheckSingleResult.md)
1080+
- [CheckError](https://github.com/openfga/python-sdk/blob/main/docs/CheckError.md)
10751081
- [CheckRequest](https://github.com/openfga/python-sdk/blob/main/docs/CheckRequest.md)
10761082
- [CheckRequestTupleKey](https://github.com/openfga/python-sdk/blob/main/docs/CheckRequestTupleKey.md)
10771083
- [CheckResponse](https://github.com/openfga/python-sdk/blob/main/docs/CheckResponse.md)

docs/BatchCheckItem.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# BatchCheckItem
2+
3+
4+
## Properties
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
**tuple_key** | [**CheckRequestTupleKey**](CheckRequestTupleKey.md) | |
8+
**contextual_tuples** | [**ContextualTupleKeys**](ContextualTupleKeys.md) | | [optional]
9+
**context** | **object** | | [optional]
10+
**correlation_id** | **str** | correlation_id must be a string containing only letters, numbers, or hyphens, with length ≤ 36 characters. |
11+
12+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
13+
14+

docs/BatchCheckRequest.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# BatchCheckRequest
2+
3+
4+
## Properties
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
**checks** | [**list[BatchCheckItem]**](BatchCheckItem.md) | |
8+
**authorization_model_id** | **str** | | [optional]
9+
**consistency** | [**ConsistencyPreference**](ConsistencyPreference.md) | | [optional]
10+
11+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
12+
13+

docs/BatchCheckResponse.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# BatchCheckResponse
2+
3+
4+
## Properties
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
**result** | [**dict[str, BatchCheckSingleResult]**](BatchCheckSingleResult.md) | map keys are the correlation_id values from the BatchCheckItems in the request | [optional]
8+
9+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
10+
11+

docs/BatchCheckSingleResult.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# BatchCheckSingleResult
2+
3+
4+
## Properties
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
**allowed** | **bool** | | [optional]
8+
**error** | [**CheckError**](CheckError.md) | | [optional]
9+
10+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
11+
12+

docs/CheckError.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# CheckError
2+
3+
4+
## Properties
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
**input_error** | [**ErrorCode**](ErrorCode.md) | | [optional]
8+
**internal_error** | [**InternalErrorCode**](InternalErrorCode.md) | | [optional]
9+
**message** | **str** | | [optional]
10+
11+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
12+
13+

docs/OpenFgaApi.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ All URIs are relative to *api.fga.example*
44

55
Method | HTTP request | Description
66
------------- | ------------- | -------------
7+
[**batch_check**](OpenFgaApi.md#batch_check) | **POST** /stores/{store_id}/batch-check | Send a list of `check` operations in a single request
78
[**check**](OpenFgaApi.md#check) | **POST** /stores/{store_id}/check | Check whether a user is authorized to access an object
89
[**create_store**](OpenFgaApi.md#create_store) | **POST** /stores | Create a store
910
[**delete_store**](OpenFgaApi.md#delete_store) | **DELETE** /stores/{store_id} | Delete a store
@@ -22,6 +23,90 @@ Method | HTTP request | Description
2223
[**write_authorization_model**](OpenFgaApi.md#write_authorization_model) | **POST** /stores/{store_id}/authorization-models | Create a new authorization model
2324

2425

26+
# **batch_check**
27+
> BatchCheckResponse batch_check(body)
28+
29+
Send a list of `check` operations in a single request
30+
31+
The `BatchCheck` API functions nearly identically to `Check`, but instead of checking a single user-object relationship BatchCheck accepts a list of relationships to check and returns a map containing `BatchCheckItem` response for each check it received. An associated `correlation_id` is required for each check in the batch. This ID is used to correlate a check to the appropriate response. It is a string consisting of only alphanumeric characters or hyphens with a maximum length of 36 characters. This `correlation_id` is used to map the result of each check to the item which was checked, so it must be unique for each item in the batch. We recommend using a UUID or ULID as the `correlation_id`, but you can use whatever unique identifier you need as long as it matches this regex pattern: `^[\\w\\d-]{1,36}$` For more details on how `Check` functions, see the docs for `/check`. ### Examples #### A BatchCheckRequest ```json { \"checks\": [ { \"tuple_key\": { \"object\": \"document:2021-budget\" \"relation\": \"reader\", \"user\": \"user:anne\", }, \"contextual_tuples\": {...} \"context\": {} \"correlation_id\": \"01JA8PM3QM7VBPGB8KMPK8SBD5\" }, { \"tuple_key\": { \"object\": \"document:2021-budget\" \"relation\": \"reader\", \"user\": \"user:bob\", }, \"contextual_tuples\": {...} \"context\": {} \"correlation_id\": \"01JA8PMM6A90NV5ET0F28CYSZQ\" } ] } ``` Below is a possible response to the above request. Note that the result map's keys are the `correlation_id` values from the checked items in the request: ```json { \"result\": { \"01JA8PMM6A90NV5ET0F28CYSZQ\": { \"allowed\": false, \"error\": {\"message\": \"\"} }, \"01JA8PM3QM7VBPGB8KMPK8SBD5\": { \"allowed\": true, \"error\": {\"message\": \"\"} } } ```
32+
33+
### Example
34+
35+
```python
36+
import time
37+
import openfga_sdk
38+
from openfga_sdk.rest import ApiException
39+
from pprint import pprint
40+
# To configure the configuration
41+
# host is mandatory
42+
# api_scheme is optional and default to https
43+
# store_id is mandatory
44+
# See configuration.py for a list of all supported configuration parameters.
45+
configuration = openfga_sdk.Configuration(
46+
scheme = "https",
47+
api_host = "api.fga.example",
48+
store_id = 'YOUR_STORE_ID',
49+
)
50+
51+
52+
# When authenticating via the API TOKEN method
53+
credentials = Credentials(method='api_token', configuration=CredentialConfiguration(api_token='TOKEN1'))
54+
configuration = openfga_sdk.Configuration(
55+
scheme = "https",
56+
api_host = "api.fga.example",
57+
store_id = 'YOUR_STORE_ID',
58+
credentials = credentials
59+
)
60+
61+
# Enter a context with an instance of the API client
62+
async with openfga_sdk.ApiClient(configuration) as api_client:
63+
# Create an instance of the API class
64+
api_instance = openfga_sdk.OpenFgaApi(api_client)
65+
body = openfga_sdk.BatchCheckRequest() # BatchCheckRequest |
66+
67+
try:
68+
# Send a list of `check` operations in a single request
69+
api_response = await api_instance.api_instance.batch_check(body)
70+
pprint(api_response)
71+
except ApiException as e:
72+
print("Exception when calling OpenFgaApi->batch_check: %s\n" % e)
73+
await api_client.close()
74+
```
75+
76+
77+
### Parameters
78+
79+
Name | Type | Description | Notes
80+
------------- | ------------- | ------------- | -------------
81+
**body** | [**BatchCheckRequest**](BatchCheckRequest.md)| |
82+
83+
### Return type
84+
85+
[**BatchCheckResponse**](BatchCheckResponse.md)
86+
87+
### Authorization
88+
89+
No authorization required
90+
91+
### HTTP request headers
92+
93+
- **Content-Type**: application/json
94+
- **Accept**: application/json
95+
96+
### HTTP response details
97+
| Status code | Description | Response headers |
98+
|-------------|-------------|------------------|
99+
**200** | A successful response. | - |
100+
**400** | Request failed due to invalid input. | - |
101+
**401** | Not authenticated. | - |
102+
**403** | Forbidden. | - |
103+
**404** | Request failed due to incorrect path. | - |
104+
**409** | Request was aborted due a transaction conflict. | - |
105+
**422** | Request timed out due to excessive request throttling. | - |
106+
**500** | Request failed due to internal server error. | - |
107+
108+
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
109+
25110
# **check**
26111
> CheckResponse check(body)
27112

openfga_sdk/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
from openfga_sdk.models.assertion_tuple_key import AssertionTupleKey
3232
from openfga_sdk.models.auth_error_code import AuthErrorCode
3333
from openfga_sdk.models.authorization_model import AuthorizationModel
34+
from openfga_sdk.models.batch_check_item import BatchCheckItem
35+
from openfga_sdk.models.batch_check_request import BatchCheckRequest
36+
from openfga_sdk.models.batch_check_response import BatchCheckResponse
37+
from openfga_sdk.models.batch_check_single_result import BatchCheckSingleResult
38+
from openfga_sdk.models.check_error import CheckError
3439
from openfga_sdk.models.check_request import CheckRequest
3540
from openfga_sdk.models.check_request_tuple_key import CheckRequestTupleKey
3641
from openfga_sdk.models.check_response import CheckResponse

0 commit comments

Comments
 (0)