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

ARC-1699: Spicegen gRPC client binding #2

Merged
merged 4 commits into from
May 23, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can extend in the future with e.g. checks etc.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


/**
* 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"?>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a full example. Testing with generated sources directly is a bit problematic, because support for generated test-sources is a bit lackluster ;)

<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