Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release(v0.3.4): with conditions support #61

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ docs/WriteRequestDeletes.md
docs/WriteRequestWrites.md
example/Makefile
example/README.md
example/example1/auth-model.json
example/example1/example1.py
example/example1/requirements.txt
example/example1/setup.cfg
Expand Down
29 changes: 13 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,7 @@ options = {
"authorization_model_id": "01GXSA8YR785C4FYS3C0RTG7B1"
}

response = await fga_client.read_authorization_model({
# You can rely on the model id set in the configuration or override it for this specific request
"authorization_model_id": "01GXSA8YR785C4FYS3C0RTG7B1"
})
response = await fga_client.read_authorization_model(options)
# response.authorization_model = AuthorizationModel(id='01GXSA8YR785C4FYS3C0RTG7B1', schema_version = '1.1', type_definitions=type_definitions[...])
```

Expand Down Expand Up @@ -429,7 +426,7 @@ options = {
"page_size": "25",
"continuation_token": "eyJwayI6IkxBVEVTVF9OU0NPTkZJR19hdXRoMHN0b3JlIiwic2siOiIxem1qbXF3MWZLZExTcUoyN01MdTdqTjh0cWgifQ=="
}
body = ClientReadChangesRequest(type='document')
body = ClientReadChangesRequest(type="document")

response = await fga_client.read_changes(body, options)
# response.continuation_token = ...
Expand Down Expand Up @@ -565,6 +562,11 @@ body = ClientWriteRequest(
user="user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation="viewer",
object="document:roadmap",
),
ClientTuple(
user="user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation="viewer",
object="document:budget",
condition=RelationshipCondition(
name='ViewCountLessThan200',
context=dict(
Expand All @@ -573,11 +575,6 @@ body = ClientWriteRequest(
),
),
),
ClientTuple(
user="user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation="viewer",
object="document:budget",
),
],
deletes=[
ClientTuple(
Expand Down Expand Up @@ -641,7 +638,7 @@ body = [ClientCheckRequest(
],
context=dict(
ViewCount=100
),
)
), ClientCheckRequest(
user="user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relation="admin",
Expand Down Expand Up @@ -675,9 +672,9 @@ response = await fga_client.batch_check(body, options)
# relation: "editor",
# object: "document:roadmap"
# }],
# context=dict(
# ViewCount=100
# ),
# context=dict(
# ViewCount=100
# )
# }
# }, {
# allowed: false,
Expand Down Expand Up @@ -798,7 +795,7 @@ Read assertions for a particular authorization model.

[API Documentation](https://openfga.dev/api/service#/Assertions/Read%20Assertions)

```csharp
```python
options = {
# You can rely on the model id set in the configuration or override it for this specific request
"authorization_model_id": "01GXSA8YR785C4FYS3C0RTG7B1"
Expand All @@ -812,7 +809,7 @@ Update the assertions for a particular authorization model.

[API Documentation](https://openfga.dev/api/service#/Assertions/Write%20Assertions)

```csharp
```python
options = {
# You can rely on the model id set in the configuration or override it for this specific request
"authorization_model_id": "01GXSA8YR785C4FYS3C0RTG7B1"
Expand Down
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.3
0.3.4
7 changes: 5 additions & 2 deletions example/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ all: run
project_name=example1
openfga_version=latest

run:
python example1/example1.py
setup:
cd "${project_name}/" && pip3 install -r requirements.txt && cd -

run: setup
python3 "${project_name}/${project_name}.py"

run-openfga:
docker pull docker.io/openfga/openfga:${openfga_version} && \
Expand Down
2 changes: 1 addition & 1 deletion example/example1/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ attrs==23.1.0
frozenlist==1.4.1
idna==3.6
multidict==6.0.4
openfga-sdk==0.3.2
openfga-sdk==0.3.4
python-dateutil==2.8.2
six==1.16.0
urllib3==2.1.0
Expand Down
2 changes: 1 addition & 1 deletion openfga_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT.
"""

__version__ = "0.3.3"
__version__ = "0.3.4"

from openfga_sdk.client.client import OpenFgaClient
from openfga_sdk.client.configuration import ClientConfiguration
Expand Down
2 changes: 1 addition & 1 deletion openfga_sdk/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from openfga_sdk.exceptions import ApiValueError, ApiException, FgaValidationException, RateLimitExceededError


DEFAULT_USER_AGENT = 'openfga-sdk python/0.3.3'
DEFAULT_USER_AGENT = 'openfga-sdk python/0.3.4'


def random_time(loop_count, min_wait_in_ms):
Expand Down
4 changes: 2 additions & 2 deletions openfga_sdk/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,8 @@ async def list_relations(self, body: ClientListRelationsRequest, options: dict[s
options = set_heading_if_not_set(options, CLIENT_METHOD_HEADER, "ListRelations")
options = set_heading_if_not_set(options, CLIENT_BULK_REQUEST_ID_HEADER, str(uuid.uuid4()))

request_body = [construct_check_request(
user=body.user, relation=i, object=body.object, contextual_tuples=body.contextual_tuples, context=body.context) for i in body.relations]
request_body = [construct_check_request(user=body.user, relation=i, object=body.object,
contextual_tuples=body.contextual_tuples, context=body.context) for i in body.relations]
result = await self.batch_check(request_body, options)
# need to filter with the allowed response
result_iterator = filter(_check_allowed, result)
Expand Down
1 change: 1 addition & 0 deletions openfga_sdk/client/models/list_relations_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT.
"""

from openfga_sdk.client.models.tuple import ClientTuple

from typing import List
Expand Down
2 changes: 1 addition & 1 deletion openfga_sdk/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def to_debug_report(self):
"OS: {env}\n"\
"Python Version: {pyversion}\n"\
"Version of the API: 0.1\n"\
"SDK Package Version: 0.3.3".\
"SDK Package Version: 0.3.4".\
format(env=sys.platform, pyversion=sys.version)

def get_host_settings(self):
Expand Down
2 changes: 1 addition & 1 deletion openfga_sdk/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def _obtain_token(self, client):
'grant_type': "client_credentials",
}
headers = urllib3.response.HTTPHeaderDict(
{'Accept': 'application/json', 'Content-Type': 'application/json', 'User-Agent': 'openfga-sdk (python) 0.3.3'})
{'Accept': 'application/json', 'Content-Type': 'application/json', 'User-Agent': 'openfga-sdk (python) 0.3.4'})
raw_response = await client.POST(token_url, headers=headers, body=body)
if 200 <= raw_response.status <= 299:
try:
Expand Down
2 changes: 1 addition & 1 deletion openfga_sdk/sync/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from openfga_sdk.exceptions import ApiValueError, ApiException, FgaValidationException, RateLimitExceededError


DEFAULT_USER_AGENT = 'openfga-sdk python/0.3.3'
DEFAULT_USER_AGENT = 'openfga-sdk python/0.3.4'


def random_time(loop_count, min_wait_in_ms):
Expand Down
4 changes: 2 additions & 2 deletions openfga_sdk/sync/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,8 @@ def list_relations(self, body: ClientListRelationsRequest, options: dict[str, st
options = set_heading_if_not_set(options, CLIENT_METHOD_HEADER, "ListRelations")
options = set_heading_if_not_set(options, CLIENT_BULK_REQUEST_ID_HEADER, str(uuid.uuid4()))

request_body = [construct_check_request(
user=body.user, relation=i, object=body.object, contextual_tuples=body.contextual_tuples) for i in body.relations]
request_body = [construct_check_request(user=body.user, relation=i, object=body.object,
contextual_tuples=body.contextual_tuples, context=body.context) for i in body.relations]
result = self.batch_check(request_body, options)
# need to filter with the allowed response
result_iterator = filter(_check_allowed, result)
Expand Down
2 changes: 1 addition & 1 deletion openfga_sdk/sync/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _obtain_token(self, client):
'grant_type': "client_credentials",
}
headers = urllib3.response.HTTPHeaderDict(
{'Accept': 'application/json', 'Content-Type': 'application/json', 'User-Agent': 'openfga-sdk (python) 0.3.3'})
{'Accept': 'application/json', 'Content-Type': 'application/json', 'User-Agent': 'openfga-sdk (python) 0.3.4'})
raw_response = client.POST(token_url, headers=headers, body=body)
if 200 <= raw_response.status <= 299:
try:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from setuptools import setup, find_packages # noqa: H301

NAME = "openfga-sdk"
VERSION = "0.3.3"
VERSION = "0.3.4"
# To install the library, run the following
#
# python setup.py install
Expand Down
2 changes: 1 addition & 1 deletion test/test_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async def test_get_authentication_obtain_client_credentials(self, mock_request):
self.assertGreaterEqual(client._access_expiry_time,
current_time + timedelta(seconds=int(120)))
expected_header = urllib3.response.HTTPHeaderDict(
{'Accept': 'application/json', 'Content-Type': 'application/json', 'User-Agent': 'openfga-sdk (python) 0.3.3'})
{'Accept': 'application/json', 'Content-Type': 'application/json', 'User-Agent': 'openfga-sdk (python) 0.3.4'})
mock_request.assert_called_once_with(
'POST',
'https://www.testme.com/oauth/token',
Expand Down
2 changes: 1 addition & 1 deletion test/test_oauth2_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_get_authentication_obtain_client_credentials(self, mock_request):
self.assertGreaterEqual(client._access_expiry_time,
current_time + timedelta(seconds=int(120)))
expected_header = urllib3.response.HTTPHeaderDict(
{'Accept': 'application/json', 'Content-Type': 'application/json', 'User-Agent': 'openfga-sdk (python) 0.3.3'})
{'Accept': 'application/json', 'Content-Type': 'application/json', 'User-Agent': 'openfga-sdk (python) 0.3.4'})
mock_request.assert_called_once_with(
'POST',
'https://www.testme.com/oauth/token',
Expand Down
4 changes: 2 additions & 2 deletions test/test_open_fga_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ async def test_check_api_token(self, mock_request):
self.assertTrue(api_response.allowed)
# Make sure the API was called with the right data
expected_headers = urllib3.response.HTTPHeaderDict(
{'Accept': 'application/json', 'Content-Type': 'application/json', 'User-Agent': 'openfga-sdk python/0.3.3', 'Authorization': 'Bearer TOKEN1'})
{'Accept': 'application/json', 'Content-Type': 'application/json', 'User-Agent': 'openfga-sdk python/0.3.4', 'Authorization': 'Bearer TOKEN1'})
mock_request.assert_called_once_with(
'POST',
'http://api.fga.example/stores/01H0H015178Y2V4CX10C2KGHF4/check',
Expand Down Expand Up @@ -1223,7 +1223,7 @@ async def test_check_custom_header(self, mock_request):
self.assertTrue(api_response.allowed)
# Make sure the API was called with the right data
expected_headers = urllib3.response.HTTPHeaderDict(
{'Accept': 'application/json', 'Content-Type': 'application/json', 'User-Agent': 'openfga-sdk python/0.3.3', 'Custom Header': 'custom value'})
{'Accept': 'application/json', 'Content-Type': 'application/json', 'User-Agent': 'openfga-sdk python/0.3.4', 'Custom Header': 'custom value'})
mock_request.assert_called_once_with(
'POST',
'http://api.fga.example/stores/01H0H015178Y2V4CX10C2KGHF4/check',
Expand Down
4 changes: 2 additions & 2 deletions test/test_open_fga_api_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ async def test_check_api_token(self, mock_request):
self.assertTrue(api_response.allowed)
# Make sure the API was called with the right data
expected_headers = urllib3.response.HTTPHeaderDict(
{'Accept': 'application/json', 'Content-Type': 'application/json', 'User-Agent': 'openfga-sdk python/0.3.3', 'Authorization': 'Bearer TOKEN1'})
{'Accept': 'application/json', 'Content-Type': 'application/json', 'User-Agent': 'openfga-sdk python/0.3.4', 'Authorization': 'Bearer TOKEN1'})
mock_request.assert_called_once_with(
'POST',
'http://api.fga.example/stores/01H0H015178Y2V4CX10C2KGHF4/check',
Expand Down Expand Up @@ -1224,7 +1224,7 @@ async def test_check_custom_header(self, mock_request):
self.assertTrue(api_response.allowed)
# Make sure the API was called with the right data
expected_headers = urllib3.response.HTTPHeaderDict(
{'Accept': 'application/json', 'Content-Type': 'application/json', 'User-Agent': 'openfga-sdk python/0.3.3', 'Custom Header': 'custom value'})
{'Accept': 'application/json', 'Content-Type': 'application/json', 'User-Agent': 'openfga-sdk python/0.3.4', 'Custom Header': 'custom value'})
mock_request.assert_called_once_with(
'POST',
'http://api.fga.example/stores/01H0H015178Y2V4CX10C2KGHF4/check',
Expand Down