Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OpenFGA module #8371

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ body:
- MySQL
- Neo4j
- NGINX
- OpenFGA
- Oracle Free
- Oracle XE
- OrientDB
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/enhancement.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ body:
- MySQL
- Neo4j
- NGINX
- OpenFGA
- Oracle Free
- Oracle XE
- OrientDB
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/feature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ body:
- MySQL
- Neo4j
- NGINX
- OpenFGA
- Oracle Free
- Oracle XE
- OrientDB
Expand Down
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ updates:
schedule:
interval: "weekly"
open-pull-requests-limit: 10
- package-ecosystem: "gradle"
directory: "/modules/openfga"
schedule:
interval: "weekly"
- package-ecosystem: "gradle"
directory: "/modules/oracle-free"
schedule:
Expand Down
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@
- changed-files:
- any-glob-to-any-file:
- modules/nginx/**/*
"modules/openfga":
- changed-files:
- any-glob-to-any-file:
- modules/openfga/**/*
"modules/oracle":
- changed-files:
- any-glob-to-any-file:
Expand Down
3 changes: 3 additions & 0 deletions .github/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ labels:
- name: modules/nginx
color: '#006b75'

- name: modules/openfga
color: '#006b75'

- name: modules/oracle
color: '#006b75'

Expand Down
30 changes: 30 additions & 0 deletions docs/modules/openfga.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# OpenFGA

Testcontainers module for [OpenFGA](https://hub.docker.com/r/"openfga/openfga).

## OpenFGAContainer's usage examples

You can start an OpenFGA container instance from any Java application by using:

<!--codeinclude-->
[OpenFGA container](../../modules/openfga/src/test/java/org/testcontainers/openfga/OpenFGAContainerTest.java) inside_block:container
<!--/codeinclude-->

## Adding this module to your project dependencies

Add the following dependency to your `pom.xml`/`build.gradle` file:

=== "Gradle"
```groovy
testImplementation "org.testcontainers:openfga:{{latest_version}}"
```

=== "Maven"
```xml
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>openfga</artifactId>
<version>{{latest_version}}</version>
<scope>test</scope>
</dependency>
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ nav:
- modules/minio.md
- modules/mockserver.md
- modules/nginx.md
- modules/openfga.md
- modules/pulsar.md
- modules/qdrant.md
- modules/rabbitmq.md
Expand Down
21 changes: 21 additions & 0 deletions modules/openfga/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
description = "Testcontainers :: OpenFGA"

dependencies {
api project(':testcontainers')

testImplementation 'org.assertj:assertj-core:3.25.1'
testImplementation 'dev.openfga:openfga-sdk:0.3.2'
}

test {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(11)
}
}

compileTestJava {
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(11)
}
options.release.set(11)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.testcontainers.openfga;

import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.DockerImageName;

/**
* Testcontainers implementation for OpenFGA.
* <p>
* Supported image: {@code openfga/openfga}
* <p>
* Exposed ports:
* <ul>
* <li>Playground: 3000</li>
* <li>HTTP: 8080</li>
* <li>gRPC: 8081</li>
* </ul>
*/
public class OpenFGAContainer extends GenericContainer<OpenFGAContainer> {

private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("openfga/openfga");

public OpenFGAContainer(String image) {
this(DockerImageName.parse(image));
}

public OpenFGAContainer(DockerImageName dockerImageName) {
super(dockerImageName);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);

withExposedPorts(3000, 8080, 8081);
withCommand("run");
waitingFor(
Wait.forHttp("/healthz").forPort(8080).forResponsePredicate(response -> response.contains("SERVING"))
);
}

public String getHttpEndpoint() {
return "http://" + getHost() + ":" + getMappedPort(8080);
}

public String getGrpcEndpoint() {
return "http://" + getHost() + ":" + getMappedPort(8081);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.testcontainers.openfga;

import dev.openfga.sdk.api.client.OpenFgaClient;
import dev.openfga.sdk.api.client.model.ClientCreateStoreResponse;
import dev.openfga.sdk.api.configuration.ClientConfiguration;
import dev.openfga.sdk.api.model.CreateStoreRequest;
import dev.openfga.sdk.errors.FgaInvalidParameterException;
import org.junit.Test;

import java.util.concurrent.ExecutionException;

import static org.assertj.core.api.Assertions.assertThat;

public class OpenFGAContainerTest {

@Test
public void withDefaultConfig() throws FgaInvalidParameterException, ExecutionException, InterruptedException {
try ( // container
OpenFGAContainer openfga = new OpenFGAContainer("openfga/openfga:v1.4.3")
// }
) {
openfga.start();

ClientConfiguration config = new ClientConfiguration().apiUrl(openfga.getHttpEndpoint());
OpenFgaClient client = new OpenFgaClient(config);

assertThat(client.listStores().get().getStores()).isEmpty();
ClientCreateStoreResponse store = client.createStore(new CreateStoreRequest().name("test")).get();
assertThat(store.getId()).isNotNull();
assertThat(client.listStores().get().getStores()).hasSize(1);
}
}
}
16 changes: 16 additions & 0 deletions modules/openfga/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} %-5level %logger - %msg%n</pattern>
</encoder>
</appender>

<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>

<logger name="org.testcontainers" level="INFO"/>
</configuration>