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:
20
contrib/docs-code-samples/list-api-display-objects/00-create-tuples/cli.sh
Executable file
20
contrib/docs-code-samples/list-api-display-objects/00-create-tuples/cli.sh
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
export KETO_WRITE_REMOTE="127.0.0.1:4467"
|
||||
|
||||
echo 'chats:memes#member@PM
|
||||
chats:memes#member@Vincent
|
||||
chats:memes#member@Julia
|
||||
|
||||
chats:cars#member@PM
|
||||
chats:cars#member@Julia
|
||||
|
||||
chats:coffee-break#member@PM
|
||||
chats:coffee-break#member@Vincent
|
||||
chats:coffee-break#member@Julia
|
||||
chats:coffee-break#member@Patrik' | \
|
||||
keto relation-tuple parse -f - --format json | \
|
||||
keto relation-tuple create -f - >/dev/null --insecure-disable-transport-security \
|
||||
&& echo "Successfully created tuples" \
|
||||
|| echo "Encountered error"
|
||||
23
contrib/docs-code-samples/list-api-display-objects/00-create-tuples/curl.sh
Executable file
23
contrib/docs-code-samples/list-api-display-objects/00-create-tuples/curl.sh
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
echo 'chats:memes#member@PM
|
||||
chats:memes#member@Vincent
|
||||
chats:memes#member@Julia
|
||||
|
||||
chats:cars#member@PM
|
||||
chats:cars#member@Julia
|
||||
|
||||
chats:coffee-break#member@PM
|
||||
chats:coffee-break#member@Vincent
|
||||
chats:coffee-break#member@Julia
|
||||
chats:coffee-break#member@Patrik' | \
|
||||
keto relation-tuple parse -f - --format json | \
|
||||
jq "[ .[] | { relation_tuple: . , action: \"insert\" } ]" -c | \
|
||||
curl -X PATCH --silent --fail \
|
||||
-H 'Content-Type: application/json' \
|
||||
--retry 7 --retry-connrefused \
|
||||
--data @- \
|
||||
http://127.0.0.1:4467/admin/relation-tuples
|
||||
|
||||
echo "Successfully created tuples"
|
||||
@@ -0,0 +1 @@
|
||||
Successfully created tuples
|
||||
@@ -0,0 +1,41 @@
|
||||
// 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, write, writeService } from "@ory/keto-grpc-client"
|
||||
|
||||
const writeClient = new writeService.WriteServiceClient(
|
||||
"127.0.0.1:4467",
|
||||
grpc.credentials.createInsecure(),
|
||||
)
|
||||
|
||||
const writeRequest = new write.TransactRelationTuplesRequest()
|
||||
|
||||
const addToChat = (chatName) => (user) => {
|
||||
const relationTuple = new relationTuples.RelationTuple()
|
||||
relationTuple.setNamespace("chats")
|
||||
relationTuple.setObject(chatName)
|
||||
relationTuple.setRelation("member")
|
||||
|
||||
const sub = new relationTuples.Subject()
|
||||
sub.setId(user)
|
||||
relationTuple.setSubject(sub)
|
||||
|
||||
const tupleDelta = new write.RelationTupleDelta()
|
||||
tupleDelta.setAction(write.RelationTupleDelta.Action.ACTION_INSERT)
|
||||
tupleDelta.setRelationTuple(relationTuple)
|
||||
|
||||
writeRequest.addRelationTupleDeltas(tupleDelta)
|
||||
}
|
||||
|
||||
;["PM", "Vincent", "Julia"].forEach(addToChat("memes"))
|
||||
;["PM", "Julia"].forEach(addToChat("cars"))
|
||||
;["PM", "Vincent", "Julia", "Patrik"].forEach(addToChat("coffee-break"))
|
||||
|
||||
writeClient.transactRelationTuples(writeRequest, (error) => {
|
||||
if (error) {
|
||||
console.log("Encountered error", error)
|
||||
} else {
|
||||
console.log("Successfully created tuples")
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,61 @@
|
||||
// Copyright © 2023 Ory Corp
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
|
||||
rts "github.com/ory/keto/gen/go/ory/keto/relation_tuples/v1alpha2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
conn, err := grpc.NewClient("127.0.0.1:4467", grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
panic("Encountered error: " + err.Error())
|
||||
}
|
||||
|
||||
client := rts.NewWriteServiceClient(conn)
|
||||
|
||||
var tuples []*rts.RelationTuple
|
||||
// memes
|
||||
for _, user := range []string{"PM", "Vincent", "Julia"} {
|
||||
tuples = append(tuples, &rts.RelationTuple{
|
||||
Namespace: "chats",
|
||||
Object: "memes",
|
||||
Relation: "member",
|
||||
Subject: rts.NewSubjectID(user),
|
||||
})
|
||||
}
|
||||
// cars
|
||||
for _, user := range []string{"PM", "Julia"} {
|
||||
tuples = append(tuples, &rts.RelationTuple{
|
||||
Namespace: "chats",
|
||||
Object: "cars",
|
||||
Relation: "member",
|
||||
Subject: rts.NewSubjectID(user),
|
||||
})
|
||||
}
|
||||
// coffee-break
|
||||
for _, user := range []string{"PM", "Vincent", "Julia", "Patrik"} {
|
||||
tuples = append(tuples, &rts.RelationTuple{
|
||||
Namespace: "chats",
|
||||
Object: "coffee-break",
|
||||
Relation: "member",
|
||||
Subject: rts.NewSubjectID(user),
|
||||
})
|
||||
}
|
||||
|
||||
_, err = client.TransactRelationTuples(context.Background(), &rts.TransactRelationTuplesRequest{
|
||||
RelationTupleDeltas: rts.RelationTupleToDeltas(tuples, rts.RelationTupleDelta_ACTION_INSERT),
|
||||
})
|
||||
if err != nil {
|
||||
panic("Encountered error: " + err.Error())
|
||||
}
|
||||
|
||||
fmt.Println("Successfully created tuples")
|
||||
}
|
||||
7
contrib/docs-code-samples/list-api-display-objects/01-list-PM/cli.sh
Executable file
7
contrib/docs-code-samples/list-api-display-objects/01-list-PM/cli.sh
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
export KETO_READ_REMOTE="127.0.0.1:4466"
|
||||
|
||||
keto relation-tuple get --namespace chats --relation member --subject-id PM --format json --insecure-disable-transport-security | \
|
||||
jq ".relation_tuples[] | .object" -r | sort
|
||||
10
contrib/docs-code-samples/list-api-display-objects/01-list-PM/curl.sh
Executable file
10
contrib/docs-code-samples/list-api-display-objects/01-list-PM/curl.sh
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
curl -G --silent \
|
||||
--retry 7 --retry-connrefused \
|
||||
--data-urlencode "namespace=chats" \
|
||||
--data-urlencode "relation=member" \
|
||||
--data-urlencode "subject_id=PM" \
|
||||
http://127.0.0.1:4466/relation-tuples | \
|
||||
jq ".relation_tuples[] | .object" -r | sort
|
||||
@@ -0,0 +1,3 @@
|
||||
cars
|
||||
coffee-break
|
||||
memes
|
||||
@@ -0,0 +1,35 @@
|
||||
// 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, read, readService } from "@ory/keto-grpc-client"
|
||||
|
||||
const readClient = new readService.ReadServiceClient(
|
||||
"127.0.0.1:4466",
|
||||
grpc.credentials.createInsecure(),
|
||||
)
|
||||
|
||||
const readRequest = new read.ListRelationTuplesRequest()
|
||||
const query = new read.ListRelationTuplesRequest.Query()
|
||||
query.setNamespace("chats")
|
||||
query.setRelation("member")
|
||||
|
||||
const sub = new relationTuples.Subject()
|
||||
sub.setId("PM")
|
||||
query.setSubject(sub)
|
||||
|
||||
readRequest.setQuery(query)
|
||||
|
||||
readClient.listRelationTuples(readRequest, (error, resp) => {
|
||||
if (error) {
|
||||
console.log("Encountered error:", error)
|
||||
} else {
|
||||
console.log(
|
||||
resp
|
||||
.getRelationTuplesList()
|
||||
.map((tuple) => tuple.getObject())
|
||||
.sort((a, b) => (a < b ? -1 : 1))
|
||||
.join("\n"),
|
||||
)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,44 @@
|
||||
// Copyright © 2023 Ory Corp
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
|
||||
rts "github.com/ory/keto/gen/go/ory/keto/relation_tuples/v1alpha2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
conn, err := grpc.NewClient("127.0.0.1:4466", grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
client := rts.NewReadServiceClient(conn)
|
||||
|
||||
res, err := client.ListRelationTuples(context.Background(), &rts.ListRelationTuplesRequest{
|
||||
RelationQuery: &rts.RelationQuery{
|
||||
Namespace: new("chats"),
|
||||
Relation: new("member"),
|
||||
Subject: rts.NewSubjectID("PM"),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
objects := make([]string, len(res.RelationTuples))
|
||||
for i, rt := range res.RelationTuples {
|
||||
objects[i] = rt.Object
|
||||
}
|
||||
sort.Strings(objects)
|
||||
for _, o := range objects {
|
||||
fmt.Println(o)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
export KETO_READ_REMOTE="127.0.0.1:4466"
|
||||
|
||||
keto relation-tuple get --namespace chats --object coffee-break --relation member --format json --insecure-disable-transport-security | \
|
||||
jq "[.relation_tuples[] | .subject_id] | sort | .[]" -r
|
||||
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
curl -G --silent \
|
||||
--retry 7 --retry-connrefused \
|
||||
--data-urlencode "namespace=chats" \
|
||||
--data-urlencode "object=coffee-break" \
|
||||
--data-urlencode "relation=member" \
|
||||
http://127.0.0.1:4466/relation-tuples | \
|
||||
jq "[.relation_tuples[] | .subject_id] | sort | .[]" -r
|
||||
@@ -0,0 +1,4 @@
|
||||
Julia
|
||||
PM
|
||||
Patrik
|
||||
Vincent
|
||||
@@ -0,0 +1,32 @@
|
||||
// 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 { read, readService } from "@ory/keto-grpc-client"
|
||||
|
||||
const readClient = new readService.ReadServiceClient(
|
||||
"127.0.0.1:4466",
|
||||
grpc.credentials.createInsecure(),
|
||||
)
|
||||
|
||||
const readRequest = new read.ListRelationTuplesRequest()
|
||||
const query = new read.ListRelationTuplesRequest.Query()
|
||||
query.setNamespace("chats")
|
||||
query.setObject("coffee-break")
|
||||
query.setRelation("member")
|
||||
|
||||
readRequest.setQuery(query)
|
||||
|
||||
readClient.listRelationTuples(readRequest, (error, resp) => {
|
||||
if (error) {
|
||||
console.log("Encountered error:", error)
|
||||
} else {
|
||||
console.log(
|
||||
resp
|
||||
.getRelationTuplesList()
|
||||
.map((tuple) => tuple.getSubject().getId())
|
||||
.sort((a, b) => (a < b ? -1 : 1))
|
||||
.join("\n"),
|
||||
)
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,44 @@
|
||||
// Copyright © 2023 Ory Corp
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
|
||||
rts "github.com/ory/keto/gen/go/ory/keto/relation_tuples/v1alpha2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
conn, err := grpc.NewClient("127.0.0.1:4466", grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
client := rts.NewReadServiceClient(conn)
|
||||
|
||||
res, err := client.ListRelationTuples(context.Background(), &rts.ListRelationTuplesRequest{
|
||||
RelationQuery: &rts.RelationQuery{
|
||||
Namespace: new("chats"),
|
||||
Object: new("coffee-break"),
|
||||
Relation: new("member"),
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
ids := make([]string, len(res.RelationTuples))
|
||||
for i, rt := range res.RelationTuples {
|
||||
ids[i] = rt.Subject.Ref.(*rts.Subject_Id).Id
|
||||
}
|
||||
sort.Strings(ids)
|
||||
for _, id := range ids {
|
||||
fmt.Println(id)
|
||||
}
|
||||
}
|
||||
9
contrib/docs-code-samples/list-api-display-objects/99-cleanup/cli.sh
Executable file
9
contrib/docs-code-samples/list-api-display-objects/99-cleanup/cli.sh
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
export KETO_READ_REMOTE="127.0.0.1:4466"
|
||||
export KETO_WRITE_REMOTE="127.0.0.1:4467"
|
||||
|
||||
keto relation-tuple get --namespace chats --format json --insecure-disable-transport-security | \
|
||||
jq ".relation_tuples" | \
|
||||
keto relation-tuple delete -f - -q > /dev/null --insecure-disable-transport-security
|
||||
16
contrib/docs-code-samples/list-api-display-objects/99-cleanup/curl.sh
Executable file
16
contrib/docs-code-samples/list-api-display-objects/99-cleanup/curl.sh
Executable file
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
export KETO_READ_REMOTE="127.0.0.1:4466"
|
||||
export KETO_WRITE_REMOTE="127.0.0.1:4467"
|
||||
|
||||
curl -G --silent \
|
||||
--retry 7 --retry-connrefused \
|
||||
--data-urlencode "namespace=chats" \
|
||||
http://127.0.0.1:4466/relation-tuples | \
|
||||
jq "[ .relation_tuples[] | { relation_tuple: . , action: \"delete\" } ]" -c | \
|
||||
curl -X PATCH --silent --fail \
|
||||
-H 'Content-Type: application/json' \
|
||||
--retry 7 --retry-connrefused \
|
||||
--data @- \
|
||||
http://127.0.0.1:4467/admin/relation-tuples
|
||||
@@ -0,0 +1,38 @@
|
||||
// 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 { write, writeService, read, readService } from "@ory/keto-grpc-client"
|
||||
|
||||
const readClient = new readService.ReadServiceClient(
|
||||
"127.0.0.1:4466",
|
||||
grpc.credentials.createInsecure(),
|
||||
)
|
||||
|
||||
const query = new read.ListRelationTuplesRequest.Query()
|
||||
query.setNamespace("chats")
|
||||
|
||||
const readRequest = new read.ListRelationTuplesRequest()
|
||||
readRequest.setQuery(query)
|
||||
|
||||
readClient.listRelationTuples(readRequest, (err, resp) => {
|
||||
const writeClient = new writeService.WriteServiceClient(
|
||||
"127.0.0.1:4467",
|
||||
grpc.credentials.createInsecure(),
|
||||
)
|
||||
|
||||
const writeRequest = new write.TransactRelationTuplesRequest()
|
||||
|
||||
resp.getRelationTuplesList().forEach((tuple) => {
|
||||
const tupleDelta = new write.RelationTupleDelta()
|
||||
tupleDelta.setAction(write.RelationTupleDelta.Action.ACTION_DELETE)
|
||||
tupleDelta.setRelationTuple(tuple)
|
||||
writeRequest.addRelationTupleDeltas(tupleDelta)
|
||||
})
|
||||
|
||||
writeClient.transactRelationTuples(writeRequest, (err) => {
|
||||
if (err) {
|
||||
console.log("Unexpected err", err)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,57 @@
|
||||
// Copyright © 2023 Ory Corp
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
//go:build docscodesamples
|
||||
// +build docscodesamples
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
rts "github.com/ory/keto/gen/go/ory/keto/relation_tuples/v1alpha2"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rc, err := grpc.NewClient("127.0.0.1:4466", grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer rc.Close()
|
||||
|
||||
rClient := rts.NewReadServiceClient(rc)
|
||||
resp, err := rClient.ListRelationTuples(context.Background(), &rts.ListRelationTuplesRequest{
|
||||
Query: &rts.ListRelationTuplesRequest_Query{
|
||||
Namespace: "chats",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
wc, err := grpc.NewClient("127.0.0.1:4467", grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer wc.Close()
|
||||
|
||||
deltas := make([]*rts.RelationTupleDelta, len(resp.RelationTuples))
|
||||
for i, rt := range resp.RelationTuples {
|
||||
deltas[i] = &rts.RelationTupleDelta{
|
||||
Action: rts.RelationTupleDelta_ACTION_DELETE,
|
||||
RelationTuple: proto.Clone(rt).(*rts.RelationTuple),
|
||||
}
|
||||
}
|
||||
|
||||
wClient := rts.NewWriteServiceClient(wc)
|
||||
_, err = wClient.TransactRelationTuples(context.Background(), &rts.TransactRelationTuplesRequest{
|
||||
RelationTupleDeltas: deltas,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
dsn: memory
|
||||
log:
|
||||
level: trace
|
||||
|
||||
namespaces:
|
||||
- name: chats
|
||||
id: 1
|
||||
Reference in New Issue
Block a user