Skip to content

Commit 9f92f78

Browse files
committed
feat: support contextual tuples in assertions
This does not add support to the OpenFGAClient, only the OpenFGAAPI
1 parent 7e447cf commit 9f92f78

3 files changed

Lines changed: 84 additions & 7 deletions

File tree

docs/Assertion.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
77
**tuple_key** | [**AssertionTupleKey**](AssertionTupleKey.md) | |
88
**expectation** | **bool** | |
9+
**contextual_tuples** | [**list[TupleKey]**](TupleKey.md) | | [optional]
10+
**context** | **object** | Additional request context that will be used to evaluate any ABAC conditions encountered in the query evaluation. | [optional]
911

1012
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
1113

docs/OpenFgaApi.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ No authorization required
766766
767767
Read assertions for an authorization model ID
768768

769-
The ReadAssertions API will return, for a given authorization model id, all the assertions stored for it. An assertion is an object that contains a tuple key, and the expectation of whether a call to the Check API of that tuple key will return true or false.
769+
The ReadAssertions API will return, for a given authorization model id, all the assertions stored for it.
770770

771771
### Example
772772

@@ -1187,7 +1187,7 @@ No authorization required
11871187
11881188
Upsert assertions for an authorization model ID
11891189

1190-
The WriteAssertions API will upsert new assertions for an authorization model id, or overwrite the existing ones. An assertion is an object that contains a tuple key, and the expectation of whether a call to the Check API of that tuple key will return true or false.
1190+
The WriteAssertions API will upsert new assertions for an authorization model id, or overwrite the existing ones. An assertion is an object that contains a tuple key, the expectation of whether a call to the Check API of that tuple key will return true or false, and optionally a list of contextual tuples.
11911191

11921192
### Example
11931193

openfga_sdk/models/assertion.py

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,45 @@ class Assertion:
3333
attribute_map (dict): The key is attribute name
3434
and the value is json key in definition.
3535
"""
36-
openapi_types = {"tuple_key": "AssertionTupleKey", "expectation": "bool"}
37-
38-
attribute_map = {"tuple_key": "tuple_key", "expectation": "expectation"}
39-
40-
def __init__(self, tuple_key=None, expectation=None, local_vars_configuration=None):
36+
openapi_types = {
37+
"tuple_key": "AssertionTupleKey",
38+
"expectation": "bool",
39+
"contextual_tuples": "list[TupleKey]",
40+
"context": "object",
41+
}
42+
43+
attribute_map = {
44+
"tuple_key": "tuple_key",
45+
"expectation": "expectation",
46+
"contextual_tuples": "contextual_tuples",
47+
"context": "context",
48+
}
49+
50+
def __init__(
51+
self,
52+
tuple_key=None,
53+
expectation=None,
54+
contextual_tuples=None,
55+
context=None,
56+
local_vars_configuration=None,
57+
):
4158
"""Assertion - a model defined in OpenAPI"""
4259
if local_vars_configuration is None:
4360
local_vars_configuration = Configuration.get_default_copy()
4461
self.local_vars_configuration = local_vars_configuration
4562

4663
self._tuple_key = None
4764
self._expectation = None
65+
self._contextual_tuples = None
66+
self._context = None
4867
self.discriminator = None
4968

5069
self.tuple_key = tuple_key
5170
self.expectation = expectation
71+
if contextual_tuples is not None:
72+
self.contextual_tuples = contextual_tuples
73+
if context is not None:
74+
self.context = context
5275

5376
@property
5477
def tuple_key(self):
@@ -96,6 +119,58 @@ def expectation(self, expectation):
96119

97120
self._expectation = expectation
98121

122+
@property
123+
def contextual_tuples(self):
124+
"""Gets the contextual_tuples of this Assertion.
125+
126+
127+
:return: The contextual_tuples of this Assertion.
128+
:rtype: list[TupleKey]
129+
"""
130+
return self._contextual_tuples
131+
132+
@contextual_tuples.setter
133+
def contextual_tuples(self, contextual_tuples):
134+
"""Sets the contextual_tuples of this Assertion.
135+
136+
137+
:param contextual_tuples: The contextual_tuples of this Assertion.
138+
:type contextual_tuples: list[TupleKey]
139+
"""
140+
if (
141+
self.local_vars_configuration.client_side_validation
142+
and contextual_tuples is not None
143+
and len(contextual_tuples) > 20
144+
):
145+
raise ValueError(
146+
"Invalid value for `contextual_tuples`, number of items must be less than or equal to `20`"
147+
)
148+
149+
self._contextual_tuples = contextual_tuples
150+
151+
@property
152+
def context(self):
153+
"""Gets the context of this Assertion.
154+
155+
Additional request context that will be used to evaluate any ABAC conditions encountered in the query evaluation.
156+
157+
:return: The context of this Assertion.
158+
:rtype: object
159+
"""
160+
return self._context
161+
162+
@context.setter
163+
def context(self, context):
164+
"""Sets the context of this Assertion.
165+
166+
Additional request context that will be used to evaluate any ABAC conditions encountered in the query evaluation.
167+
168+
:param context: The context of this Assertion.
169+
:type context: object
170+
"""
171+
172+
self._context = context
173+
99174
def to_dict(self, serialize=False):
100175
"""Returns the model properties as a dict"""
101176
result = {}

0 commit comments

Comments
 (0)