Skip to content

Commit

Permalink
Merge pull request #152 from quarkiverse/task/update-api
Browse files Browse the repository at this point in the history
Update API to match new options and capabilities
  • Loading branch information
kdubb authored Aug 19, 2024
2 parents a3b6e0d + a393ed6 commit e5b4589
Show file tree
Hide file tree
Showing 97 changed files with 3,523 additions and 1,000 deletions.
18 changes: 4 additions & 14 deletions deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>openfga</artifactId>
<version>1.20.0</version>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand All @@ -59,9 +48,10 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.exparity</groupId>
<artifactId>hamcrest-date</artifactId>
<version>${hamcrest.date.version}</version>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Supplier;

Expand All @@ -29,13 +24,10 @@
import io.quarkiverse.openfga.client.OpenFGAClient;
import io.quarkiverse.openfga.client.api.API;
import io.quarkiverse.openfga.client.api.VertxWebClientFactory;
import io.quarkiverse.openfga.client.model.AuthorizationModel;
import io.quarkiverse.openfga.client.model.Store;
import io.quarkiverse.openfga.client.model.TupleKey;
import io.quarkiverse.openfga.client.model.TupleKeys;
import io.quarkiverse.openfga.client.model.TypeDefinitions;
import io.quarkiverse.openfga.client.model.*;
import io.quarkiverse.openfga.client.model.dto.CreateStoreRequest;
import io.quarkiverse.openfga.client.model.dto.WriteBody;
import io.quarkiverse.openfga.client.model.dto.WriteAuthorizationModelRequest;
import io.quarkiverse.openfga.client.model.dto.WriteRequest;
import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
import io.quarkus.deployment.IsNormal;
import io.quarkus.deployment.annotations.BuildProducer;
Expand All @@ -59,7 +51,7 @@ public class DevServicesOpenFGAProcessor {

private static final Logger log = Logger.getLogger(DevServicesOpenFGAProcessor.class);

static final String OPEN_FGA_VERSION = "v1.5.1";
static final String OPEN_FGA_VERSION = "v1.5.9";
static final String OPEN_FGA_IMAGE = "openfga/openfga:" + OPEN_FGA_VERSION;
static final int OPEN_FGA_EXPOSED_HTTP_PORT = 8080;
static final int OPEN_FGA_EXPOSED_GRPC_PORT = 8081;
Expand Down Expand Up @@ -198,7 +190,7 @@ private RunningDevService startContainer(DockerStatusBuildItem dockerStatusBuild

log.info("Initializing authorization store...");

storeId = api.createStore(new CreateStoreRequest(devServicesConfig.storeName))
storeId = api.createStore(CreateStoreRequest.of(devServicesConfig.storeName))
.await().atMost(INIT_OP_MAX_WAIT)
.getId();

Expand All @@ -209,13 +201,14 @@ private RunningDevService startContainer(DockerStatusBuildItem dockerStatusBuild
}

loadAuthorizationModelDefinition(api, devServicesConfig)
.ifPresentOrElse(authModelDef -> {
.ifPresentOrElse(schema -> {

String authModelId;
try {
log.info("Initializing authorization model...");

authModelId = api.writeAuthorizationModel(storeId, authModelDef)
var request = WriteAuthorizationModelRequest.of(schema);
authModelId = api.writeAuthorizationModel(storeId, request)
.await()
.atMost(INIT_OP_MAX_WAIT)
.getAuthorizationModelId();
Expand All @@ -231,7 +224,11 @@ private RunningDevService startContainer(DockerStatusBuildItem dockerStatusBuild
try {
log.info("Initializing authorization tuples...");

api.write(storeId, new WriteBody(new TupleKeys(authTuples), null, authModelId))
var writeRequest = WriteRequest.builder()
.authorizationModelId(authModelId)
.addWrites(authTuples)
.build();
api.write(storeId, writeRequest)
.await()
.atMost(INIT_OP_MAX_WAIT);

Expand Down Expand Up @@ -308,7 +305,7 @@ private RunningDevService startContainer(DockerStatusBuildItem dockerStatusBuild
.orElseGet(defaultOpenFGAInstanceSupplier);
}

private static Optional<TypeDefinitions> loadAuthorizationModelDefinition(API api,
private static Optional<AuthorizationModelSchema> loadAuthorizationModelDefinition(API api,
DevServicesOpenFGAConfig devServicesConfig) {
return devServicesConfig.authorizationModel
.or(() -> {
Expand All @@ -325,14 +322,14 @@ private static Optional<TypeDefinitions> loadAuthorizationModelDefinition(API ap
})
.map(authModelJSON -> {
try {
return api.parseModel(authModelJSON);
return api.parseModelSchema(authModelJSON);
} catch (Throwable t) {
throw new RuntimeException("Unable to parse authorization model", t);
}
});
}

private static Optional<List<TupleKey>> loadAuthorizationTuples(API api,
private static Optional<List<ConditionalTupleKey>> loadAuthorizationTuples(API api,
DevServicesOpenFGAConfig devServicesConfig) {
return devServicesConfig.authorizationTuples
.or(() -> {
Expand Down
Loading

0 comments on commit e5b4589

Please sign in to comment.