Skip to content

Commit

Permalink
Use Testcontainers OpenFGA module
Browse files Browse the repository at this point in the history
Testcontainers 1.19.7 released a new `OpenFGA` module.
  • Loading branch information
eddumelendez authored and kdubb committed Apr 2, 2024
1 parent 64541a3 commit 70ceb88
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
3 changes: 2 additions & 1 deletion deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<artifactId>openfga</artifactId>
<version>1.19.7</version>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
import java.util.function.Supplier;

import org.jboss.logging.Logger;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.openfga.OpenFGAContainer;
import org.testcontainers.utility.DockerImageName;

import io.quarkiverse.openfga.client.AuthorizationModelsClient;
Expand Down Expand Up @@ -61,7 +60,6 @@ public class DevServicesOpenFGAProcessor {
static final String AUTHORIZATION_MODEL_ID_CONFIG_KEY = CONFIG_PREFIX + "authorization-model-id";
static final ContainerLocator openFGAContainerLocator = new ContainerLocator(DEV_SERVICE_LABEL, OPEN_FGA_EXPOSED_HTTP_PORT);
static final Duration INIT_OP_MAX_WAIT = Duration.ofSeconds(5);
public static final String HEALTH_ENDPOINT = "/healthz";

private static volatile RunningDevService devService;
private static volatile DevServicesOpenFGAConfig capturedDevServicesConfiguration;
Expand Down Expand Up @@ -167,11 +165,10 @@ private RunningDevService startContainer(DockerStatusBuildItem dockerStatusBuild

final Supplier<RunningDevService> defaultOpenFGAInstanceSupplier = () -> {

QuarkusOpenFGAContainer container = new QuarkusOpenFGAContainer(dockerImageName, devServicesConfig.httpPort,
OpenFGAContainer container = new QuarkusOpenFGAContainer(dockerImageName, devServicesConfig.httpPort,
devServicesConfig.grpcPort, devServicesConfig.playgroundPort,
devServicesConfig.serviceName)
.withNetwork(Network.SHARED)
.waitingFor(Wait.forHttp(HEALTH_ENDPOINT).forPort(OPEN_FGA_EXPOSED_HTTP_PORT));
.withNetwork(Network.SHARED);

timeout.ifPresent(container::withStartupTimeout);

Expand All @@ -181,7 +178,7 @@ private RunningDevService startContainer(DockerStatusBuildItem dockerStatusBuild

var devServicesConfigProperties = new HashMap<String, String>();

withAPI(container.getHost(), container.getHttpPort(), (instanceURL, api) -> {
withAPI(container.getHost(), ((QuarkusOpenFGAContainer) container).getHttpPort(), (instanceURL, api) -> {

devServicesConfigProperties.put(URL_CONFIG_KEY, instanceURL.toExternalForm());

Expand Down Expand Up @@ -394,7 +391,7 @@ private static void withAPI(String host, Integer port, BiFunction<URL, API, Void
}
}

private static class QuarkusOpenFGAContainer extends GenericContainer<QuarkusOpenFGAContainer> {
private static class QuarkusOpenFGAContainer extends OpenFGAContainer {
OptionalInt fixedExposedHttpPort;
OptionalInt fixedExposedGrpcPort;
OptionalInt fixedExposedPlaygroundPort;
Expand All @@ -405,7 +402,6 @@ public QuarkusOpenFGAContainer(DockerImageName dockerImageName, OptionalInt fixe
this.fixedExposedHttpPort = fixedExposedHttpPort;
this.fixedExposedGrpcPort = fixedExposedGrpcPort;
this.fixedExposedPlaygroundPort = fixedExposedPlaygroundPort;
withCommand("run");
withNetwork(Network.SHARED);
if (serviceName != null) { // Only adds the label in dev mode.
withLabel(DEV_SERVICE_LABEL, serviceName);
Expand Down

0 comments on commit 70ceb88

Please sign in to comment.