snapshot of https://github.com/ory/keto.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
CI / Run lints and checks (push) Failing after 47s
CI / Run tests (push) Failing after 1s
CI / Run race tests (push) Failing after 5s
CI / Build CLI docs (push) Has been skipped
CI / Run buf actions (push) Failing after 5s
CodeQL / Analyze (go) (push) Failing after 3s
CodeQL / Analyze (javascript) (push) Failing after 2s
Docker Image Scanners / scanners (push) Failing after 3s
Format / format (push) Failing after 3s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Draft newsletter (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
Some checks failed
CI / Run lints and checks (push) Failing after 47s
CI / Run tests (push) Failing after 1s
CI / Run race tests (push) Failing after 5s
CI / Build CLI docs (push) Has been skipped
CI / Run buf actions (push) Failing after 5s
CodeQL / Analyze (go) (push) Failing after 3s
CodeQL / Analyze (javascript) (push) Failing after 2s
Docker Image Scanners / scanners (push) Failing after 3s
Format / format (push) Failing after 3s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Draft newsletter (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
export KETO_READ_REMOTE="127.0.0.1:4466"
|
||||
|
||||
keto expand access files:/photos/beach.jpg --format json-pretty --max-depth 3 --insecure-disable-transport-security
|
||||
11
contrib/docs-code-samples/expand-api-display-access/01-expand-beach/curl.sh
Executable file
11
contrib/docs-code-samples/expand-api-display-access/01-expand-beach/curl.sh
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
curl -G --silent \
|
||||
--retry 7 --retry-connrefused \
|
||||
--data-urlencode "namespace=files" \
|
||||
--data-urlencode "relation=access" \
|
||||
--data-urlencode "object=/photos/beach.jpg" \
|
||||
--data-urlencode "max-depth=3" \
|
||||
http://127.0.0.1:4466/relation-tuples/expand | \
|
||||
jq
|
||||
@@ -0,0 +1,76 @@
|
||||
{
|
||||
"children": [
|
||||
{
|
||||
"children": [
|
||||
{
|
||||
"tuple": {
|
||||
"namespace": "",
|
||||
"object": "",
|
||||
"relation": "",
|
||||
"subject_id": "maureen"
|
||||
},
|
||||
"type": "leaf"
|
||||
}
|
||||
],
|
||||
"tuple": {
|
||||
"namespace": "",
|
||||
"object": "",
|
||||
"relation": "",
|
||||
"subject_set": {
|
||||
"namespace": "files",
|
||||
"object": "/photos/beach.jpg",
|
||||
"relation": "owner"
|
||||
}
|
||||
},
|
||||
"type": "union"
|
||||
},
|
||||
{
|
||||
"children": [
|
||||
{
|
||||
"tuple": {
|
||||
"namespace": "",
|
||||
"object": "",
|
||||
"relation": "",
|
||||
"subject_id": "laura"
|
||||
},
|
||||
"type": "leaf"
|
||||
},
|
||||
{
|
||||
"tuple": {
|
||||
"namespace": "",
|
||||
"object": "",
|
||||
"relation": "",
|
||||
"subject_set": {
|
||||
"namespace": "directories",
|
||||
"object": "/photos",
|
||||
"relation": "owner"
|
||||
}
|
||||
},
|
||||
"type": "leaf"
|
||||
}
|
||||
],
|
||||
"tuple": {
|
||||
"namespace": "",
|
||||
"object": "",
|
||||
"relation": "",
|
||||
"subject_set": {
|
||||
"namespace": "directories",
|
||||
"object": "/photos",
|
||||
"relation": "access"
|
||||
}
|
||||
},
|
||||
"type": "union"
|
||||
}
|
||||
],
|
||||
"tuple": {
|
||||
"namespace": "",
|
||||
"object": "",
|
||||
"relation": "",
|
||||
"subject_set": {
|
||||
"namespace": "files",
|
||||
"object": "/photos/beach.jpg",
|
||||
"relation": "access"
|
||||
}
|
||||
},
|
||||
"type": "union"
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
// Copyright © 2023 Ory Corp
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import grpc from "@ory/keto-grpc-client/node_modules/@grpc/grpc-js/build/src/index.js"
|
||||
import { relationTuples, expand, expandService } from "@ory/keto-grpc-client"
|
||||
|
||||
const expandClient = new expandService.ExpandServiceClient(
|
||||
"127.0.0.1:4466",
|
||||
grpc.credentials.createInsecure(),
|
||||
)
|
||||
|
||||
const subjectSet = new relationTuples.SubjectSet()
|
||||
subjectSet.setNamespace("files")
|
||||
subjectSet.setRelation("access")
|
||||
subjectSet.setObject("/photos/beach.jpg")
|
||||
|
||||
const sub = new relationTuples.Subject()
|
||||
sub.setSet(subjectSet)
|
||||
|
||||
const expandRequest = new expand.ExpandRequest()
|
||||
expandRequest.setSubject(sub)
|
||||
expandRequest.setMaxDepth(3)
|
||||
|
||||
// helper to get a nice result
|
||||
const subjectJSON = (subject) => {
|
||||
if (subject.hasId()) {
|
||||
return { subject_id: subject.getId() }
|
||||
}
|
||||
const set = subject.getSet()
|
||||
return {
|
||||
subject_set: {
|
||||
namespace: set.getNamespace(),
|
||||
object: set.getObject(),
|
||||
relation: set.getRelation(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// helper to get a nice result
|
||||
const prettyTree = (tree) => {
|
||||
const [nodeType, tuple, children] = [
|
||||
tree.getNodeType(),
|
||||
{
|
||||
tuple: {
|
||||
namespace: "",
|
||||
object: "",
|
||||
relation: "",
|
||||
...subjectJSON(tree.getSubject()),
|
||||
},
|
||||
},
|
||||
tree.getChildrenList(),
|
||||
]
|
||||
switch (nodeType) {
|
||||
case expand.NodeType.NODE_TYPE_LEAF:
|
||||
return { type: "leaf", ...tuple }
|
||||
case expand.NodeType.NODE_TYPE_UNION: {
|
||||
const mapped = children.map(prettyTree)
|
||||
return mapped.length > 0
|
||||
? { type: "union", children: mapped, ...tuple }
|
||||
: { type: "union", ...tuple }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
expandClient.expand(expandRequest, (error, resp) => {
|
||||
if (error) {
|
||||
console.log("Encountered error:", error)
|
||||
} else {
|
||||
console.log(JSON.stringify(prettyTree(resp.getTree()), null, 2))
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,41 @@
|
||||
// Copyright © 2023 Ory Corp
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
|
||||
rts "github.com/ory/keto/gen/go/ory/keto/relation_tuples/v1alpha2"
|
||||
"github.com/ory/keto/ketoapi"
|
||||
)
|
||||
|
||||
func main() {
|
||||
conn, err := grpc.NewClient("127.0.0.1:4466", grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
client := rts.NewExpandServiceClient(conn)
|
||||
|
||||
res, err := client.Expand(context.Background(), &rts.ExpandRequest{
|
||||
Subject: rts.NewSubjectSet("files", "/photos/beach.jpg", "access"),
|
||||
MaxDepth: 3,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
tree := ketoapi.TreeFromProto[*ketoapi.RelationTuple](res.Tree)
|
||||
|
||||
enc := json.NewEncoder(os.Stdout)
|
||||
enc.SetIndent("", " ")
|
||||
if err := enc.Encode(tree); err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user