Skip to content

Commit

Permalink
feat: support start_time parameter on read_changes (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
ewanharris authored Dec 18, 2024
2 parents 99f45c7 + e56a36f commit 7af8409
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ...
Expand Down
4 changes: 3 additions & 1 deletion docs/OpenFgaApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
8 changes: 7 additions & 1 deletion openfga_sdk/api/open_fga_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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", {}))

Expand Down
1 change: 1 addition & 0 deletions openfga_sdk/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
10 changes: 9 additions & 1 deletion openfga_sdk/client/models/read_changes_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@ 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):
"""
Return type
"""
return self._type

@property
def start_time(self):
"""
Return startTime
"""
return self._startTime
2 changes: 2 additions & 0 deletions openfga_sdk/models/error_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -141,6 +142,7 @@ class ErrorCode:
INVALID_AUTHORIZATION_MODEL,
UNSUPPORTED_SCHEMA_VERSION,
CANCELLED,
INVALID_START_TIME,
]

"""
Expand Down
1 change: 1 addition & 0 deletions openfga_sdk/sync/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
8 changes: 7 additions & 1 deletion openfga_sdk/sync/open_fga_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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", {}))

Expand Down
6 changes: 5 additions & 1 deletion test/api/open_fga_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion test/client/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
)

Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion test/sync/client/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
)

Expand All @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion test/sync/open_fga_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down

0 comments on commit 7af8409

Please sign in to comment.