### Get Version - Go Example Source: https://github.com/ory/keto/blob/master/internal/httpclient/docs/MetadataApi.md Demonstrates how to call the GetVersion API to retrieve the running software version. Requires setting up the API client configuration. ```go package main import ( "context" "fmt" "os" openapiclient "./openapi" ) func main() { configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) resp, r, err := apiClient.MetadataApi.GetVersion(context.Background()).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `MetadataApi.GetVersion``: %v\n", err) fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) } // response from `GetVersion`: GetVersion200Response fmt.Fprintf(os.Stdout, "Response from `MetadataApi.GetVersion`: %v\n", resp) } ``` -------------------------------- ### Install Dependencies for Go Client Source: https://github.com/ory/keto/blob/master/internal/httpclient/README.md Install necessary dependencies for the Go API client using 'go get'. ```shell go get github.com/stretchr/testify/assert go get golang.org/x/oauth2 go get golang.org/x/net/context ``` -------------------------------- ### Install Ory Pagination Source: https://github.com/ory/keto/blob/master/oryx/pagination/README.md Use 'go get' to install the Ory pagination library. ```go go get github.com/ory/pagination ``` -------------------------------- ### Check Readiness - Go Example Source: https://github.com/ory/keto/blob/master/internal/httpclient/docs/MetadataApi.md Provides an example of calling the IsReady API to verify the status of both the HTTP server and the database. Ensure the API client is properly configured before execution. ```go package main import ( "context" "fmt" "os" openapiclient "./openapi" ) func main() { configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) resp, r, err := apiClient.MetadataApi.IsReady(context.Background()).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `MetadataApi.IsReady``: %v\n", err) fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) } // response from `IsReady`: IsAlive200Response fmt.Fprintf(os.Stdout, "Response from `MetadataApi.IsReady`: %v\n", resp) } ``` -------------------------------- ### Start Keto Server (CLI & Docker) Source: https://context7.com/ory/keto/llms.txt Commands to start the Keto server using the CLI or Docker, specifying a configuration file. ```bash # Start the Keto server keto serve all --config ./keto.yml # Or using Docker docker run -d \ -p 4466:4466 \ -p 4467:4467 \ -v $(pwd)/keto.yml:/home/user/keto.yml \ oryd/keto:v0.14.0 serve all --config /home/user/keto.yml ``` -------------------------------- ### Install Ory Keto from Source Source: https://github.com/ory/keto/blob/master/DEVELOP.md Use this command to install the Ory Keto binary after cloning the repository. ```shell make install ``` -------------------------------- ### Short Example Source: https://github.com/ory/keto/blob/master/oryx/clidoc/testdata/hydra-client-admin.md A short example demonstrating multiple lines. ```plaintext short with multiple ``` -------------------------------- ### Example Hydra Client Command Source: https://github.com/ory/keto/blob/master/oryx/clidoc/testdata/hydra-client.md An example of how to invoke the hydra client command with a placeholder flag. ```bash hydra client --whatever ``` -------------------------------- ### Run the public server Source: https://github.com/ory/keto/blob/master/oryx/clidoc/testdata/hydra-client-public.md Use this command to start the public server. It accepts arguments and flags for configuration. ```bash hydra client public [flags] ``` -------------------------------- ### Create Relationship - JavaScript gRPC Source: https://context7.com/ory/keto/llms.txt This JavaScript example demonstrates creating a relationship using the @ory/keto-grpc-client library. It requires gRPC credentials and client setup. ```javascript // JavaScript gRPC: Create a relationship using @ory/keto-grpc-client 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 relationTuple = new relationTuples.RelationTuple() relationTuple.setNamespace("messages") relationTuple.setObject("02y_15_4w350m3") relationTuple.setRelation("decypher") const sub = new relationTuples.Subject() sub.setId("john") relationTuple.setSubject(sub) const tupleDelta = new write.RelationTupleDelta() tupleDelta.setAction(write.RelationTupleDelta.Action.ACTION_INSERT) tupleDelta.setRelationTuple(relationTuple) const writeRequest = new write.TransactRelationTuplesRequest() writeRequest.addRelationTupleDeltas(tupleDelta) writeClient.transactRelationTuples(writeRequest, (error) => { if (error) { console.error("Encountered error", error) } else { console.log("Successfully created tuple") } }) ``` -------------------------------- ### Hydra Serve Synopsis Source: https://github.com/ory/keto/blob/master/oryx/clidoc/testdata/hydra-serve.md This is the basic command to start or manage the Hydra server. Use flags to configure its behavior. ```bash hydra serve [flags] ``` -------------------------------- ### Install Ory CLI Source: https://github.com/ory/keto/blob/master/README.md Installs the Ory CLI tool. Ensure you have curl and bash installed. The binary is moved to /usr/local/bin for system-wide access. ```bash bash <(curl https://raw.githubusercontent.com/ory/meta/master/install.sh) -b . ory sudo mv ./ory /usr/local/bin/ ``` -------------------------------- ### Check Liveness - Go Example Source: https://github.com/ory/keto/blob/master/internal/httpclient/docs/MetadataApi.md Shows how to use the IsAlive API to check the HTTP server's status. This involves initializing the API client and executing the request. ```go package main import ( "context" "fmt" "os" openapiclient "./openapi" ) func main() { configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) resp, r, err := apiClient.MetadataApi.IsAlive(context.Background()).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `MetadataApi.IsAlive``: %v\n", err) fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) } // response from `IsAlive`: IsAlive200Response fmt.Fprintf(os.Stdout, "Response from `MetadataApi.IsAlive`: %v\n", resp) } ``` -------------------------------- ### Get Relationships Go Example Source: https://github.com/ory/keto/blob/master/internal/httpclient/docs/RelationshipApi.md This Go code retrieves relationships from Ory Keto. It supports pagination and filtering by various relationship attributes. The default page size is 250. ```go package main import ( "context" "fmt" "os" openapiclient "./openapi" ) func main() { pageSize := int64(789) // int64 | Items per Page This is the number of items per page to return. For details on pagination please head over to the [pagination documentation](https://www.ory.com/docs/ecosystem/api-design#pagination). (optional) (default to 250) pageToken := "pageToken_example" // string | Next Page Token The next page token. For details on pagination please head over to the [pagination documentation](https://www.ory.com/docs/ecosystem/api-design#pagination). (optional) namespace := "namespace_example" // string | Namespace of the Relationship (optional) object := "object_example" // string | Object of the Relationship (optional) relation := "relation_example" // string | Relation of the Relationship (optional) subjectId := "subjectId_example" // string | SubjectID of the Relationship (optional) subjectSetNamespace := "subjectSetNamespace_example" // string | Namespace of the Subject Set (optional) subjectSetObject := "subjectSetObject_example" // string | Object of the Subject Set (optional) subjectSetRelation := "subjectSetRelation_example" // string | Relation of the Subject Set (optional) configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) resp, r, err := apiClient.RelationshipApi.GetRelationships(context.Background()).PageSize(pageSize).PageToken(pageToken).Namespace(namespace).Object(object).Relation(relation).SubjectId(subjectId).SubjectSetNamespace(subjectSetNamespace).SubjectSetObject(subjectSetObject).SubjectSetRelation(subjectSetRelation).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `RelationshipApi.GetRelationships``: %v\n", err) fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) } // response from `GetRelationships`: Relationships fmt.Fprintf(os.Stdout, "Response from `RelationshipApi.GetRelationships`: %v\n", resp) } ``` -------------------------------- ### Generated JSON Paths for Example Schema Source: https://github.com/ory/keto/blob/master/oryx/jsonschemax/README.md The output of `jsonschemax.ListPaths()` for the provided example schema, showing how array elements are represented. ```json [ { "Title": "", "Description": "", "Examples": null, "Name": "providers", "Default": null, "Type": [], "TypeHint": 5, "Format": "", "Pattern": null, "Enum": null, "Constant": null, "ReadOnly": false, "MinLength": -1, "MaxLength": -1, "Required": false, "Minimum": null, "Maximum": null, "MultipleOf": null, "CustomProperties": null }, { "Title": "", "Description": "", "Examples": null, "Name": "providers.#", "Default": null, "Type": {}, "TypeHint": 5, "Format": "", "Pattern": null, "Enum": null, "Constant": null, "ReadOnly": false, "MinLength": -1, "MaxLength": -1, "Required": false, "Minimum": null, "Maximum": null, "MultipleOf": null, "CustomProperties": null }, { "Title": "", "Description": "", "Examples": null, "Name": "providers.#.id", "Default": null, "Type": "", "TypeHint": 1, "Format": "", "Pattern": null, "Enum": null, "Constant": null, "ReadOnly": false, "MinLength": -1, "MaxLength": -1, "Required": false, "Minimum": null, "Maximum": null, "MultipleOf": null, "CustomProperties": null } ] ``` -------------------------------- ### List Relationship Namespaces Go Example Source: https://github.com/ory/keto/blob/master/internal/httpclient/docs/RelationshipApi.md Queries the available relationship namespaces. Ensure the OpenAPI client is generated and imported correctly. No authorization is required for this operation. ```go package main import ( "context" "fmt" "os" openapiclient "./openapi" ) func main() { configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) resp, r, err := apiClient.RelationshipApi.ListRelationshipNamespaces(context.Background()).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `RelationshipApi.ListRelationshipNamespaces``: %v\n", err) fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) } // response from `ListRelationshipNamespaces`: RelationshipNamespaces fmt.Fprintf(os.Stdout, "Response from `RelationshipApi.ListRelationshipNamespaces`: %v\n", resp) } ``` -------------------------------- ### List All Namespaces (Go SDK) Source: https://context7.com/ory/keto/llms.txt The Go SDK offers a convenient method to list all namespaces. This example iterates through the response and prints each namespace name. Ensure your Go environment is set up with the SDK. ```go package main import ( "context" "fmt" "os" openapiclient "./openapi" ) func main() { configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) resp, r, err := apiClient.RelationshipApi.ListRelationshipNamespaces(context.Background()).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error: %v\nHTTP: %v\n", err, r) os.Exit(1) } for _, ns := range resp.Namespaces { fmt.Println(ns.Name) } } ``` -------------------------------- ### Check Single Permission - JavaScript gRPC Client Source: https://context7.com/ory/keto/llms.txt This JavaScript example demonstrates checking permissions using the @ory/keto-grpc-client library. Ensure the library is installed and configured correctly. ```javascript // JavaScript gRPC: Check permission using @ory/keto-grpc-client import grpc from "@ory/keto-grpc-client/node_modules/@grpc/grpc-js/build/src/index.js" import { relationTuples, check, checkService } from "@ory/keto-grpc-client" const checkClient = new checkService.CheckServiceClient( "127.0.0.1:4466", grpc.credentials.createInsecure(), ) const checkRequest = new check.CheckRequest() checkRequest.setNamespace("messages") checkRequest.setObject("02y_15_4w350m3") checkRequest.setRelation("decypher") const sub = new relationTuples.Subject() sub.setId("john") checkRequest.setSubject(sub) checkClient.check(checkRequest, (error, resp) => { if (error) { console.error("Encountered error:", error) } else { console.log(resp.getAllowed() ? "Allowed" : "Denied") } }) ``` -------------------------------- ### Expand Permissions Go Example Source: https://github.com/ory/keto/blob/master/internal/httpclient/docs/PermissionApi.md Demonstrates how to expand a permission tree for a given subject set. Requires specifying namespace, object, and relation. An optional maxDepth parameter can be provided. ```go package main import ( "context" "fmt" "os" openapiclient "./openapi" ) func main() { namespace := "namespace_example" // string | Namespace of the Subject Set object := "object_example" // string | Object of the Subject Set relation := "relation_example" // string | Relation of the Subject Set maxDepth := int64(789) // int64 | (optional) configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) resp, r, err := apiClient.PermissionApi.ExpandPermissions(context.Background()).Namespace(namespace).Object(object).Relation(relation).MaxDepth(maxDepth).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `PermissionApi.ExpandPermissions``: %v\n", err) fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) } // response from `ExpandPermissions`: ExpandedPermissionTree fmt.Fprintf(os.Stdout, "Response from `PermissionApi.ExpandPermissions`: %v\n", resp) } ``` -------------------------------- ### Check OPL Syntax (Go SDK) Source: https://context7.com/ory/keto/llms.txt Validate OPL syntax using the Go SDK. This example demonstrates how to send OPL content and handle the response, checking for syntax errors. ```go // Go SDK: Check OPL syntax package main import ( "context" "fmt" "os" openapiclient "./openapi" ) func main() { body := `class User implements Namespace {} class File implements Namespace { related: { owners: User[] } permits = { edit: (ctx: Context) => this.related.owners.includes(ctx.subject) } }` configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) resp, r, err := apiClient.RelationshipApi.CheckOplSyntax(context.Background()).Body(body).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error: %v\nHTTP response: %v\n", err, r) os.Exit(1) } if len(resp.Errors) > 0 { fmt.Printf("Syntax errors: %v\n", resp.Errors) } else { fmt.Println("OPL syntax is valid") } } ``` -------------------------------- ### Batch Check Permissions - Go SDK Source: https://context7.com/ory/keto/llms.txt This Go SDK example demonstrates how to perform batch permission checks. It utilizes the OpenAPI client generated for the Ory Keto API. ```go // Go SDK: Batch check permissions package main import ( "context" "fmt" "os" openapiclient "./openapi" ) func main() { configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) subjPM := "PM"; subjVincent := "Vincent" body := openapiclient.BatchCheckPermissionBody{ Tuples: []openapiclient.Relationship{ {Namespace: "chats", Object: "memes", Relation: "member", SubjectId: &subjPM}, {Namespace: "chats", Object: "cars", Relation: "member", SubjectId: &subjVincent}, }, } resp, r, err := apiClient.PermissionApi.BatchCheckPermission(context.Background()). BatchCheckPermissionBody(body).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error: %v\nHTTP: %v\n", err, r) os.Exit(1) } for i, result := range resp.Results { fmt.Printf("Check %d: allowed=%v\n", i, result.Allowed) } } ``` -------------------------------- ### Clone and Fork Ory Keto Repository Source: https://github.com/ory/keto/blob/master/CONTRIBUTING.md Steps to clone the Ory Keto repository and set up a remote for your fork. This is the initial setup for contributing. ```bash git clone git@github.com:ory/ory/keto.git ``` ```bash git remote add fork git@github.com:/ory/keto.git ``` -------------------------------- ### Check Permission Go Example Source: https://github.com/ory/keto/blob/master/internal/httpclient/docs/PermissionApi.md Shows how to check a permission using the PostCheckPermission endpoint. It accepts an optional maxDepth and a PostCheckPermissionBody. The response indicates whether the permission is granted. ```go package main import ( "context" "fmt" "os" openapiclient "./openapi" ) func main() { maxDepth := int64(789) // int64 | (optional) postCheckPermissionBody := *openapiclient.NewPostCheckPermissionBody() // PostCheckPermissionBody | (optional) configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) resp, r, err := apiClient.PermissionApi.PostCheckPermission(context.Background()).MaxDepth(maxDepth).PostCheckPermissionBody(postCheckPermissionBody).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `PermissionApi.PostCheckPermission``: %v\n", err) fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) } // response from `PostCheckPermission`: CheckPermissionResult fmt.Fprintf(os.Stdout, "Response from `PermissionApi.PostCheckPermission`: %v\n", resp) } ``` -------------------------------- ### Check Health and Version (Go SDK) Source: https://context7.com/ory/keto/llms.txt The Go SDK provides methods to check the liveness, readiness, and version of the Ory Keto service. This example demonstrates calling each of these endpoints and printing their status or version. Proper error handling is included. ```go package main import ( "context" "fmt" "os" openapiclient "./openapi" ) func main() { configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) // Liveness aliveResp, _, err := apiClient.MetadataApi.IsAlive(context.Background()).Execute() if err != nil { fmt.Fprintln(os.Stderr, "Server not alive:", err) os.Exit(1) } fmt.Println("Alive:", aliveResp.Status) // Readiness readyResp, _, err := apiClient.MetadataApi.IsReady(context.Background()).Execute() if err != nil { fmt.Fprintln(os.Stderr, "Server not ready:", err) os.Exit(1) } fmt.Println("Ready:", readyResp.Status) // Version versionResp, _, err := apiClient.MetadataApi.GetVersion(context.Background()).Execute() if err != nil { fmt.Fprintln(os.Stderr, "Error:", err) os.Exit(1) } fmt.Println("Version:", versionResp.Version) } ``` -------------------------------- ### Example JSON Schema Source: https://github.com/ory/keto/blob/master/oryx/jsonschemax/README.md This is an example JSON Schema demonstrating the structure for an array of objects, which influences the generated JSON paths. ```json { "$schema": "http://json-schema.org/draft-07/schema#", "properties": { "providers": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "string" } } } } } } ``` -------------------------------- ### Check Permission Or Error Go Example Source: https://github.com/ory/keto/blob/master/internal/httpclient/docs/PermissionApi.md Demonstrates checking a permission and handling potential errors explicitly. This endpoint also accepts an optional maxDepth and a PostCheckPermissionOrErrorBody. The result indicates permission status or an error. ```go package main import ( "context" "fmt" "os" openapiclient "./openapi" ) func main() { maxDepth := int64(789) // int64 | (optional) postCheckPermissionOrErrorBody := *openapiclient.NewPostCheckPermissionOrErrorBody() // PostCheckPermissionOrErrorBody | (optional) configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) resp, r, err := apiClient.PermissionApi.PostCheckPermissionOrError(context.Background()).MaxDepth(maxDepth).PostCheckPermissionOrErrorBody(postCheckPermissionOrErrorBody).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `PermissionApi.PostCheckPermissionOrError``: %v\n", err) fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) } // response from `PostCheckPermissionOrError`: CheckPermissionResult fmt.Fprintf(os.Stdout, "Response from `PermissionApi.PostCheckPermissionOrError`: %v\n", resp) } ``` -------------------------------- ### Run Full Ory Keto Test Suite Source: https://github.com/ory/keto/blob/master/DEVELOP.md Execute the complete test suite, which requires a database setup (PostgreSQL, MySQL, CockroachDB). This command first sources a script to reset the database. ```shell source ./scripts/test-resetdb.sh go test ./... ``` -------------------------------- ### Define Ory Permissions Namespace Source: https://github.com/ory/keto/blob/master/README.md Creates a configuration file defining a namespace for Ory Permissions using the Ory Permission Language. This example defines a 'Document' namespace. ```bash # Write a simple configuration with one namespace echo "class Document implements Namespace {}" > config.ts ``` -------------------------------- ### Patch Relationships - Go SDK Source: https://context7.com/ory/keto/llms.txt This Go SDK example demonstrates atomically patching relationships. It uses the RelationshipApi and requires OpenAPI client generation. ```go // Go SDK: Patch relationships atomically package main import ( "context" "fmt" "os" openapiclient "./openapi" ) func main() { configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) ns := "chats"; obj := "memes"; rel := "member"; subj := "PM" patches := []openapiclient.RelationshipPatch{ { Action: openapiclient.PtrString("insert"), RelationTuple: &openapiclient.Relationship{ Namespace: ns, Object: obj, Relation: rel, SubjectId: &subj, }, }, } _, r, err := apiClient.RelationshipApi.PatchRelationships(context.Background()).RelationshipPatch(patches).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error: %v\nHTTP: %v\n", err, r) os.Exit(1) } fmt.Println("Relationships patched successfully") } ``` -------------------------------- ### Transact and Delete Relation Tuples (gRPC) Source: https://context7.com/ory/keto/llms.txt This Go gRPC example demonstrates how to use the WriteService to perform bulk inserts of relation tuples and how to delete tuples matching a specific query. ```APIDOC ## TransactRelationTuples & DeleteRelationTuples (gRPC) ### Description The `WriteService` provides transactional writes to the admin port. `TransactRelationTuples` supports batch insert/delete in one atomic operation, while `DeleteRelationTuples` removes tuples matching a `RelationQuery`. ### Method `TransactRelationTuples` and `DeleteRelationTuples` (gRPC methods) ### Usage Example (Go) ```go package main import ( "context" "fmt" rts "github.com/ory/keto/proto/ory/keto/relation_tuples/v1alpha2" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" ) func main() { conn, err := grpc.NewClient("127.0.0.1:4467", grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { panic(err) } client := rts.NewWriteServiceClient(conn) tuples := []*rts.RelationTuple{ {Namespace: "directories", Object: "/photos", Relation: "owner", Subject: rts.NewSubjectID("maureen")}, {Namespace: "files", Object: "/photos/beach.jpg", Relation: "owner", Subject: rts.NewSubjectID("maureen")}, {Namespace: "files", Object: "/photos/mountains.jpg", Relation: "owner", Subject: rts.NewSubjectID("laura")}, {Namespace: "directories", Object: "/photos", Relation: "access", Subject: rts.NewSubjectID("laura")}, {Namespace: "directories", Object: "/photos", Relation: "access", Subject: rts.NewSubjectSet("directories", "/photos", "owner")}, {Namespace: "files", Object: "/photos/beach.jpg", Relation: "access", Subject: rts.NewSubjectSet("files", "/photos/beach.jpg", "owner")}, {Namespace: "files", Object: "/photos/beach.jpg", Relation: "access", Subject: rts.NewSubjectSet("directories", "/photos", "access")}, {Namespace: "files", Object: "/photos/mountains.jpg", Relation: "access", Subject: rts.NewSubjectSet("directories", "/photos", "access")}, } _, err = client.TransactRelationTuples(context.Background(), &rts.TransactRelationTuplesRequest{ RelationTupleDeltas: rts.RelationTupleToDeltas(tuples, rts.RelationTupleDelta_ACTION_INSERT), }) if err != nil { panic(err) } fmt.Println("Successfully created tuples") _, err = client.DeleteRelationTuples(context.Background(), &rts.DeleteRelationTuplesRequest{ RelationQuery: &rts.RelationQuery{ Namespace: strPtr("files"), Subject: rts.NewSubjectID("laura"), }, }) if err != nil { panic(err) } fmt.Println("Deleted tuples for laura") } func strPtr(s string) *string { return &s } ``` ``` -------------------------------- ### TypeScript Namespace and Permission Definitions Source: https://github.com/ory/keto/blob/master/docs/ory_permission_language_spec.md Provides example TypeScript class definitions for namespaces like User, Group, Folder, and File, including their 'related' properties and 'permits' methods. ```typescript class User implements Namespace { related: { manager: User[] } } class Group implements Namespace { related: { members: (User | Group)[] } } class Folder implements Namespace { related: { parents: File[] viewers: (User | SubjectSet)[] } permits = { view: (ctx: Context): boolean => this.related.viewers.includes(ctx.subject), } } class File implements Namespace { related: { parents: (File | Folder)[] viewers: (User | SubjectSet)[] owners: (User | SubjectSet)[] siblings: File[] } permits = { view: (ctx: Context): boolean => this.related.parents.traverse((p) => p.related.viewers.includes(ctx.subject), ) || this.related.parents.traverse((p) => p.permits.view(ctx)) || this.related.viewers.includes(ctx.subject) || this.related.owners.includes(ctx.subject), edit: (ctx: Context) => this.related.owners.includes(ctx.subject), rename: (ctx: Context) => this.related.siblings.traverse((s) => s.permits.edit(ctx)), } } ``` -------------------------------- ### Patch Relationships Go Example Source: https://github.com/ory/keto/blob/master/internal/httpclient/docs/RelationshipApi.md Patches multiple relationships using a slice of RelationshipPatch objects. The `RelationshipPatch` struct should be initialized with the desired patch operations. This endpoint does not require authorization. ```go package main import ( "context" "fmt" "os" openapiclient "./openapi" ) func main() { relationshipPatch := []openapiclient.RelationshipPatch{*openapiclient.NewRelationshipPatch()} // []RelationshipPatch | (optional) configuration := openapiclient.NewConfiguration() apiClient := openapiclient.NewAPIClient(configuration) resp, r, err := apiClient.RelationshipApi.PatchRelationships(context.Background()).RelationshipPatch(relationshipPatch).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `RelationshipApi.PatchRelationships``: %v\n", err) fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) } } ``` -------------------------------- ### Create Ory Permissions Relationship Tuple Source: https://github.com/ory/keto/blob/master/README.md Creates a relationship tuple that grants a user access to a resource. This example grants 'tom' the 'read' action on a 'secret' document. ```bash # Create a relationship that grants tom access to a document echo "Document:secret#read@tom" \ | ory parse relation-tuples --format=json - \ | ory create relation-tuples - ``` -------------------------------- ### Relation Tuple String Format (CLI) Source: https://context7.com/ory/keto/llms.txt This section details the compact string notation for relation tuples used with the CLI and ingestion workflows, and provides examples for parsing, creating, checking, and listing tuples. ```APIDOC ## Relation Tuple String Format (CLI) ### Description Keto supports a compact string notation for relation tuples: `namespace:object#relation@subject`. The subject can be a plain ID or a subject set `(namespace:object#relation)`. ### Usage Examples #### Parse and Insert Relation Tuples from String Notation ```bash echo 'directories:/photos#owner@maureen files:/photos/beach.jpg#owner@maureen files:/photos/mountains.jpg#owner@laura directories:/photos#access@laura directories:/photos#access@(directories:/photos#owner) files:/photos/beach.jpg#access@(files:/photos/beach.jpg#owner) files:/photos/beach.jpg#access@(directories:/photos#access)' | \ keto relation-tuple parse -f - --format json | \ jq "[ .[] | { relation_tuple: . , action: \"insert\" } ]" -c | \ curl -s -X PATCH \ -H 'Content-Type: application/json' \ --data @- \ http://127.0.0.1:4467/admin/relation-tuples ``` #### Check a Permission ```bash keto check permission Document:secret read tom # Output: Allowed / Denied ``` #### List All Relation Tuples ```bash keto list relation-tuples --namespace chats --relation member --subject-id PM ``` #### Create a Single Tuple ```bash echo "Document:secret#read@tom" | \ keto parse relation-tuples --format=json - | \ keto create relation-tuples - ``` ``` -------------------------------- ### gRPC: Bulk Insert and Delete Relation Tuples Source: https://context7.com/ory/keto/llms.txt Use the gRPC WriteService for atomic batch operations. This example demonstrates inserting filesystem ACL hierarchy tuples and then deleting tuples associated with a specific subject. ```Go package main import ( "context" "fmt" rts "github.com/ory/keto/proto/ory/keto/relation_tuples/v1alpha2" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" ) func main() { conn, err := grpc.NewClient("127.0.0.1:4467", grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { panic(err) } client := rts.NewWriteServiceClient(conn) tuples := []*rts.RelationTuple{ // maureen owns /photos directory and beach.jpg {Namespace: "directories", Object: "/photos", Relation: "owner", Subject: rts.NewSubjectID("maureen")}, {Namespace: "files", Object: "/photos/beach.jpg", Relation: "owner", Subject: rts.NewSubjectID("maureen")}, // laura owns mountains.jpg; maureen explicitly grants laura access to /photos {Namespace: "files", Object: "/photos/mountains.jpg", Relation: "owner", Subject: rts.NewSubjectID("laura")}, {Namespace: "directories", Object: "/photos", Relation: "access", Subject: rts.NewSubjectID("laura")}, // owners always have access (subject-set rewrite) {Namespace: "directories", Object: "/photos", Relation: "access", Subject: rts.NewSubjectSet("directories", "/photos", "owner")}, {Namespace: "files", Object: "/photos/beach.jpg", Relation: "access", Subject: rts.NewSubjectSet("files", "/photos/beach.jpg", "owner")}, // access to parent directory implies access to files {Namespace: "files", Object: "/photos/beach.jpg", Relation: "access", Subject: rts.NewSubjectSet("directories", "/photos", "access")}, {Namespace: "files", Object: "/photos/mountains.jpg", Relation: "access", Subject: rts.NewSubjectSet("directories", "/photos", "access")}, } _, err = client.TransactRelationTuples(context.Background(), &rts.TransactRelationTuplesRequest{ RelationTupleDeltas: rts.RelationTupleToDeltas(tuples, rts.RelationTupleDelta_ACTION_INSERT), }) if err != nil { panic(err) } fmt.Println("Successfully created tuples") // Delete all tuples for a subject _, err = client.DeleteRelationTuples(context.Background(), &rts.DeleteRelationTuplesRequest{ RelationQuery: &rts.RelationQuery{ Namespace: strPtr("files"), Subject: rts.NewSubjectID("laura"), }, }) if err != nil { panic(err) } fmt.Println("Deleted tuples for laura") } func strPtr(s string) *string { return &s } ``` -------------------------------- ### CheckPermission Source: https://github.com/ory/keto/blob/master/internal/httpclient/README.md Checks a single permission using GET request. ```APIDOC ## GET /relation-tuples/check/openapi ### Description Check a permission ### Method GET ### Endpoint /relation-tuples/check/openapi ``` -------------------------------- ### ExpandedPermissionTree Getters and Setters Source: https://github.com/ory/keto/blob/master/internal/httpclient/docs/ExpandedPermissionTree.md Methods for getting and setting the properties of an ExpandedPermissionTree object. ```APIDOC ### GetChildren `func (o *ExpandedPermissionTree) GetChildren() []ExpandedPermissionTree` GetChildren returns the Children field if non-nil, zero value otherwise. ### GetChildrenOk `func (o *ExpandedPermissionTree) GetChildrenOk() (*[]ExpandedPermissionTree, bool)` GetChildrenOk returns a tuple with the Children field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetChildren `func (o *ExpandedPermissionTree) SetChildren(v []ExpandedPermissionTree)` SetChildren sets Children field to given value. ### HasChildren `func (o *ExpandedPermissionTree) HasChildren() bool` HasChildren returns a boolean if a field has been set. ### GetTuple `func (o *ExpandedPermissionTree) GetTuple() Relationship` GetTuple returns the Tuple field if non-nil, zero value otherwise. ### GetTupleOk `func (o *ExpandedPermissionTree) GetTupleOk() (*Relationship, bool)` GetTupleOk returns a tuple with the Tuple field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetTuple `func (o *ExpandedPermissionTree) SetTuple(v Relationship)` SetTuple sets Tuple field to given value. ### HasTuple `func (o *ExpandedPermissionTree) HasTuple() bool` HasTuple returns a boolean if a field has been set. ### GetType `func (o *ExpandedPermissionTree) GetType() string` GetType returns the Type field if non-nil, zero value otherwise. ### GetTypeOk `func (o *ExpandedPermissionTree) GetTypeOk() (*string, bool)` GetTypeOk returns a tuple with the Type field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetType `func (o *ExpandedPermissionTree) SetType(v string)` SetType sets Type field to given value. ``` -------------------------------- ### Select Server Configuration by Index Source: https://github.com/ory/keto/blob/master/internal/httpclient/README.md Override the default server configuration by setting the 'ContextServerIndex' context value to the desired server index. ```go ctx := context.WithValue(context.Background(), client.ContextServerIndex, 1) ``` -------------------------------- ### BatchCheckPermissionBody Methods Source: https://github.com/ory/keto/blob/master/internal/httpclient/docs/BatchCheckPermissionBody.md Methods for interacting with the BatchCheckPermissionBody, including getting and setting its properties. ```APIDOC ## Methods ### GetTuples `func (o *BatchCheckPermissionBody) GetTuples() []Relationship` Returns the Tuples field if non-nil, otherwise returns the zero value. ### GetTuplesOk `func (o *BatchCheckPermissionBody) GetTuplesOk() (*[]Relationship, bool)` Returns a tuple containing the Tuples field and a boolean indicating if it has been set. ### SetTuples `func (o *BatchCheckPermissionBody) SetTuples(v []Relationship)` Sets the Tuples field to the provided value. ### HasTuples `func (o *BatchCheckPermissionBody) HasTuples() bool` Returns true if the Tuples field has been set, false otherwise. ``` -------------------------------- ### View Ory Keto Command Line Documentation Source: https://github.com/ory/keto/blob/master/DEVELOP.md Run this command to see all available commands and flags for the Ory Keto CLI. ```shell keto -h ``` ```shell keto help ``` -------------------------------- ### RelationshipPatch RelationTuple Methods Source: https://github.com/ory/keto/blob/master/internal/httpclient/docs/RelationshipPatch.md Methods for getting, setting, and checking the RelationTuple field of a RelationshipPatch. ```APIDOC ## RelationshipPatch RelationTuple Methods ### GetRelationTuple `func (o *RelationshipPatch) GetRelationTuple() Relationship` GetRelationTuple returns the RelationTuple field if non-nil, zero value otherwise. ### GetRelationTupleOk `func (o *RelationshipPatch) GetRelationTupleOk() (*Relationship, bool)` GetRelationTupleOk returns a tuple with the RelationTuple field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetRelationTuple `func (o *RelationshipPatch) SetRelationTuple(v Relationship)` SetRelationTuple sets RelationTuple field to given value. ### HasRelationTuple `func (o *RelationshipPatch) HasRelationTuple() bool` HasRelationTuple returns a boolean if a field has been set. ``` -------------------------------- ### RelationshipPatch Action Methods Source: https://github.com/ory/keto/blob/master/internal/httpclient/docs/RelationshipPatch.md Methods for getting, setting, and checking the Action field of a RelationshipPatch. ```APIDOC ## RelationshipPatch Action Methods ### GetAction `func (o *RelationshipPatch) GetAction() string` GetAction returns the Action field if non-nil, zero value otherwise. ### GetActionOk `func (o *RelationshipPatch) GetActionOk() (*string, bool)` GetActionOk returns a tuple with the Action field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### SetAction `func (o *RelationshipPatch) SetAction(v string)` SetAction sets Action field to given value. ### HasAction `func (o *RelationshipPatch) HasAction() bool` HasAction returns a boolean if a field has been set. ``` -------------------------------- ### Namespace Property Accessors Source: https://github.com/ory/keto/blob/master/internal/httpclient/docs/Namespace.md Methods for getting and setting the 'Name' property of a Namespace object. ```APIDOC ## GetName ### Description GetName returns the Name field if non-nil, zero value otherwise. ### Function Signature `func (o *Namespace) GetName() string` ## GetNameOk ### Description GetNameOk returns a tuple with the Name field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### Function Signature `func (o *Namespace) GetNameOk() (*string, bool)` ## SetName ### Description SetName sets Name field to given value. ### Function Signature `func (o *Namespace) SetName(v string)` ## HasName ### Description HasName returns a boolean if a field has been set. ### Function Signature `func (o *Namespace) HasName() bool` ``` -------------------------------- ### Hydra Serve Help Option Source: https://github.com/ory/keto/blob/master/oryx/clidoc/testdata/hydra-serve.md The --help flag provides detailed information about the serve command and its available options. ```bash -h, --help help for serve ``` -------------------------------- ### Build Ory Keto Docker Image Source: https://github.com/ory/keto/blob/master/DEVELOP.md Build a development Docker image for Ory Keto. ```shell make docker ``` -------------------------------- ### SourcePosition Column Field Methods Source: https://github.com/ory/keto/blob/master/internal/httpclient/docs/SourcePosition.md Methods for getting, setting, and checking the presence of the Column field in a SourcePosition object. ```APIDOC ## GetColumn `func (o *SourcePosition) GetColumn() int64` GetColumn returns the Column field if non-nil, zero value otherwise. ## GetColumnOk `func (o *SourcePosition) GetColumnOk() (*int64, bool)` GetColumnOk returns a tuple with the Column field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ## SetColumn `func (o *SourcePosition) SetColumn(v int64)` SetColumn sets Column field to given value. ## HasColumn `func (o *SourcePosition) HasColumn() bool` HasColumn returns a boolean if a field has been set. ``` -------------------------------- ### Instantiate IsAlive200Response with Defaults Source: https://github.com/ory/keto/blob/master/internal/httpclient/docs/IsAlive200Response.md Use this constructor to create a new IsAlive200Response object. It assigns default values to properties where defined but does not guarantee that all required properties are set. ```go func NewIsAlive200ResponseWithDefaults() *IsAlive200Response ``` -------------------------------- ### SourcePosition Line Field Methods Source: https://github.com/ory/keto/blob/master/internal/httpclient/docs/SourcePosition.md Methods for getting, setting, and checking the presence of the Line field in a SourcePosition object. ```APIDOC ## GetLine `func (o *SourcePosition) GetLine() int64` GetLine returns the Line field if non-nil, zero value otherwise. ## GetLineOk `func (o *SourcePosition) GetLineOk() (*int64, bool)` GetLineOk returns a tuple with the Line field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ## SetLine `func (o *SourcePosition) SetLine(v int64)` SetLine sets Line field to given value. ## HasLine `func (o *SourcePosition) HasLine() bool` HasLine returns a boolean if a field has been set. ``` -------------------------------- ### Check Ory Permissions Source: https://github.com/ory/keto/blob/master/README.md Checks if a specific permission is granted. This example verifies if 'tom' has the 'read' permission on the 'secret' document. ```bash # Check if tom can read the document ory check permission Document:secret read tom ``` -------------------------------- ### Ory CLI Authentication and Project Creation Source: https://github.com/ory/keto/blob/master/README.md Authenticates with Ory services and creates a new project with a workspace. This is a prerequisite for using Ory Permissions. ```bash # Sign in or sign up ory auth # Create a new project ory create project --create-workspace "Ory Open Source" --name "GitHub Quickstart" --use-project ``` -------------------------------- ### Get Namespace Name Source: https://github.com/ory/keto/blob/master/internal/httpclient/docs/Namespace.md GetName retrieves the value of the Name field. If the field is nil, it returns the zero value for a string. ```go func (o *Namespace) GetName() string { if o == nil || o.Name == nil { var ret string return ret } return *o.Name } ``` -------------------------------- ### Get Status Field Source: https://github.com/ory/keto/blob/master/internal/httpclient/docs/IsAlive200Response.md Retrieves the value of the 'Status' field from an IsAlive200Response object. Returns the zero value if the field is nil. ```go func (o *IsAlive200Response) GetStatus() string ``` -------------------------------- ### GenericError Getters and Setters Source: https://github.com/ory/keto/blob/master/internal/httpclient/docs/GenericError.md Provides methods to get, set, and check the presence of the Request and Status fields within the GenericError model. ```APIDOC ## GetRequestOk ### Description GetRequestOk returns a tuple with the Request field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### Method Signature `func (o *GenericError) GetRequestOk() (*string, bool)` ## SetRequest ### Description SetRequest sets the Request field to the given value. ### Method Signature `func (o *GenericError) SetRequest(v string)` ## HasRequest ### Description HasRequest returns a boolean indicating if the Request field has been set. ### Method Signature `func (o *GenericError) HasRequest() bool` ## GetStatus ### Description GetStatus returns the Status field if non-nil, zero value otherwise. ### Method Signature `func (o *GenericError) GetStatus() string` ## GetStatusOk ### Description GetStatusOk returns a tuple with the Status field if it's non-nil, zero value otherwise and a boolean to check if the value has been set. ### Method Signature `func (o *GenericError) GetStatusOk() (*string, bool)` ## SetStatus ### Description SetStatus sets the Status field to the given value. ### Method Signature `func (o *GenericError) SetStatus(v string)` ## HasStatus ### Description HasStatus returns a boolean if a field has been set. ### Method Signature `func (o *GenericError) HasStatus() bool` ```