-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d9cacf
commit aa94c70
Showing
10 changed files
with
512 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/dev/openfga/sdk/api/client/ListStoresOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* OpenFGA | ||
* A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar. | ||
* | ||
* The version of the OpenAPI document: 0.1 | ||
* Contact: [email protected] | ||
* | ||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). | ||
* https://openapi-generator.tech | ||
* Do not edit the class manually. | ||
*/ | ||
|
||
package dev.openfga.sdk.api.client; | ||
|
||
public class ListStoresOptions { | ||
private Integer pageSize; | ||
private String continuationToken; | ||
|
||
public ListStoresOptions pageSize(Integer pageSize) { | ||
this.pageSize = pageSize; | ||
return this; | ||
} | ||
|
||
public Integer getPageSize() { | ||
return pageSize; | ||
} | ||
|
||
public ListStoresOptions continuationToken(String continuationToken) { | ||
this.continuationToken = continuationToken; | ||
return this; | ||
} | ||
|
||
public String getContinuationToken() { | ||
return continuationToken; | ||
} | ||
} |
283 changes: 283 additions & 0 deletions
283
src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,283 @@ | ||
/* | ||
* OpenFGA | ||
* A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar. | ||
* | ||
* The version of the OpenAPI document: 0.1 | ||
* Contact: [email protected] | ||
* | ||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). | ||
* https://openapi-generator.tech | ||
* Do not edit the class manually. | ||
*/ | ||
|
||
package dev.openfga.sdk.api.client; | ||
|
||
import static dev.openfga.sdk.util.StringUtil.isNullOrWhitespace; | ||
|
||
import dev.openfga.sdk.api.*; | ||
import dev.openfga.sdk.api.configuration.*; | ||
import dev.openfga.sdk.api.model.*; | ||
import dev.openfga.sdk.errors.*; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class OpenFgaClient { | ||
private final ClientConfiguration configuration; | ||
private final OpenFgaApi api; | ||
|
||
private static final String CLIENT_BULK_REQUEST_ID_HEADER = "X-OpenFGA-Client-Bulk-Request-Id"; | ||
private static final String CLIENT_METHOD_HEADER = "X-OpenFGA-Client-Method"; | ||
private static final int DEFAULT_MAX_METHOD_PARALLEL_REQS = 10; | ||
|
||
public OpenFgaClient(ApiClient apiClient, ClientConfiguration configuration) throws FgaInvalidParameterException { | ||
this.configuration = configuration; | ||
this.api = new OpenFgaApi(apiClient, configuration); | ||
} | ||
|
||
/* *********** | ||
* Utilities * | ||
*************/ | ||
|
||
public void setStoreId(String storeId) { | ||
configuration.storeId(storeId); | ||
} | ||
|
||
public void setAuthorizationModelId(String authorizationModelId) { | ||
configuration.authorizationModelId(authorizationModelId); | ||
} | ||
|
||
/* ******** | ||
* Stores * | ||
**********/ | ||
|
||
/** | ||
* ListStores - Get a paginated list of stores. | ||
*/ | ||
public CompletableFuture<ListStoresResponse> listStores() throws FgaInvalidParameterException, ApiException { | ||
return api.listStores(null, null); | ||
} | ||
|
||
public CompletableFuture<ListStoresResponse> listStores(ListStoresOptions options) | ||
throws FgaInvalidParameterException, ApiException { | ||
return api.listStores(options.getPageSize(), options.getContinuationToken()); | ||
} | ||
|
||
/** | ||
* CreateStore - Initialize a store | ||
*/ | ||
public CompletableFuture<CreateStoreResponse> createStore(CreateStoreRequest request) | ||
throws FgaInvalidParameterException, ApiException { | ||
return api.createStore(request); | ||
} | ||
|
||
/** | ||
* GetStore - Get information about the current store. | ||
* | ||
* @throws FgaInvalidParameterException When the Store ID is null, empty, or whitespace | ||
*/ | ||
public CompletableFuture<GetStoreResponse> getStore() throws FgaInvalidParameterException, ApiException { | ||
String storeId = configuration.getStoreIdChecked(); | ||
return api.getStore(storeId); | ||
} | ||
|
||
/** | ||
* DeleteStore - Delete a store | ||
* | ||
* @throws FgaInvalidParameterException When the Store ID is null, empty, or whitespace | ||
*/ | ||
public CompletableFuture<Void> deleteStore() throws FgaInvalidParameterException, ApiException { | ||
String storeId = configuration.getStoreIdChecked(); | ||
return api.deleteStore(storeId); | ||
} | ||
|
||
/* ********************** | ||
* Authorization Models * | ||
************************/ | ||
|
||
/** | ||
* ReadAuthorizationModels - Read all authorization models | ||
* | ||
* @throws FgaInvalidParameterException When the Store ID is null, empty, or whitespace | ||
*/ | ||
public CompletableFuture<ReadAuthorizationModelsResponse> ReadAuthorizationModels( | ||
ReadAuthorizationModelsOptions options) throws FgaInvalidParameterException, ApiException { | ||
String storeId = configuration.getStoreIdChecked(); | ||
return api.readAuthorizationModels(storeId, options.getPageSize(), options.getContinuationToken()); | ||
} | ||
|
||
/** | ||
* WriteAuthorizationModel - Create a new version of the authorization model | ||
* | ||
* @throws FgaInvalidParameterException When the Store ID is null, empty, or whitespace | ||
*/ | ||
public CompletableFuture<WriteAuthorizationModelResponse> writeAuthorizationModel( | ||
WriteAuthorizationModelRequest request) throws FgaInvalidParameterException, ApiException { | ||
String storeId = configuration.getStoreIdChecked(); | ||
return api.writeAuthorizationModel(storeId, request); | ||
} | ||
|
||
/** | ||
* ReadAuthorizationModel - Read the current authorization model | ||
* | ||
* @throws FgaInvalidParameterException When either the Store ID or Authorization Model ID are null, empty, or whitespace | ||
*/ | ||
public CompletableFuture<ReadAuthorizationModelResponse> readAuthorizationModel() | ||
throws FgaInvalidParameterException, ApiException { | ||
String storeId = configuration.getStoreIdChecked(); | ||
String authorizationModelId = configuration.getAuthorizationModelIdChecked(); | ||
return api.readAuthorizationModel(storeId, authorizationModelId); | ||
} | ||
|
||
/** | ||
* ReadLatestAuthorizationModel - Read the latest authorization model for the current store | ||
* | ||
* @throws FgaInvalidParameterException When the Store ID is null, empty, or whitespace | ||
*/ | ||
public CompletableFuture<ReadAuthorizationModelResponse> readLatestAuthorizationModel() | ||
throws FgaInvalidParameterException, ApiException { | ||
String storeId = configuration.getStoreIdChecked(); | ||
return api.readAuthorizationModels(storeId, 1, null).thenApply(response -> new ReadAuthorizationModelResponse() | ||
.authorizationModel(response.getAuthorizationModels().get(0))); | ||
} | ||
|
||
/* ********************* | ||
* Relationship Tuples * | ||
***********************/ | ||
|
||
/** | ||
* Read Changes - Read the list of historical relationship tuple writes and deletes | ||
* | ||
* @throws FgaInvalidParameterException When the Store ID is null, empty, or whitespace | ||
*/ | ||
public CompletableFuture<ReadChangesResponse> ReadChanges(ReadChangesOptions options) | ||
throws FgaInvalidParameterException, ApiException { | ||
String storeId = configuration.getStoreIdChecked(); | ||
return api.readChanges(storeId, options.getType(), options.getPageSize(), options.getContinuationToken()); | ||
} | ||
|
||
/** | ||
* Read - Read tuples previously written to the store (does not evaluate) | ||
* | ||
* @throws FgaInvalidParameterException When the Store ID is null, empty, or whitespace | ||
*/ | ||
public CompletableFuture<ReadResponse> read(ReadRequest body) throws FgaInvalidParameterException, ApiException { | ||
String storeId = configuration.getStoreIdChecked(); | ||
return api.read(storeId, body); | ||
} | ||
|
||
/** | ||
* Write - Create or delete relationship tuples | ||
* | ||
* @throws FgaInvalidParameterException When the Store ID is null, empty, or whitespace | ||
*/ | ||
public CompletableFuture<Object> write(WriteRequest request) throws FgaInvalidParameterException, ApiException { | ||
String storeId = configuration.getStoreIdChecked(); | ||
return api.write(storeId, request); | ||
} | ||
|
||
/** | ||
* WriteTuples - Utility method to write tuples, wraps Write | ||
* | ||
* @throws FgaInvalidParameterException When the Store ID is null, empty, or whitespace | ||
*/ | ||
public CompletableFuture<Object> writeTuples(TupleKeys tupleKeys) | ||
throws FgaInvalidParameterException, ApiException { | ||
var request = new WriteRequest().writes(tupleKeys); | ||
String storeId = configuration.getStoreIdChecked(); | ||
String authorizationModelId = configuration.getAuthorizationModelId(); | ||
if (!isNullOrWhitespace(authorizationModelId)) { | ||
request.authorizationModelId(authorizationModelId); | ||
} | ||
return api.write(storeId, request); | ||
} | ||
|
||
/** | ||
* DeleteTuples - Utility method to delete tuples, wraps Write | ||
* | ||
* @throws FgaInvalidParameterException When the Store ID is null, empty, or whitespace | ||
*/ | ||
public CompletableFuture<Object> deleteTuples(TupleKeys tupleKeys) | ||
throws FgaInvalidParameterException, ApiException { | ||
var request = new WriteRequest().deletes(tupleKeys); | ||
String storeId = configuration.getStoreIdChecked(); | ||
String authorizationModelId = configuration.getAuthorizationModelId(); | ||
if (!isNullOrWhitespace(authorizationModelId)) { | ||
request.authorizationModelId(authorizationModelId); | ||
} | ||
return api.write(storeId, request); | ||
} | ||
|
||
/* ********************** | ||
* Relationship Queries * | ||
***********************/ | ||
|
||
/** | ||
* Check - Check if a user has a particular relation with an object (evaluates) | ||
* | ||
* @throws FgaInvalidParameterException When the Store ID is null, empty, or whitespace | ||
*/ | ||
public CompletableFuture<CheckResponse> check(CheckRequest request) | ||
throws FgaInvalidParameterException, ApiException { | ||
String storeId = configuration.getStoreIdChecked(); | ||
return api.check(storeId, request); | ||
} | ||
|
||
/* | ||
* BatchCheck - Run a set of checks (evaluates) | ||
*/ | ||
// TODO | ||
|
||
/** | ||
* Expand - Expands the relationships in userset tree format (evaluates) | ||
* | ||
* @throws FgaInvalidParameterException When the Store ID is null, empty, or whitespace | ||
*/ | ||
public CompletableFuture<ExpandResponse> expand(ExpandRequest request) | ||
throws FgaInvalidParameterException, ApiException { | ||
String storeId = configuration.getStoreIdChecked(); | ||
return api.expand(storeId, request); | ||
} | ||
|
||
/** | ||
* ListObjects - List the objects of a particular type that the user has a certain relation to (evaluates) | ||
* | ||
* @throws FgaInvalidParameterException When the Store ID is null, empty, or whitespace | ||
*/ | ||
public CompletableFuture<ListObjectsResponse> listObjects(ListObjectsRequest request) | ||
throws FgaInvalidParameterException, ApiException { | ||
String storeId = configuration.getStoreIdChecked(); | ||
return api.listObjects(storeId, request); | ||
} | ||
|
||
/* | ||
* ListRelations - List all the relations a user has with an object (evaluates) | ||
*/ | ||
// TODO | ||
|
||
/* ************ | ||
* Assertions * | ||
**************/ | ||
|
||
/** | ||
* ReadAssertions - Read assertions for a particular authorization model | ||
* | ||
* @throws FgaInvalidParameterException When either the Store ID or Authorization Model ID is null, empty, or whitespace | ||
*/ | ||
public CompletableFuture<ReadAssertionsResponse> readAssertions() | ||
throws FgaInvalidParameterException, ApiException { | ||
String storeId = configuration.getStoreIdChecked(); | ||
String authorizationModelId = configuration.getAuthorizationModelIdChecked(); | ||
return api.readAssertions(storeId, authorizationModelId); | ||
} | ||
|
||
/** | ||
* WriteAssertions - Updates assertions for a particular authorization model | ||
* | ||
* @throws FgaInvalidParameterException When either the Store ID or Authorization Model ID is null, empty, or whitespace | ||
*/ | ||
public CompletableFuture<Void> writeAssertions(WriteAssertionsRequest request) | ||
throws FgaInvalidParameterException, ApiException { | ||
String storeId = configuration.getStoreIdChecked(); | ||
String authorizationModelId = configuration.getAuthorizationModelIdChecked(); | ||
return api.writeAssertions(storeId, authorizationModelId, request); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/dev/openfga/sdk/api/client/ReadAuthorizationModelsOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* OpenFGA | ||
* A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar. | ||
* | ||
* The version of the OpenAPI document: 0.1 | ||
* Contact: [email protected] | ||
* | ||
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). | ||
* https://openapi-generator.tech | ||
* Do not edit the class manually. | ||
*/ | ||
|
||
package dev.openfga.sdk.api.client; | ||
|
||
public class ReadAuthorizationModelsOptions { | ||
private Integer pageSize; | ||
private String continuationToken; | ||
|
||
public ReadAuthorizationModelsOptions pageSize(Integer pageSize) { | ||
this.pageSize = pageSize; | ||
return this; | ||
} | ||
|
||
public Integer getPageSize() { | ||
return pageSize; | ||
} | ||
|
||
public ReadAuthorizationModelsOptions continuationToken(String continuationToken) { | ||
this.continuationToken = continuationToken; | ||
return this; | ||
} | ||
|
||
public String getContinuationToken() { | ||
return continuationToken; | ||
} | ||
} |
Oops, something went wrong.