Skip to content

Commit

Permalink
Merge pull request #111 from project-kessel/update-for-schema
Browse files Browse the repository at this point in the history
Change examples from user to principal
  • Loading branch information
lennysgarage authored Dec 17, 2024
2 parents 47b1b74 + b9e47b5 commit ba469fc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ var checkClient = clientsManager.getCheckClient();
### Making requests
#### Synchronous example

Let's say we want to check whether a subject of type "user" (in the "rbac" type namespace) with id "bob" has "view" permission to a resource of type "thing" (in the "rbac" type namespace) and id "my_thing". We can make the following synchronous check request:
Let's say we want to check whether a subject of type "principal" (in the "rbac" type namespace) with id "bob" has "view" permission to a resource of type "widget" (in the "rbac" type namespace) and id "my_thing". We can make the following synchronous check request:

```java
var checkRequest = CheckRequest.newBuilder()
.setSubject(SubjectReference.newBuilder()
.setSubject(ObjectReference.newBuilder()
.setType(ObjectType.newBuilder()
.setNamespace("rbac")
.setName("user").build())
.setName("principal").build())
.setId("bob").build())
.build())
.setRelation("view")
.setResource(ObjectReference.newBuilder()
.setType(ObjectType.newBuilder()
.setNamespace("rbac")
.setName("thing").build())
.setName("widget").build())
.setId("my_thing")
.build())
.build();
Expand All @@ -55,17 +55,17 @@ var permitted = checkResponse.getAllowed() == CheckResponse.Allowed.ALLOWED_TRUE

#### Asynchronous reactive example (using Mutiny)

Let's say we want to look up all of the resources of type "thing" (in the "rbac" type namespace) that a subject of type "user" (in the "rbac" type namespace) and id "bob" has "view" permission on. Since there may be many responses, we might want to operate on them asynchronously as they come in, but we may also want to collect them all afterwards and perform a synchronous operation on the list. We can make the following request using the mutiny reactive programming API to achieve both:
Let's say we want to look up all of the resources of type "widget" (in the "rbac" type namespace) that a subject of type "principal" (in the "rbac" type namespace) and id "bob" has "view" permission on. Since there may be many responses, we might want to operate on them asynchronously as they come in, but we may also want to collect them all afterwards and perform a synchronous operation on the list. We can make the following request using the mutiny reactive programming API to achieve both:

```java
var lookupResourcesRequest = LookupResourcesRequest.newBuilder()
.setResourceType(ObjectType.newBuilder()
.setNamespace("rbac").setName("thing"))
.setNamespace("rbac").setName("widget"))
.setRelation("view").setSubject(SubjectReference.newBuilder()
.setSubject(ObjectReference.newBuilder()
.setType(ObjectType.newBuilder()
.setNamespace("rbac")
.setName("user").build())
.setName("principal").build())
.setId("bob").build())
.build()).build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
public class Caller {

static final String userName = "joe";
static final String subjectType = "user";
static final String subjectType = "principal";
static final String permission = "view";
static final String namespace = "rbac";
static final String resourceType = "thing";
static final String resourceType = "widget";
static final String resourceId = "my_thing";

public static void main(String[] argv) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,22 +178,22 @@ void testRequestMultiFailsWithError() {

List<Relationship> relationshipListMaker(int startPostfix, int endPostfix) {
return IntStream.range(startPostfix, endPostfix).mapToObj(i ->
relationshipMaker("thing_" + i, "workspace_" + i)
relationshipMaker("widget_" + i, "workspace_" + i)
).collect(Collectors.toList());
}

@SuppressWarnings("SameParameterValue")
List<Relationship> badRelationshipListMaker(int startPostfix, int endPostfix) {
return IntStream.range(startPostfix, endPostfix).mapToObj(i ->
badRelationshipMaker("thing_" + i, "workspace_" + i)
badRelationshipMaker("widget_" + i, "workspace_" + i)
).collect(Collectors.toList());
}

void deleteRelationships() {
DeleteTuplesRequest req = DeleteTuplesRequest.newBuilder()
.setFilter(RelationTupleFilter.newBuilder()
.setResourceNamespace("rbac")
.setResourceType("thing")
.setResourceType("widget")
.build())
.build();
client.deleteTuples(req);
Expand All @@ -212,7 +212,7 @@ Relationship relationshipMaker(String thingId, String workspaceId) {
.setResource(ObjectReference.newBuilder()
.setType(ObjectType.newBuilder()
.setNamespace("rbac")
.setName("thing").build())
.setName("widget").build())
.setId(thingId)
.build())
.build();
Expand All @@ -231,7 +231,7 @@ Relationship badRelationshipMaker(String thingId, String workspaceId) {
.setResource(ObjectReference.newBuilder()
.setType(ObjectType.newBuilder()
.setNamespace("rbac")
.setName("thing").build())
.setName("widget").build())
.setId(thingId)
.build())
.build();
Expand All @@ -243,7 +243,7 @@ long countStoredRelationships() {
ReadTuplesRequest request = ReadTuplesRequest.newBuilder()
.setFilter(RelationTupleFilter.newBuilder()
.setResourceNamespace("rbac")
.setResourceType("thing")
.setResourceType("widget")
.build())
.build();
var relResponses = StreamSupport.stream(
Expand Down

0 comments on commit ba469fc

Please sign in to comment.