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

feat: unified APIs with REST, gRPC and Connect RPC #1659

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3cafe32
WIP: gRPC gateway
hperl Nov 23, 2022
866380c
WIP: generate complete OpenAPI spec
hperl Dec 2, 2022
79a45a1
WIP
hperl Dec 6, 2022
a86c910
WIP: grpc gateway
hperl Jan 2, 2023
8fd10fa
WIP
hperl Feb 13, 2023
57a26a5
chore: update sdk
hperl Feb 13, 2023
c20f53a
WIP: E2E tests missing
hperl Feb 20, 2023
2f11642
feat: switch to gRPC gateway
hperl Feb 21, 2023
3b006fa
Merge remote-tracking branch 'origin/master' into hperl/exp/grpc-gateway
hperl Feb 22, 2023
31e931c
fix: docs examples
hperl Feb 22, 2023
7ec7e6b
chore: format
hperl Feb 22, 2023
600be5f
fix: remove well-known pb for Go
hperl Feb 22, 2023
4883c7c
fix: block on dial
hperl Feb 22, 2023
36d77f8
chore: remove http handlers
hperl Feb 22, 2023
7a8c33f
refactor: add validation middleware
hperl Feb 23, 2023
f9e5646
chore: clean up swagger comments
hperl Feb 23, 2023
a769059
fix: re-add ParseErrors field
hperl Feb 23, 2023
147b988
Merge remote-tracking branch 'origin/master' into hperl/exp/grpc-gateway
hperl Feb 23, 2023
4136a0b
chore: make sdk
hperl Feb 23, 2023
e588023
chore: fix makefile
hperl Feb 23, 2023
1452688
Merge remote-tracking branch 'origin/master' into hperl/exp/grpc-gateway
hperl Feb 23, 2023
619a306
fix: null tree
hperl Feb 28, 2023
a99a212
fix: add internal gRPC server
hperl Mar 10, 2023
af1c06f
feat: configure gRPC interceptors per type
hperl Mar 13, 2023
1e7458b
Merge branch 'master' into hperl/exp/grpc-gateway
hperl Mar 13, 2023
149c9cd
chore: sdk
hperl Mar 28, 2023
8bb9ab6
Merge remote-tracking branch 'origin/master' into hperl/exp/grpc-gateway
hperl Feb 15, 2024
d2d14c8
chore: update deps
hperl Feb 15, 2024
f2eea82
chore: bump deps
hperl Feb 15, 2024
628979f
fix buf
hperl Feb 15, 2024
f5a960a
WIP: vanguard
hperl Sep 5, 2024
e7aa65d
WIP
hperl Oct 14, 2024
2293c22
fix all tests
hperl Dec 17, 2024
d95d526
fix API breakages
hperl Dec 19, 2024
f354335
fix spec
hperl Dec 20, 2024
40d1884
fix spec
hperl Dec 20, 2024
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
22 changes: 22 additions & 0 deletions .schema/openapi/patches/checkServices.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
- op: add
path: /paths/~1relation-tuples~1check/get/operationId
value: checkPermissionOrError
- op: add
path: /paths/~1relation-tuples~1check/post/operationId
value: postCheckPermissionOrError
- op: add
path: /paths/~1relation-tuples~1check~1openapi/get/operationId
value: checkPermission
- op: add
path: /paths/~1relation-tuples~1check~1openapi/post/operationId
value: postCheckPermission

