From e56a36f6023f1cdf55a5ac8f8e5eb6f756e01041 Mon Sep 17 00:00:00 2001 From: Ryan Quinn Date: Wed, 18 Dec 2024 10:41:07 +0000 Subject: [PATCH] feat: support start_time parameter on read_changes --- CHANGELOG.md | 1 + README.md | 2 +- docs/OpenFgaApi.md | 4 +++- openfga_sdk/api/open_fga_api.py | 8 +++++++- openfga_sdk/client/client.py | 1 + openfga_sdk/client/models/read_changes_request.py | 10 +++++++++- openfga_sdk/models/error_code.py | 2 ++ openfga_sdk/sync/client/client.py | 1 + openfga_sdk/sync/open_fga_api.py | 8 +++++++- test/api/open_fga_api_test.py | 6 +++++- test/client/client_test.py | 3 ++- test/sync/client/client_test.py | 3 ++- test/sync/open_fga_api_test.py | 6 +++++- 13 files changed, 46 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7034c3a..a298846 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [Unreleased](https://github.com/openfga/python-sdk/compare/v0.8.1...HEAD) - feat: remove client-side validation - thanks @GMorris-professional (#155) +- feat: add support for `start_time` parameter in `ReadChanges` endpoint (#156) - fix: change default max retry limit to 3 from 15 - thanks @ovindu-a (#155) ## v0.8.1 diff --git a/README.md b/README.md index a6ba2a1..60185d8 100644 --- a/README.md +++ b/README.md @@ -485,7 +485,7 @@ options = { "page_size": "25", "continuation_token": "eyJwayI6IkxBVEVTVF9OU0NPTkZJR19hdXRoMHN0b3JlIiwic2siOiIxem1qbXF3MWZLZExTcUoyN01MdTdqTjh0cWgifQ==" } -body = ClientReadChangesRequest(type="document") +body = ClientReadChangesRequest(type="document", start_time="2022-01-01T00:00:00Z") response = await fga_client.read_changes(body, options) # response.continuation_token = ... diff --git a/docs/OpenFgaApi.md b/docs/OpenFgaApi.md index 578bd18..0c542fd 100644 --- a/docs/OpenFgaApi.md +++ b/docs/OpenFgaApi.md @@ -1066,10 +1066,11 @@ async with openfga_sdk.ApiClient(configuration) as api_client: type = 'type_example' # str | (optional) page_size = 56 # int | (optional) continuation_token = 'continuation_token_example' # str | (optional) + start_time = '2013-10-20T19:20:30+01:00' # datetime | Start date and time of changes to read. Format: ISO 8601 timestamp (e.g., 2022-01-01T00:00:00Z) If a continuation_token is provided along side start_time, the continuation_token will take precedence over start_time. (optional) try: # Return a list of all the tuple changes - api_response = await api_instance.api_instance.read_changes(type=type, page_size=page_size, continuation_token=continuation_token) + api_response = await api_instance.api_instance.read_changes(type=type, page_size=page_size, continuation_token=continuation_token, start_time=start_time) pprint(api_response) except ApiException as e: print("Exception when calling OpenFgaApi->read_changes: %s\n" % e) @@ -1084,6 +1085,7 @@ Name | Type | Description | Notes **type** | **str**| | [optional] **page_size** | **int**| | [optional] **continuation_token** | **str**| | [optional] + **start_time** | **datetime**| Start date and time of changes to read. Format: ISO 8601 timestamp (e.g., 2022-01-01T00:00:00Z) If a continuation_token is provided along side start_time, the continuation_token will take precedence over start_time. | [optional] ### Return type diff --git a/openfga_sdk/api/open_fga_api.py b/openfga_sdk/api/open_fga_api.py index c4ddaaa..6c88b91 100644 --- a/openfga_sdk/api/open_fga_api.py +++ b/openfga_sdk/api/open_fga_api.py @@ -2051,6 +2051,8 @@ async def read_changes(self, **kwargs): :type page_size: int, optional :param continuation_token:(optional) :type continuation_token: str, optional + :param start_time: Start date and time of changes to read. Format: ISO 8601 timestamp (e.g., 2022-01-01T00:00:00Z) If a continuation_token is provided along side start_time, the continuation_token will take precedence over start_time.(optional) + :type start_time: datetime, optional :param async_req: Whether to execute the request asynchronously. :type async_req: bool, optional :param _preload_content: if False, the urllib3.HTTPResponse object will @@ -2082,6 +2084,8 @@ async def read_changes_with_http_info(self, **kwargs): :type page_size: int, optional :param continuation_token:(optional) :type continuation_token: str, optional + :param start_time: Start date and time of changes to read. Format: ISO 8601 timestamp (e.g., 2022-01-01T00:00:00Z) If a continuation_token is provided along side start_time, the continuation_token will take precedence over start_time.(optional) + :type start_time: datetime, optional :param async_req: Whether to execute the request asynchronously. :type async_req: bool, optional :param _return_http_data_only: response data without head status code @@ -2109,7 +2113,7 @@ async def read_changes_with_http_info(self, **kwargs): local_var_params = locals() - all_params = ["type", "page_size", "continuation_token"] + all_params = ["type", "page_size", "continuation_token", "start_time"] all_params.extend( [ "async_req", @@ -2153,6 +2157,8 @@ async def read_changes_with_http_info(self, **kwargs): query_params.append( ("continuation_token", local_var_params["continuation_token"]) ) + if local_var_params.get("start_time") is not None: + query_params.append(("start_time", local_var_params["start_time"])) header_params = dict(local_var_params.get("_headers", {})) diff --git a/openfga_sdk/client/client.py b/openfga_sdk/client/client.py index 014dc18..974e511 100644 --- a/openfga_sdk/client/client.py +++ b/openfga_sdk/client/client.py @@ -347,6 +347,7 @@ async def read_changes( """ kwargs = options_to_kwargs(options) kwargs["type"] = body.type + kwargs["start_time"] = body.start_time api_response = await self._api.read_changes( **kwargs, ) diff --git a/openfga_sdk/client/models/read_changes_request.py b/openfga_sdk/client/models/read_changes_request.py index 8eba2a6..9b99aeb 100644 --- a/openfga_sdk/client/models/read_changes_request.py +++ b/openfga_sdk/client/models/read_changes_request.py @@ -16,8 +16,9 @@ class ClientReadChangesRequest: ClientReadChangesRequest encapsulates the parameters required to read changes """ - def __init__(self, type: str): + def __init__(self, type: str, start_time: str = None): self._type = type + self._startTime = start_time @property def type(self): @@ -25,3 +26,10 @@ def type(self): Return type """ return self._type + + @property + def start_time(self): + """ + Return startTime + """ + return self._startTime diff --git a/openfga_sdk/models/error_code.py b/openfga_sdk/models/error_code.py index 45da702..b67ebaa 100644 --- a/openfga_sdk/models/error_code.py +++ b/openfga_sdk/models/error_code.py @@ -90,6 +90,7 @@ class ErrorCode: INVALID_AUTHORIZATION_MODEL = "invalid_authorization_model" UNSUPPORTED_SCHEMA_VERSION = "unsupported_schema_version" CANCELLED = "cancelled" + INVALID_START_TIME = "invalid_start_time" allowable_values = [ NO_ERROR, @@ -141,6 +142,7 @@ class ErrorCode: INVALID_AUTHORIZATION_MODEL, UNSUPPORTED_SCHEMA_VERSION, CANCELLED, + INVALID_START_TIME, ] """ diff --git a/openfga_sdk/sync/client/client.py b/openfga_sdk/sync/client/client.py index 7151de5..ede0b8b 100644 --- a/openfga_sdk/sync/client/client.py +++ b/openfga_sdk/sync/client/client.py @@ -345,6 +345,7 @@ def read_changes( """ kwargs = options_to_kwargs(options) kwargs["type"] = body.type + kwargs["start_time"] = body.start_time api_response = self._api.read_changes( **kwargs, ) diff --git a/openfga_sdk/sync/open_fga_api.py b/openfga_sdk/sync/open_fga_api.py index b12230d..1a1910c 100644 --- a/openfga_sdk/sync/open_fga_api.py +++ b/openfga_sdk/sync/open_fga_api.py @@ -2047,6 +2047,8 @@ def read_changes(self, **kwargs): :type page_size: int, optional :param continuation_token:(optional) :type continuation_token: str, optional + :param start_time: Start date and time of changes to read. Format: ISO 8601 timestamp (e.g., 2022-01-01T00:00:00Z) If a continuation_token is provided along side start_time, the continuation_token will take precedence over start_time.(optional) + :type start_time: datetime, optional :param async_req: Whether to execute the request asynchronously. :type async_req: bool, optional :param _preload_content: if False, the urllib3.HTTPResponse object will @@ -2078,6 +2080,8 @@ def read_changes_with_http_info(self, **kwargs): :type page_size: int, optional :param continuation_token:(optional) :type continuation_token: str, optional + :param start_time: Start date and time of changes to read. Format: ISO 8601 timestamp (e.g., 2022-01-01T00:00:00Z) If a continuation_token is provided along side start_time, the continuation_token will take precedence over start_time.(optional) + :type start_time: datetime, optional :param async_req: Whether to execute the request asynchronously. :type async_req: bool, optional :param _return_http_data_only: response data without head status code @@ -2105,7 +2109,7 @@ def read_changes_with_http_info(self, **kwargs): local_var_params = locals() - all_params = ["type", "page_size", "continuation_token"] + all_params = ["type", "page_size", "continuation_token", "start_time"] all_params.extend( [ "async_req", @@ -2149,6 +2153,8 @@ def read_changes_with_http_info(self, **kwargs): query_params.append( ("continuation_token", local_var_params["continuation_token"]) ) + if local_var_params.get("start_time") is not None: + query_params.append(("start_time", local_var_params["start_time"])) header_params = dict(local_var_params.get("_headers", {})) diff --git a/test/api/open_fga_api_test.py b/test/api/open_fga_api_test.py index b8c64fb..1f70b12 100644 --- a/test/api/open_fga_api_test.py +++ b/test/api/open_fga_api_test.py @@ -783,7 +783,10 @@ async def test_read_changes(self, mock_request): # Return a particular version of an authorization model api_response = await api_instance.read_changes( - page_size=1, continuation_token="abcdefg", type="document" + page_size=1, + continuation_token="abcdefg", + start_time="2022-01-01T00:00:00+00:00", + type="document", ) self.assertIsInstance(api_response, ReadChangesResponse) changes = TupleChange( @@ -808,6 +811,7 @@ async def test_read_changes(self, mock_request): ("type", "document"), ("page_size", 1), ("continuation_token", "abcdefg"), + ("start_time", "2022-01-01T00:00:00+00:00"), ], _preload_content=ANY, _request_timeout=None, diff --git a/test/client/client_test.py b/test/client/client_test.py index 48fec42..5609b54 100644 --- a/test/client/client_test.py +++ b/test/client/client_test.py @@ -675,7 +675,7 @@ async def test_read_changes(self, mock_request): # Return a particular version of an authorization model api_response = await api_client.read_changes( - ClientReadChangesRequest("document"), + ClientReadChangesRequest("document", "2022-01-01T00:00:00+00:00"), options={"page_size": 1, "continuation_token": "abcdefg"}, ) @@ -702,6 +702,7 @@ async def test_read_changes(self, mock_request): ("type", "document"), ("page_size", 1), ("continuation_token", "abcdefg"), + ("start_time", "2022-01-01T00:00:00+00:00"), ], _preload_content=ANY, _request_timeout=None, diff --git a/test/sync/client/client_test.py b/test/sync/client/client_test.py index c8b8835..938a2aa 100644 --- a/test/sync/client/client_test.py +++ b/test/sync/client/client_test.py @@ -674,7 +674,7 @@ def test_read_changes(self, mock_request): # Return a particular version of an authorization model api_response = api_client.read_changes( - ClientReadChangesRequest("document"), + ClientReadChangesRequest("document", "2022-01-01T00:00:00+00:00"), options={"page_size": 1, "continuation_token": "abcdefg"}, ) @@ -701,6 +701,7 @@ def test_read_changes(self, mock_request): ("type", "document"), ("page_size", 1), ("continuation_token", "abcdefg"), + ("start_time", "2022-01-01T00:00:00+00:00"), ], _preload_content=ANY, _request_timeout=None, diff --git a/test/sync/open_fga_api_test.py b/test/sync/open_fga_api_test.py index 8ab4ff0..e8e0358 100644 --- a/test/sync/open_fga_api_test.py +++ b/test/sync/open_fga_api_test.py @@ -787,7 +787,10 @@ async def test_read_changes(self, mock_request): # Return a particular version of an authorization model api_response = api_instance.read_changes( - page_size=1, continuation_token="abcdefg", type="document" + page_size=1, + continuation_token="abcdefg", + start_time="2022-01-01T00:00:00+00:00", + type="document", ) self.assertIsInstance(api_response, ReadChangesResponse) changes = TupleChange( @@ -812,6 +815,7 @@ async def test_read_changes(self, mock_request): ("type", "document"), ("page_size", 1), ("continuation_token", "abcdefg"), + ("start_time", "2022-01-01T00:00:00+00:00"), ], _preload_content=ANY, _request_timeout=None,