Skip to content

Commit

Permalink
feat: add support for specifying consistency parameter (#70)
Browse files Browse the repository at this point in the history
<!-- Thanks for opening a PR! Here are some quick tips:
If this is your first time contributing, [read our Contributing
Guidelines](https://github.com/openfga/.github/blob/main/CONTRIBUTING.md)
to learn how to create an acceptable PR for this repo.
By submitting a PR to this repository, you agree to the terms within the
[OpenFGA Code of
Conduct](https://github.com/openfga/.github/blob/main/CODE_OF_CONDUCT.md)

If your PR is under active development, please submit it as a "draft".
Once it's ready, open it up for review.
-->

<!-- Provide a brief summary of the changes -->

Adds support for specifying the consistency parameter.

## Description
<!-- Provide a detailed description of the changes -->

Supports the ability to specify the consistency parameter for those
endpoints that accept it (read, check, list users, list objects, and
expand).

Note that a change to `JsonStringEnumMemberConverter` is also required
to support the new enum `UNSPECIFIED` along with its `EnumMember` value
(also `UNSPECIFIED`). Otherwise, there are errors when attempting to add
the same key twice to the dictionary.

In addition to the included unit tests, manual testing was also done
using the example application to verify that the enum changes work as
expected, and that the consistency parameter is being sent.

## References
<!-- Provide a list of any applicable references here (GitHub Issue,
[OpenFGA RFC](https://github.com/openfga/rfcs), other PRs, etc..) -->

## Review Checklist
- [ ] I have clicked on ["allow edits by
maintainers"](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork).
- [ ] I have added documentation for new/changed functionality in this
PR or in a PR to [openfga.dev](https://github.com/openfga/openfga.dev)
[Provide a link to any relevant PRs in the references section above]
- [ ] The correct base branch is being used, if not `main`
- [ ] I have added tests to validate that the change in functionality is
working as expected
  • Loading branch information
jimmyjames authored Aug 23, 2024
2 parents 5e08694 + fe663b4 commit f020bc6
Show file tree
Hide file tree
Showing 28 changed files with 392 additions and 40 deletions.
6 changes: 6 additions & 0 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ docs/Computed.md
docs/Condition.md
docs/ConditionMetadata.md
docs/ConditionParamTypeRef.md
docs/ConsistencyPreference.md
docs/ContextualTupleKeys.md
docs/CreateStoreRequest.md
docs/CreateStoreResponse.md
Expand Down Expand Up @@ -118,14 +119,18 @@ src/OpenFga.Sdk/Client/Model/ClientBatchCheckOptions.cs
src/OpenFga.Sdk/Client/Model/ClientBatchCheckResponse.cs
src/OpenFga.Sdk/Client/Model/ClientCheckOptions.cs
src/OpenFga.Sdk/Client/Model/ClientCheckRequest.cs
src/OpenFga.Sdk/Client/Model/ClientConsistencyOptions.cs
src/OpenFga.Sdk/Client/Model/ClientCreateStoreOptions.cs
src/OpenFga.Sdk/Client/Model/ClientCreateStoreRequest.cs
src/OpenFga.Sdk/Client/Model/ClientExpandOptions.cs
src/OpenFga.Sdk/Client/Model/ClientExpandRequest.cs
src/OpenFga.Sdk/Client/Model/ClientListObjectsOptions.cs
src/OpenFga.Sdk/Client/Model/ClientListObjectsRequest.cs
src/OpenFga.Sdk/Client/Model/ClientListRelationsOptions.cs
src/OpenFga.Sdk/Client/Model/ClientListRelationsRequest.cs
src/OpenFga.Sdk/Client/Model/ClientListRelationsResponse.cs
src/OpenFga.Sdk/Client/Model/ClientListStoresOptions.cs
src/OpenFga.Sdk/Client/Model/ClientListUsersOptions.cs
src/OpenFga.Sdk/Client/Model/ClientListUsersRequest.cs
src/OpenFga.Sdk/Client/Model/ClientPaginationOptions.cs
src/OpenFga.Sdk/Client/Model/ClientReadAssertionsOptions.cs
Expand Down Expand Up @@ -176,6 +181,7 @@ src/OpenFga.Sdk/Model/Computed.cs
src/OpenFga.Sdk/Model/Condition.cs
src/OpenFga.Sdk/Model/ConditionMetadata.cs
src/OpenFga.Sdk/Model/ConditionParamTypeRef.cs
src/OpenFga.Sdk/Model/ConsistencyPreference.cs
src/OpenFga.Sdk/Model/ContextualTupleKeys.cs
src/OpenFga.Sdk/Model/CreateStoreRequest.cs
src/OpenFga.Sdk/Model/CreateStoreResponse.cs
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ namespace Example {
| [**GetStore**](docs/OpenFgaApi.md#getstore) | **GET** /stores/{store_id} | Get a store |
| [**ListObjects**](docs/OpenFgaApi.md#listobjects) | **POST** /stores/{store_id}/list-objects | List all objects of the given type that the user has a relation with |
| [**ListStores**](docs/OpenFgaApi.md#liststores) | **GET** /stores | List all stores |
| [**ListUsers**](docs/OpenFgaApi.md#listusers) | **POST** /stores/{store_id}/list-users | [EXPERIMENTAL] List the users matching the provided filter who have a certain relation to a particular type. |
| [**ListUsers**](docs/OpenFgaApi.md#listusers) | **POST** /stores/{store_id}/list-users | List the users matching the provided filter who have a certain relation to a particular type. |
| [**Read**](docs/OpenFgaApi.md#read) | **POST** /stores/{store_id}/read | Get tuples from the store that matches a query, without following userset rewrite rules |
| [**ReadAssertions**](docs/OpenFgaApi.md#readassertions) | **GET** /stores/{store_id}/assertions/{authorization_model_id} | Read assertions for an authorization model ID |
| [**ReadAuthorizationModel**](docs/OpenFgaApi.md#readauthorizationmodel) | **GET** /stores/{store_id}/authorization-models/{id} | Return a particular version of an authorization model |
Expand All @@ -858,6 +858,7 @@ namespace Example {
- [Model.Condition](docs/Condition.md)
- [Model.ConditionMetadata](docs/ConditionMetadata.md)
- [Model.ConditionParamTypeRef](docs/ConditionParamTypeRef.md)
- [Model.ConsistencyPreference](docs/ConsistencyPreference.md)
- [Model.ContextualTupleKeys](docs/ContextualTupleKeys.md)
- [Model.CreateStoreRequest](docs/CreateStoreRequest.md)
- [Model.CreateStoreResponse](docs/CreateStoreResponse.md)
Expand Down
1 change: 1 addition & 0 deletions docs/CheckRequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Name | Type | Description | Notes
**AuthorizationModelId** | **string** | | [optional]
**Trace** | **bool** | Defaults to false. Making it true has performance implications. | [optional] [readonly]
**Context** | **Object** | Additional request context that will be used to evaluate any ABAC conditions encountered in the query evaluation. | [optional]
**Consistency** | **ConsistencyPreference** | | [optional]

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

10 changes: 10 additions & 0 deletions docs/ConsistencyPreference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# OpenFga.Sdk.Model.ConsistencyPreference
- UNSPECIFIED: Default if not set. Behavior will be the same as MINIMIZE_LATENCY - MINIMIZE_LATENCY: Minimize latency at the potential expense of lower consistency. - HIGHER_CONSISTENCY: Prefer higher consistency, at the potential expense of increased latency.

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------

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

1 change: 1 addition & 0 deletions docs/ExpandRequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**TupleKey** | [**ExpandRequestTupleKey**](ExpandRequestTupleKey.md) | |
**AuthorizationModelId** | **string** | | [optional]
**Consistency** | **ConsistencyPreference** | | [optional]

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

1 change: 1 addition & 0 deletions docs/ListObjectsRequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Name | Type | Description | Notes
**User** | **string** | |
**ContextualTuples** | [**ContextualTupleKeys**](ContextualTupleKeys.md) | | [optional]
**Context** | **Object** | Additional request context that will be used to evaluate any ABAC conditions encountered in the query evaluation. | [optional]
**Consistency** | **ConsistencyPreference** | | [optional]

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

1 change: 1 addition & 0 deletions docs/ListUsersRequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Name | Type | Description | Notes
**UserFilters** | [**List&lt;UserTypeFilter&gt;**](UserTypeFilter.md) | The type of results returned. Only accepts exactly one value. |
**ContextualTuples** | [**List&lt;TupleKey&gt;**](TupleKey.md) | | [optional]
**Context** | **Object** | Additional request context that will be used to evaluate any ABAC conditions encountered in the query evaluation. | [optional]
**Consistency** | **ConsistencyPreference** | | [optional]

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

8 changes: 4 additions & 4 deletions docs/OpenFgaApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Method | HTTP request | Description
[**GetStore**](OpenFgaApi.md#getstore) | **GET** /stores/{store_id} | Get a store
[**ListObjects**](OpenFgaApi.md#listobjects) | **POST** /stores/{store_id}/list-objects | List all objects of the given type that the user has a relation with
[**ListStores**](OpenFgaApi.md#liststores) | **GET** /stores | List all stores
[**ListUsers**](OpenFgaApi.md#listusers) | **POST** /stores/{store_id}/list-users | [EXPERIMENTAL] List the users matching the provided filter who have a certain relation to a particular type.
[**ListUsers**](OpenFgaApi.md#listusers) | **POST** /stores/{store_id}/list-users | List the users matching the provided filter who have a certain relation to a particular type.
[**Read**](OpenFgaApi.md#read) | **POST** /stores/{store_id}/read | Get tuples from the store that matches a query, without following userset rewrite rules
[**ReadAssertions**](OpenFgaApi.md#readassertions) | **GET** /stores/{store_id}/assertions/{authorization_model_id} | Read assertions for an authorization model ID
[**ReadAuthorizationModel**](OpenFgaApi.md#readauthorizationmodel) | **GET** /stores/{store_id}/authorization-models/{id} | Return a particular version of an authorization model
Expand Down Expand Up @@ -579,9 +579,9 @@ Name | Type | Description | Notes
# **ListUsers**
> ListUsersResponse ListUsers (ListUsersRequest body)
[EXPERIMENTAL] List the users matching the provided filter who have a certain relation to a particular type.
List the users matching the provided filter who have a certain relation to a particular type.

The ListUsers API returns a list of all the users of a specific type that have a relation to a given object. This API is available in an experimental capacity and can be enabled with the `- -experimentals enable-list-users` flag. To arrive at a result, the API uses: an authorization model, explicit tuples written through the Write API, contextual tuples present in the request, and implicit tuples that exist by virtue of applying set theory (such as `document:2021-budget#viewer@document:2021-budget#viewer`; the set of users who are viewers of `document:2021-budget` are the set of users who are the viewers of `document:2021-budget`). An `authorization_model_id` may be specified in the body. If it is not specified, the latest authorization model ID will be used. It is strongly recommended to specify authorization model id for better performance. You may also specify `contextual_tuples` that will be treated as regular tuples. Each of these tuples may have an associated `condition`. You may also provide a `context` object that will be used to evaluate the conditioned tuples in the system. It is strongly recommended to provide a value for all the input parameters of all the conditions, to ensure that all tuples be evaluated correctly. The response will contain the related users in an array in the \"users\" field of the response. These results may include specific objects, usersets or type-bound public access. Each of these types of results is encoded in its own type and not represented as a string.In cases where a type-bound public acces result is returned (e.g. `user:*`), it cannot be inferred that all subjects of that type have a relation to the object; it is possible that negations exist and checks should still be queried on individual subjects to ensure access to that document.The number of users in the response array will be limited by the execution timeout specified in the flag OPENFGA_LIST_USERS_DEADLINE and by the upper bound specified in the flag OPENFGA_LIST_USERS_MAX_RESULTS, whichever is hit first. The returned users will not be sorted, and therefore two identical calls may yield different sets of users.
The ListUsers API returns a list of all the users of a specific type that have a relation to a given object. To arrive at a result, the API uses: an authorization model, explicit tuples written through the Write API, contextual tuples present in the request, and implicit tuples that exist by virtue of applying set theory (such as `document:2021-budget#viewer@document:2021-budget#viewer`; the set of users who are viewers of `document:2021-budget` are the set of users who are the viewers of `document:2021-budget`). An `authorization_model_id` may be specified in the body. If it is not specified, the latest authorization model ID will be used. It is strongly recommended to specify authorization model id for better performance. You may also specify `contextual_tuples` that will be treated as regular tuples. Each of these tuples may have an associated `condition`. You may also provide a `context` object that will be used to evaluate the conditioned tuples in the system. It is strongly recommended to provide a value for all the input parameters of all the conditions, to ensure that all tuples be evaluated correctly. The response will contain the related users in an array in the \"users\" field of the response. These results may include specific objects, usersets or type-bound public access. Each of these types of results is encoded in its own type and not represented as a string.In cases where a type-bound public acces result is returned (e.g. `user:*`), it cannot be inferred that all subjects of that type have a relation to the object; it is possible that negations exist and checks should still be queried on individual subjects to ensure access to that document.The number of users in the response array will be limited by the execution timeout specified in the flag OPENFGA_LIST_USERS_DEADLINE and by the upper bound specified in the flag OPENFGA_LIST_USERS_MAX_RESULTS, whichever is hit first. The returned users will not be sorted, and therefore two identical calls may yield different sets of users.

### Example
```csharp
Expand Down Expand Up @@ -610,7 +610,7 @@ namespace Example
try
{
// [EXPERIMENTAL] List the users matching the provided filter who have a certain relation to a particular type.
// List the users matching the provided filter who have a certain relation to a particular type.
ListUsersResponse response = await openFgaApi.ListUsers(body);
Debug.WriteLine(response);
}
Expand Down
1 change: 1 addition & 0 deletions docs/ReadRequest.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Name | Type | Description | Notes
**TupleKey** | [**ReadRequestTupleKey**](ReadRequestTupleKey.md) | | [optional]
**PageSize** | **int** | | [optional]
**ContinuationToken** | **string** | | [optional]
**Consistency** | **ConsistencyPreference** | | [optional]

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

Loading

0 comments on commit f020bc6

Please sign in to comment.