# Remove schema from empty response.
- op: replace
path: /paths/~1admin~1relation-tuples/delete/responses/204
value:
description: An empty response.
- op: replace
path: /paths/~1admin~1relation-tuples/patch/responses/204
value:
description: An empty response.
19 changes: 15 additions & 4 deletions .schema/openapi/patches/health.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- op: replace
- op: add
path: /paths/~1health~1alive
value:
get:
Expand All @@ -17,17 +17,22 @@
content:
application/json:
schema:
"$ref": "#/components/schemas/healthStatus"
required:
- status
type: object
properties:
status:
type: string
description: {{.ProjectHumanName}} is ready to accept connections.
'500':
content:
application/json:
schema:
"$ref": "#/components/schemas/genericError"
"$ref": "#/definitions/errorGeneric"
description: genericError
summary: Check HTTP Server Status
tags: {{ .HealthPathTags | toJson }}
- op: replace
- op: add
path: /paths/~1health~1ready
value:
get:
Expand All @@ -46,6 +51,8 @@
content:
application/json:
schema:
required:
- status
type: object
properties:
status:
Expand All @@ -56,6 +63,8 @@
content:
application/json:
schema:
required:
- errors
properties:
errors:
additionalProperties:
Expand Down Expand Up @@ -85,6 +94,8 @@
application/json:
schema:
type: object
required:
- version
properties:
version:
description: The version of {{.ProjectHumanName}}.
Expand Down
2 changes: 1 addition & 1 deletion .schema/openapi/patches/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- op: replace
- op: add
path: /info
value:
title: Ory Keto API
Expand Down
11 changes: 11 additions & 0 deletions .schema/openapi/patches/replacements.sed
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
s/ory.keto.relation_tuples.v1alpha2.ErrorResponse/errorGeneric/g
s/ory.keto.relation_tuples.v1alpha2.ErrorResponse.Error/genericError/g
s/ory.keto.relation_tuples.v1alpha2.CreateRelationTupleRequest.Relationship/createRelationshipBody/g
s/ory.keto.relation_tuples.v1alpha2.SubjectSet/subjectSet/g
s/ory.keto.relation_tuples.v1alpha2.SubjectTree/expandedPermissionTree/g
s/ory.keto.relation_tuples.v1alpha2.RelationTuple/relationship/g
s/ory.keto.relation_tuples.v1alpha2.ListRelationTuplesResponse/relationships/g
s/ory.keto.relation_tuples.v1alpha2.ListNamespacesResponse/relationshipNamespaces/g
s/ory.keto.relation_tuples.v1alpha2.CheckRequest/postCheckPermissionBody/g
s/ory.keto.relation_tuples.v1alpha2.CheckResponse/checkPermissionResult/g
s/ory.keto.opl.v1alpha1.CheckResponse/checkOplSyntaxResult/g
23 changes: 11 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export IMAGE_TAG := $(if $(IMAGE_TAG),$(IMAGE_TAG),latest)
GO_DEPENDENCIES = golang.org/x/tools/cmd/goimports \
github.com/mattn/goveralls \
github.com/ory/go-acc \
github.com/bufbuild/buf/cmd/buf \
github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc \
github.com/bufbuild/buf/cmd/buf \
github.com/josephburnett/jd \
github.com/mikefarah/yq/v4 \
golang.org/x/tools/cmd/stringer \
Expand Down Expand Up @@ -46,10 +46,11 @@ authors: # updates the AUTHORS file
curl https://raw.githubusercontent.com/ory/ci/master/authors/authors.sh | env PRODUCT="Ory Keto" bash

.PHONY: format
format: .bin/ory .bin/goimports node_modules
format: .bin/buf .bin/ory .bin/goimports node_modules
.bin/ory dev headers copyright --type=open-source --exclude=.bin --exclude=internal/httpclient --exclude=proto
.bin/goimports -w -local github.com/ory/keto *.go internal cmd contrib ketoctx ketoapi embedx
npm exec -- prettier --write .
buf format -w

.PHONY: install
install:
Expand All @@ -61,21 +62,18 @@ docker:

# Generates the SDKs
.PHONY: sdk
sdk: .bin/swagger .bin/ory node_modules
sdk: buf .bin/swagger .bin/ory node_modules
rm -rf internal/httpclient
swagger generate spec -m -o spec/swagger.json \
-c github.com/ory/keto \
-c github.com/ory/x/healthx \
-x internal/httpclient \
-x internal/e2e
.bin/ory dev swagger sanitize ./spec/swagger.json
swagger validate ./spec/swagger.json
.bin/ory dev swagger sanitize ./spec/api.swagger.json
sed -i -f ./.schema/openapi/patches/replacements.sed ./spec/api.swagger.json
swagger validate ./spec/api.swagger.json
CIRCLE_PROJECT_USERNAME=ory CIRCLE_PROJECT_REPONAME=keto \
.bin/ory dev openapi migrate \
--health-path-tags metadata \
-p https://raw.githubusercontent.com/ory/x/master/healthx/openapi/patch.yaml \
-p file://.schema/openapi/patches/health.yaml \
-p file://.schema/openapi/patches/meta.yaml \
spec/swagger.json spec/api.json
-p file://.schema/openapi/patches/checkServices.yaml \
spec/api.swagger.json spec/api.json

mkdir -p internal/httpclient

