Skip to content

Commit

Permalink
ARC-1699: Spicegen gRPC client binding (#2)
Browse files Browse the repository at this point in the history
* ARC-1699: Added SpiceDB binding and example

* ARC-1699: Update CODEOWNERS

* ARC-1699: Better README

* ARC-1699: Removed copy paste leftovers.
  • Loading branch information
thomasrichner-oviva committed May 23, 2024
1 parent c0ffeeb commit 365d857
Show file tree
Hide file tree
Showing 37 changed files with 1,545 additions and 82 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [email protected] [email protected] [email protected]
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ The generator work in multiple stages that could be re-used for other generators

To make this easy to use, all the above is bundled in the [maven plugin](./generator-maven-plugin).

## Useful Links

- [SpiceDB API Docs](https://buf.build/authzed/api/docs/main/authzed.api.v1)

## Wishlist

- type-safe IDs, needs additional metadata in the schema
Expand Down
14 changes: 11 additions & 3 deletions api/src/main/java/com/oviva/spicegen/api/ObjectRef.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package com.oviva.spicegen.api;

import com.oviva.spicegen.api.internal.SimpleObjectRef;

public interface ObjectRef {
String kind();

String id();

static ObjectRef of(String kind, String id) {
return SimpleObjectRef.of(kind, id);
return new ObjectRef() {
@Override
public String kind() {
return kind;
}

@Override
public String id() {
return id;
}
};
}
}
15 changes: 15 additions & 0 deletions api/src/main/java/com/oviva/spicegen/api/PermissionService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.oviva.spicegen.api;

public interface PermissionService {

/**
* Updates relationships, optionally with preconditions. The returned consistencyToken should be
* stored alongside the created resource such that the authorization can be done at the given
* consistency. This vastly improves the performance and allows the system to function even when
* it is partitioned.
*
* @param updateRelationships the request
* @return the result, containing the consistencyToken
*/
UpdateResult updateRelationships(UpdateRelationships updateRelationships);
}
5 changes: 5 additions & 0 deletions api/src/main/java/com/oviva/spicegen/api/UpdateResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.oviva.spicegen.api;

public interface UpdateResult {
String consistencyToken();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.oviva.spicegen.api.exceptions;

public class AuthenticationException extends ClientException {
public AuthenticationException(String message) {
super(message);
}

public AuthenticationException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.oviva.spicegen.api.exceptions;

public class AuthorizationException extends ClientException {
public AuthorizationException(String message) {
super(message);
}

public AuthorizationException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.oviva.spicegen.api.exceptions;

public class ClientException extends RuntimeException {
public ClientException(String message) {
super(message);
}

public ClientException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.oviva.spicegen.api.exceptions;

public class ConflictException extends ClientException {
public ConflictException(String message) {
super(message);
}

public ConflictException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.oviva.spicegen.api.exceptions;

public class ValidationException extends ClientException {
public ValidationException(String message) {
super(message);
}

public ValidationException(String message, Throwable cause) {
super(message, cause);
}
}

This file was deleted.

69 changes: 69 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Spicegen Example

## Code
See [ExampleTest](./src/test/java/com/oviva/spicegen/example/ExampleTest.java).


## Maven Setup
Example [pom.xml](./pom.xml)
```xml
<project>

<!-- ... -->

<!-- see https://docs.github.com/de/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registr&lt;!&ndash;&ndash;&gt;y-->
<repositories>
<repository>
<id>spicegen</id>
<name>GitHub Oviva Spicegen</name>
<url>https://maven.pkg.github.com/oviva-ag/spicegen</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spicegen</id>
<name>GitHub Oviva Spicegen Plugin</name>
<url>https://maven.pkg.github.com/oviva-ag/spicegen</url>
</pluginRepository>
</pluginRepositories>

<!-- ... -->

<dependencies>
<dependency>
<groupId>com.oviva.spicegen</groupId>
<artifactId>api</artifactId>
<version>...</version>
</dependency>
<dependency>
<groupId>com.oviva.spicegen</groupId>
<artifactId>spicedb-binding</artifactId>
<version>...</version>
</dependency>
</dependencies>

<!-- ... -->

<build>
<plugins>
<plugin>
<groupId>com.oviva.spicegen</groupId>
<artifactId>spicegen-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<configuration>
<schemaPath>${project.basedir}/src/test/resources/files.zed</schemaPath>
<packageName>${project.groupId}.permissions</packageName>
<outputDirectory>${project.basedir}/target/generated-sources/src/main/java</outputDirectory>
</configuration>
<goals>
<goal>spicegen</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
```
120 changes: 120 additions & 0 deletions example/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.oviva.spicegen</groupId>
<artifactId>spicegen-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<name>Permissions Generator Example</name>
<artifactId>example</artifactId>

<dependencies>
<dependency>
<groupId>com.oviva.spicegen</groupId>
<artifactId>api</artifactId>
</dependency>
<dependency>
<groupId>com.oviva.spicegen</groupId>
<artifactId>spicedb-binding</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludedGroups>integration</excludedGroups>
<argLine>
${argLine}
</argLine>
</configuration>
<executions>
<execution>
<id>integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludedGroups>!integration</excludedGroups>
<groups>integration</groups>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.oviva.spicegen</groupId>
<artifactId>spicegen-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<configuration>
<schemaPath>${project.basedir}/src/test/resources/files.zed</schemaPath>
<packageName>${project.groupId}.permissions</packageName>
<outputDirectory>${project.basedir}/target/generated-sources/src/main/java</outputDirectory>
</configuration>
<goals>
<goal>spicegen</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Loading

0 comments on commit 365d857

Please sign in to comment.