-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from openfga/add-example
chore: add example java/kotlin projects
- Loading branch information
Showing
22 changed files
with
1,275 additions
and
9 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
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
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
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
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,17 @@ | ||
all: build | ||
|
||
project_name=example1 | ||
openfga_version=latest | ||
language=java | ||
|
||
build: | ||
cd "${project_name}" && \ | ||
./gradlew -P language=$(language) build | ||
|
||
run: | ||
cd "${project_name}" && \ | ||
./gradlew -P language=$(language) run | ||
|
||
run-openfga: | ||
docker pull docker.io/openfga/openfga:${openfga_version} && \ | ||
docker run -p 8080:8080 docker.io/openfga/openfga:${openfga_version} run |
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,49 @@ | ||
## Examples of using the OpenFGA Java SDK | ||
|
||
A set of Examples on how to call the OpenFGA Java SDK | ||
|
||
### Examples | ||
Example 1: | ||
A bare-bones example. It creates a store, and runs a set of calls against it including creating a model, writing tuples and checking for access. | ||
This example is implemented in both Java and Kotlin. | ||
|
||
|
||
### Running the Examples | ||
|
||
Prerequisites: | ||
- `docker` | ||
- `make` | ||
- A Java Runtime Environment (JRE) | ||
|
||
#### Run using a published SDK | ||
|
||
Steps | ||
1. Clone/Copy the example folder | ||
2. Run `make` to build the project | ||
3. If you have an OpenFGA server running, you can use it, otherwise run `make run-openfga` to spin up an instance (you'll need to switch to a different terminal after - don't forget to close it when done) | ||
4. Run `make run` to run the example | ||
|
||
#### Run using a local unpublished SDK build | ||
|
||
Steps | ||
1. Build the SDK | ||
2. In the Example project file (e.g. `build.gradle`), comment out the part that specifies the remote SDK, e.g. | ||
```groovy | ||
dependencies { | ||
implementation("dev.openfga:openfga-sdk:0.3.+") | ||
// ...etc | ||
} | ||
``` | ||
and replace it with one pointing to the local gradle project, e.g. | ||
```groovy | ||
dependencies { | ||
// implementation("dev.openfga:openfga-sdk:0.3.+") | ||
implementation project(path: ':') | ||
// ...etc | ||
} | ||
``` | ||
3. Run `make` to build the project | ||
4. If you have an OpenFGA server running, you can use it, otherwise run `make run-openfga` to spin up an instance (you'll need to switch to a different terminal after - don't forget to close it when done) | ||
5. Run `make run` to run the example |
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,50 @@ | ||
## Examples of using the OpenFGA Java SDK | ||
|
||
A set of Examples on how to call the OpenFGA Java SDK | ||
|
||
### Examples | ||
Example 1: | ||
A bare-bones example. It creates a store, and runs a set of calls against it including creating a model, writing tuples and checking for access. | ||
This example is implemented in both Java and Kotlin. | ||
|
||
|
||
### Running the Examples | ||
|
||
Prerequisites: | ||
- `docker` | ||
- `make` | ||
- A Java Runtime Environment (JRE) | ||
|
||
#### Run using a published SDK | ||
|
||
Steps | ||
1. Clone/Copy the example folder | ||
2. Run `make` to build the project | ||
3. If you have an OpenFGA server running, you can use it, otherwise run `make run-openfga` to spin up an instance (you'll need to switch to a different terminal after - don't forget to close it when done) | ||
4. Run `make run` to run the example | ||
* This should run a Java example by default. Where implemented, it's possible to specify an alternate JVM language too, like `make run language=kotlin`. | ||
|
||
#### Run using a local unpublished SDK build | ||
|
||
Steps | ||
1. Build the SDK | ||
2. In the Example project file (e.g. `build.gradle`), comment out the part that specifies the remote SDK, e.g. | ||
```groovy | ||
dependencies { | ||
implementation("dev.openfga:openfga-sdk:0.3.+") | ||
// ...etc | ||
} | ||
``` | ||
and replace it with one pointing to the local gradle project, e.g. | ||
```groovy | ||
dependencies { | ||
// implementation("dev.openfga:openfga-sdk:0.3.+") | ||
implementation project(path: ':') | ||
// ...etc | ||
} | ||
``` | ||
3. Run `make` to build the project | ||
4. If you have an OpenFGA server running, you can use it, otherwise run `make run-openfga` to spin up an instance (you'll need to switch to a different terminal after - don't forget to close it when done) | ||
5. Run `make run` to run the example |
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,77 @@ | ||
plugins { | ||
id 'application' | ||
id 'com.diffplug.spotless' version '6.23.3' | ||
id 'org.jetbrains.kotlin.jvm' version '2.0.0-Beta2' | ||
} | ||
|
||
application { | ||
switch (language) { | ||
case 'kotlin': | ||
mainClass = 'dev.openfga.sdk.example.KotlinExample1' | ||
break | ||
default: | ||
mainClass = 'dev.openfga.sdk.example.Example1' | ||
} | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
ext { | ||
jacksonVersion = "2.16.0" | ||
} | ||
|
||
dependencies { | ||
implementation("dev.openfga:openfga-sdk:0.3.+") | ||
|
||
// Serialization | ||
implementation("com.fasterxml.jackson.core:jackson-core:$jacksonVersion") | ||
implementation("com.fasterxml.jackson.core:jackson-annotations:$jacksonVersion") | ||
implementation("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion") | ||
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jacksonVersion") | ||
implementation("org.openapitools:jackson-databind-nullable:0.2.+") | ||
|
||
// Kotlin | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" | ||
} | ||
|
||
// Use spotless plugin to automatically format code, remove unused import, etc | ||
// To apply changes directly to the file, run `gradlew spotlessApply` | ||
// Ref: https://github.com/diffplug/spotless/tree/main/plugin-gradle | ||
spotless { | ||
// comment out below to run spotless as part of the `check` task | ||
enforceCheck false | ||
format 'misc', { | ||
// define the files (e.g. '*.gradle', '*.md') to apply `misc` to | ||
target '.gitignore' | ||
// define the steps to apply to those files | ||
trimTrailingWhitespace() | ||
indentWithSpaces() // Takes an integer argument if you don't like 4 | ||
endWithNewline() | ||
} | ||
java { | ||
palantirJavaFormat() | ||
removeUnusedImports() | ||
importOrder() | ||
} | ||
} | ||
|
||
// Use spotless plugin to automatically format code, remove unused import, etc | ||
// To apply changes directly to the file, run `gradlew spotlessApply` | ||
// Ref: https://github.com/diffplug/spotless/tree/main/plugin-gradle | ||
tasks.register('fmt') { | ||
dependsOn 'spotlessApply' | ||
} | ||
|
||
compileKotlin { | ||
kotlinOptions { | ||
jvmTarget = "17" | ||
} | ||
} | ||
|
||
compileTestKotlin { | ||
kotlinOptions { | ||
jvmTarget = "17" | ||
} | ||
} |
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 @@ | ||
language=java |
Binary file not shown.
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,6 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip | ||
networkTimeout=10000 | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.