Expand Down Expand Up @@ -103,6 +101,7 @@ build:
#
.PHONY: buf-gen
buf-gen: .bin/buf .bin/protoc-gen-doc node_modules
buf format -w
buf generate proto
make format
@echo "All code was generated successfully!"
Expand Down
19 changes: 19 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ plugins:
out: proto
opt: paths=source_relative,require_unimplemented_servers=false

- plugin: buf.build/bufbuild/validate-go
out: proto
opt: paths=source_relative

- plugin: buf.build/protocolbuffers/js
out: proto
opt: import_style=commonjs,binary
Expand All @@ -26,3 +30,18 @@ plugins:
out: proto
opt: proto/markdown.tmpl,proto/buf.md
strategy: all

- plugin: buf.build/grpc-ecosystem/gateway
out: proto
opt: paths=source_relative

- plugin: buf.build/grpc-ecosystem/openapiv2
opt:
- allow_merge=true
- merge_file_name=api
- openapi_naming_strategy=fqn
- visibility_restriction_selectors=PUBLIC
- disable_service_tags=true
- disable_default_errors=true
- disable_default_responses=true
out: spec
6 changes: 3 additions & 3 deletions cmd/check/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import (
"github.com/ory/keto/ketoapi"
rts "github.com/ory/keto/proto/ory/keto/relation_tuples/v1alpha2"

"github.com/ory/keto/internal/check"

"github.com/ory/x/cmdx"
"github.com/spf13/cobra"

"github.com/ory/keto/cmd/client"
)

type checkOutput check.CheckPermissionResult
type checkOutput struct {
Allowed bool `json:"allowed"`
}

func (o *checkOutput) String() string {
if o.Allowed {
Expand Down
21 changes: 20 additions & 1 deletion cmd/expand/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package expand
import (
"fmt"

"google.golang.org/protobuf/encoding/protojson"

"github.com/ory/keto/ketoapi"

rts "github.com/ory/keto/proto/ory/keto/relation_tuples/v1alpha2"
Expand Down Expand Up @@ -53,7 +55,7 @@ func NewExpandCmd() *cobra.Command {
tree = ketoapi.TreeFromProto[*ketoapi.RelationTuple](resp.Tree)
}

cmdx.PrintJSONAble(cmd, tree)
cmdx.PrintJSONAble(cmd, &pbJSONValue{resp})
switch flagx.MustGetString(cmd, cmdx.FlagFormat) {
case string(cmdx.FormatDefault), "":
if tree == nil && !flagx.MustGetBool(cmd, cmdx.FlagQuiet) {
Expand All @@ -76,3 +78,20 @@ func NewExpandCmd() *cobra.Command {
func RegisterCommandsRecursive(parent *cobra.Command) {
parent.AddCommand(NewExpandCmd())
}

type pbJSONValue struct{ *rts.ExpandResponse }

func (v *pbJSONValue) MarshalJSON() ([]byte, error) {
marshaler := &protojson.MarshalOptions{EmitUnpopulated: true}
if v.Tree == nil || v.Tree.NodeType.Number() == 0 {
return []byte("null"), nil
}
return marshaler.Marshal(v.Tree)
}
func (v *pbJSONValue) String() string {
var tree *ketoapi.Tree[*ketoapi.RelationTuple]
if v.Tree != nil {
tree = ketoapi.TreeFromProto[*ketoapi.RelationTuple](v.Tree)
}
return tree.String()
}
5 changes: 3 additions & 2 deletions cmd/status/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import (
"testing"
"time"

"github.com/ory/x/cmdx"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
grpcHealthV1 "google.golang.org/grpc/health/grpc_health_v1"
"google.golang.org/grpc/metadata"

"github.com/ory/x/cmdx"

"github.com/ory/keto/cmd/client"
"github.com/ory/keto/internal/driver"
"github.com/ory/keto/internal/namespace"
Expand All @@ -37,7 +38,7 @@ func TestStatusCmd(t *testing.T) {
defer cancel()

stdErr := cmdx.ExecExpectedErrCtx(ctx, t, newStatusCmd(), "--"+FlagEndpoint, string(serverType), "--"+ts.FlagRemote, ts.Addr[:len(ts.Addr)-1])
assert.Equal(t, "context deadline exceeded", stdErr)
assert.Contains(t, stdErr, "context deadline exceeded")
})

t.Run("case=noblock", func(t *testing.T) {
Expand Down
Loading
Loading