Skip to content

Commit

Permalink
Merge pull request #80 from openfga/feat/list-users
Browse files Browse the repository at this point in the history
feat: support list users
  • Loading branch information
ewanharris authored May 2, 2024
2 parents 9b94a4d + 6b38a68 commit c6f9926
Show file tree
Hide file tree
Showing 32 changed files with 2,633 additions and 22 deletions.
23 changes: 23 additions & 0 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,22 @@ docs/ErrorCode.md
docs/ExpandRequest.md
docs/ExpandRequestTupleKey.md
docs/ExpandResponse.md
docs/FgaObject.md
docs/GetStoreResponse.md
docs/InternalErrorCode.md
docs/InternalErrorMessageResponse.md
docs/Leaf.md
docs/ListObjectsRequest.md
docs/ListObjectsResponse.md
docs/ListStoresResponse.md
docs/ListUsersRequest.md
docs/ListUsersResponse.md
docs/Metadata.md
docs/Node.md
docs/Nodes.md
docs/NotFoundErrorCode.md
docs/NullValue.md
docs/ObjectOrUserset.md
docs/ObjectRelation.md
docs/OpenFgaApi.md
docs/PathUnknownErrorMessageResponse.md
Expand All @@ -72,11 +76,17 @@ docs/TupleOperation.md
docs/TupleToUserset.md
docs/TypeDefinition.md
docs/TypeName.md
docs/TypedWildcard.md
docs/UnprocessableContentErrorCode.md
docs/UnprocessableContentMessageResponse.md
docs/User.md
docs/UserTypeFilter.md
docs/Users.md
docs/Userset.md
docs/UsersetTree.md
docs/UsersetTreeDifference.md
docs/UsersetTreeTupleToUserset.md
docs/UsersetUser.md
docs/Usersets.md
docs/ValidationErrorMessageResponse.md
docs/WriteAssertionsRequest.md
Expand Down Expand Up @@ -127,6 +137,8 @@ src/main/java/dev/openfga/sdk/api/client/model/ClientListObjectsResponse.java
src/main/java/dev/openfga/sdk/api/client/model/ClientListRelationsRequest.java
src/main/java/dev/openfga/sdk/api/client/model/ClientListRelationsResponse.java
src/main/java/dev/openfga/sdk/api/client/model/ClientListStoresResponse.java
src/main/java/dev/openfga/sdk/api/client/model/ClientListUsersRequest.java
src/main/java/dev/openfga/sdk/api/client/model/ClientListUsersResponse.java
src/main/java/dev/openfga/sdk/api/client/model/ClientReadAssertionsResponse.java
src/main/java/dev/openfga/sdk/api/client/model/ClientReadAuthorizationModelResponse.java
src/main/java/dev/openfga/sdk/api/client/model/ClientReadAuthorizationModelsResponse.java
Expand Down Expand Up @@ -156,6 +168,7 @@ src/main/java/dev/openfga/sdk/api/configuration/ClientGetStoreOptions.java
src/main/java/dev/openfga/sdk/api/configuration/ClientListObjectsOptions.java
src/main/java/dev/openfga/sdk/api/configuration/ClientListRelationsOptions.java
src/main/java/dev/openfga/sdk/api/configuration/ClientListStoresOptions.java
src/main/java/dev/openfga/sdk/api/configuration/ClientListUsersOptions.java
src/main/java/dev/openfga/sdk/api/configuration/ClientReadAssertionsOptions.java
src/main/java/dev/openfga/sdk/api/configuration/ClientReadAuthorizationModelOptions.java
src/main/java/dev/openfga/sdk/api/configuration/ClientReadAuthorizationModelsOptions.java
Expand Down Expand Up @@ -191,18 +204,22 @@ src/main/java/dev/openfga/sdk/api/model/ErrorCode.java
src/main/java/dev/openfga/sdk/api/model/ExpandRequest.java
src/main/java/dev/openfga/sdk/api/model/ExpandRequestTupleKey.java
src/main/java/dev/openfga/sdk/api/model/ExpandResponse.java
src/main/java/dev/openfga/sdk/api/model/FgaObject.java
src/main/java/dev/openfga/sdk/api/model/GetStoreResponse.java
src/main/java/dev/openfga/sdk/api/model/InternalErrorCode.java
src/main/java/dev/openfga/sdk/api/model/InternalErrorMessageResponse.java
src/main/java/dev/openfga/sdk/api/model/Leaf.java
src/main/java/dev/openfga/sdk/api/model/ListObjectsRequest.java
src/main/java/dev/openfga/sdk/api/model/ListObjectsResponse.java
src/main/java/dev/openfga/sdk/api/model/ListStoresResponse.java
src/main/java/dev/openfga/sdk/api/model/ListUsersRequest.java
src/main/java/dev/openfga/sdk/api/model/ListUsersResponse.java
src/main/java/dev/openfga/sdk/api/model/Metadata.java
src/main/java/dev/openfga/sdk/api/model/Node.java
src/main/java/dev/openfga/sdk/api/model/Nodes.java
src/main/java/dev/openfga/sdk/api/model/NotFoundErrorCode.java
src/main/java/dev/openfga/sdk/api/model/NullValue.java
src/main/java/dev/openfga/sdk/api/model/ObjectOrUserset.java
src/main/java/dev/openfga/sdk/api/model/ObjectRelation.java
src/main/java/dev/openfga/sdk/api/model/PathUnknownErrorMessageResponse.java
src/main/java/dev/openfga/sdk/api/model/ReadAssertionsResponse.java
Expand All @@ -226,11 +243,17 @@ src/main/java/dev/openfga/sdk/api/model/TupleOperation.java
src/main/java/dev/openfga/sdk/api/model/TupleToUserset.java
src/main/java/dev/openfga/sdk/api/model/TypeDefinition.java
src/main/java/dev/openfga/sdk/api/model/TypeName.java
src/main/java/dev/openfga/sdk/api/model/TypedWildcard.java
src/main/java/dev/openfga/sdk/api/model/UnprocessableContentErrorCode.java
src/main/java/dev/openfga/sdk/api/model/UnprocessableContentMessageResponse.java
src/main/java/dev/openfga/sdk/api/model/User.java
src/main/java/dev/openfga/sdk/api/model/UserTypeFilter.java
src/main/java/dev/openfga/sdk/api/model/Users.java
src/main/java/dev/openfga/sdk/api/model/Userset.java
src/main/java/dev/openfga/sdk/api/model/UsersetTree.java
src/main/java/dev/openfga/sdk/api/model/UsersetTreeDifference.java
src/main/java/dev/openfga/sdk/api/model/UsersetTreeTupleToUserset.java
src/main/java/dev/openfga/sdk/api/model/UsersetUser.java
src/main/java/dev/openfga/sdk/api/model/Usersets.java
src/main/java/dev/openfga/sdk/api/model/ValidationErrorMessageResponse.java
src/main/java/dev/openfga/sdk/api/model/WriteAssertionsRequest.java
Expand Down
75 changes: 70 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ This is an autogenerated Java SDK for OpenFGA. It provides a wrapper around the
- [Expand](#expand)
- [List Objects](#list-objects)
- [List Relations](#list-relations)
- [List Users](#list-users)
- [Assertions](#assertions)
- [Read Assertions](#read-assertions)
- [Write Assertions](#write-assertions)
Expand Down Expand Up @@ -136,7 +137,7 @@ public class Example {
var config = new ClientConfiguration()
.apiUrl(System.getenv("FGA_API_URL")) // If not specified, will default to "http://localhost:8080"
.storeId(System.getenv("FGA_STORE_ID")) // Not required when calling createStore() or listStores()
.authorizationModelId(System.getenv("FGA_AUTHORIZATION_MODEL_ID")); // Optional, can be overridden per request
.authorizationModelId(System.getenv("FGA_MODEL_ID")); // Optional, can be overridden per request

var fgaClient = new OpenFgaClient(config);
var response = fgaClient.readAuthorizationModels().get();
Expand All @@ -159,7 +160,7 @@ public class Example {
var config = new ClientConfiguration()
.apiUrl(System.getenv("FGA_API_URL")) // If not specified, will default to "http://localhost:8080"
.storeId(System.getenv("FGA_STORE_ID")) // Not required when calling createStore() or listStores()
.authorizationModelId(System.getenv("FGA_AUTHORIZATION_MODEL_ID")) // Optional, can be overridden per request
.authorizationModelId(System.getenv("FGA_MODEL_ID")) // Optional, can be overridden per request
.credentials(new Credentials(
new ApiToken(System.getenv("FGA_API_TOKEN")) // will be passed as the "Authorization: Bearer ${ApiToken}" request header
));
Expand All @@ -185,7 +186,7 @@ public class Example {
var config = new ClientConfiguration()
.apiUrl(System.getenv("FGA_API_URL")) // If not specified, will default to "http://localhost:8080"
.storeId(System.getenv("FGA_STORE_ID")) // Not required when calling createStore() or listStores()
.authorizationModelId(System.getenv("FGA_AUTHORIZATION_MODEL_ID")) // Optional, can be overridden per request
.authorizationModelId(System.getenv("FGA_MODEL_ID")) // Optional, can be overridden per request
.credentials(new Credentials(
new ClientCredentials()
.apiTokenIssuer(System.getenv("FGA_API_TOKEN_ISSUER"))
Expand Down Expand Up @@ -215,7 +216,7 @@ public class Example {
var config = new ClientConfiguration()
.apiUrl(System.getenv("FGA_API_URL")) // If not specified, will default to "http://localhost:8080"
.storeId(System.getenv("FGA_STORE_ID")) // Not required when calling createStore() or listStores()
.authorizationModelId(System.getenv("FGA_AUTHORIZATION_MODEL_ID")) // Optional, can be overridden per request
.authorizationModelId(System.getenv("FGA_MODEL_ID")) // Optional, can be overridden per request
.credentials(new Credentials(
new ClientCredentials()
.apiTokenIssuer(System.getenv("FGA_API_TOKEN_ISSUER"))
Expand Down Expand Up @@ -765,6 +766,49 @@ var response = fgaClient.listRelations(request, options).get();
// response.getRelations() = ["can_view", "can_edit"]
```

##### List Users

List the users who have a certain relation to a particular type.

[API Documentation](https://openfga.dev/api/service#/Relationship%20Queries/ListUsers)

```java
// Only a single filter is allowed for the time being
var userFilters = new ArrayList<UserTypeFilter>() {
{
add(new UserTypeFilter().type("user"));
// user filters can also be of the form
// add(new UserTypeFilter().type("team").relation("member"));
}
};

var request = new ClientListUsersRequest()
._object(new FgaObject().type("document").id("roadmap"))
.relation("can_read")
.userFilters(userFilters)
.context(Map.of("view_count", 100))
.contextualTupleKeys(List.of(
new ClientTupleKey()
.user("user:81684243-9356-4421-8fbf-a4f8d36aa31b")
.relation("editor")
._object("folder:product"),
new ClientTupleKey()
.user("folder:product")
.relation("parent")
._object("document:roadmap")
));

var options = new ClientListUsersOptions()
.additionalHeaders(Map.of("Some-Http-Header", "Some value"))
// You can rely on the model id set in the configuration or override it for this specific request
.authorizationModelId("01GXSA8YR785C4FYS3C0RTG7B1");

var response = fgaClient.listUsers(request, options).get();

// response.getUsers() = [{object: {type: "user", id: "81684243-9356-4421-8fbf-a4f8d36aa31b"}}, {userset: { type: "user" }}, ...]
// response.getExcludedUsers = [ {object: {type: "user", id: "4a455e27-d15a-4434-82e0-136f9c2aa4cf"}}, ... ]
```

#### Assertions

##### Read Assertions
Expand Down Expand Up @@ -823,7 +867,7 @@ public class Example {
var config = new ClientConfiguration()
.apiUrl(System.getenv("FGA_API_URL")) // If not specified, will default to "http://localhost:8080"
.storeId(System.getenv("FGA_STORE_ID")) // Not required when calling createStore() or listStores()
.authorizationModelId(System.getenv("FGA_AUTHORIZATION_MODEL_ID")) // Optional, can be overridden per request
.authorizationModelId(System.getenv("FGA_MODEL_ID")) // Optional, can be overridden per request
.maxRetries(3) // retry up to 3 times on API requests
.minimumRetryDelay(250); // wait a minimum of 250 milliseconds between requests

Expand All @@ -844,6 +888,7 @@ public class 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 | 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 Down Expand Up @@ -898,6 +943,8 @@ public class Example {

- [ExpandResponse](https://github.com/openfga/java-sdk/blob/main/docs/ExpandResponse.md)

- [FgaObject](https://github.com/openfga/java-sdk/blob/main/docs/FgaObject.md)

- [GetStoreResponse](https://github.com/openfga/java-sdk/blob/main/docs/GetStoreResponse.md)

- [InternalErrorCode](https://github.com/openfga/java-sdk/blob/main/docs/InternalErrorCode.md)
Expand All @@ -912,6 +959,10 @@ public class Example {

- [ListStoresResponse](https://github.com/openfga/java-sdk/blob/main/docs/ListStoresResponse.md)

- [ListUsersRequest](https://github.com/openfga/java-sdk/blob/main/docs/ListUsersRequest.md)

- [ListUsersResponse](https://github.com/openfga/java-sdk/blob/main/docs/ListUsersResponse.md)

- [Metadata](https://github.com/openfga/java-sdk/blob/main/docs/Metadata.md)

- [Node](https://github.com/openfga/java-sdk/blob/main/docs/Node.md)
Expand All @@ -922,6 +973,8 @@ public class Example {

- [NullValue](https://github.com/openfga/java-sdk/blob/main/docs/NullValue.md)

- [ObjectOrUserset](https://github.com/openfga/java-sdk/blob/main/docs/ObjectOrUserset.md)

- [ObjectRelation](https://github.com/openfga/java-sdk/blob/main/docs/ObjectRelation.md)

- [PathUnknownErrorMessageResponse](https://github.com/openfga/java-sdk/blob/main/docs/PathUnknownErrorMessageResponse.md)
Expand Down Expand Up @@ -968,6 +1021,16 @@ public class Example {

- [TypeName](https://github.com/openfga/java-sdk/blob/main/docs/TypeName.md)

- [TypedWildcard](https://github.com/openfga/java-sdk/blob/main/docs/TypedWildcard.md)

- [UnprocessableContentErrorCode](https://github.com/openfga/java-sdk/blob/main/docs/UnprocessableContentErrorCode.md)

- [UnprocessableContentMessageResponse](https://github.com/openfga/java-sdk/blob/main/docs/UnprocessableContentMessageResponse.md)

- [User](https://github.com/openfga/java-sdk/blob/main/docs/User.md)

- [UserTypeFilter](https://github.com/openfga/java-sdk/blob/main/docs/UserTypeFilter.md)

- [Users](https://github.com/openfga/java-sdk/blob/main/docs/Users.md)

- [Userset](https://github.com/openfga/java-sdk/blob/main/docs/Userset.md)
Expand All @@ -978,6 +1041,8 @@ public class Example {

- [UsersetTreeTupleToUserset](https://github.com/openfga/java-sdk/blob/main/docs/UsersetTreeTupleToUserset.md)

- [UsersetUser](https://github.com/openfga/java-sdk/blob/main/docs/UsersetUser.md)

- [Usersets](https://github.com/openfga/java-sdk/blob/main/docs/Usersets.md)

- [ValidationErrorMessageResponse](https://github.com/openfga/java-sdk/blob/main/docs/ValidationErrorMessageResponse.md)
Expand Down
15 changes: 15 additions & 0 deletions docs/FgaObject.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@


# FgaObject

Object represents an OpenFGA Object. An Object is composed of a type and identifier (e.g. 'document:1') See https://openfga.dev/docs/concepts#what-is-an-object

## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**type** | **String** | | |
|**id** | **String** | | |



18 changes: 18 additions & 0 deletions docs/ListUsersRequest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@


# ListUsersRequest


## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**authorizationModelId** | **String** | | [optional] |
|**_object** | [**FgaObject**](FgaObject.md) | | |
|**relation** | **String** | | |
|**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] |



14 changes: 14 additions & 0 deletions docs/ListUsersResponse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@


# ListUsersResponse


## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**users** | [**List&lt;User&gt;**](User.md) | | |
|**excludedUsers** | [**List&lt;ObjectOrUserset&gt;**](ObjectOrUserset.md) | | |



14 changes: 14 additions & 0 deletions docs/ObjectOrUserset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@


# ObjectOrUserset


## Properties

| Name | Type | Description | Notes |
|------------ | ------------- | ------------- | -------------|
|**_object** | [**FgaObject**](FgaObject.md) | | [optional] |
|**userset** | [**UsersetUser**](UsersetUser.md) | | [optional] |



Loading

0 comments on commit c6f9926

Please sign in to comment.