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

refactor: API paths #862

Merged
merged 3 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ for your colleagues, and much more!

### :mega: Community gets Ory Cloud for Free! :mega:

Ory community members get the Ory Cloud Start Up plan **free for six months**, with
all quality-of-life features available, such as custom domains and giving your
team members access.
Ory community members get the Ory Cloud Start Up plan **free for six months**,
with all quality-of-life features available, such as custom domains and giving
your team members access.
[Sign up with your GitHub account](https://console.ory.sh/registration?preferred_plan=start-up&utm_source=github&utm_medium=banner&utm_campaign=keto-readme-first900)
and use the coupon code **`FIRST900`** on the _"Start-Up Plan"_ checkout page to
claim your free project now! Make sure to be signed up to the
Expand Down
2 changes: 1 addition & 1 deletion buf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ lint:
- google
ignore_only:
ENUM_VALUE_PREFIX:
- ory/keto/acl/v1alpha1/write_service.proto
- ory/keto/relation_tuples/v1alpha2/write_service.proto
breaking:
use:
- PACKAGE
12 changes: 5 additions & 7 deletions cmd/check/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package check
import (
"fmt"

"github.com/ory/keto/internal/check"
rts "github.com/ory/keto/proto/ory/keto/relation_tuples/v1alpha2"

acl "github.com/ory/keto/proto/ory/keto/acl/v1alpha1"
"github.com/ory/keto/internal/check"

"github.com/ory/x/cmdx"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -42,11 +42,9 @@ func newCheckCmd() *cobra.Command {
return err
}

cl := acl.NewCheckServiceClient(conn)
resp, err := cl.Check(cmd.Context(), &acl.CheckRequest{
Subject: &acl.Subject{
Ref: &acl.Subject_Id{Id: args[0]},
},
cl := rts.NewCheckServiceClient(conn)
resp, err := cl.Check(cmd.Context(), &rts.CheckRequest{
Subject: rts.NewSubjectID(args[0]),
Relation: args[1],
Namespace: args[2],
Object: args[3],
Expand Down
17 changes: 5 additions & 12 deletions cmd/expand/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package expand
import (
"fmt"

rts "github.com/ory/keto/proto/ory/keto/relation_tuples/v1alpha2"

"github.com/ory/x/flagx"

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

"github.com/ory/keto/cmd/client"
"github.com/ory/keto/internal/expand"
acl "github.com/ory/keto/proto/ory/keto/acl/v1alpha1"
)

const FlagMaxDepth = "max-depth"
Expand All @@ -33,17 +34,9 @@ func NewExpandCmd() *cobra.Command {
return err
}

cl := acl.NewExpandServiceClient(conn)
resp, err := cl.Expand(cmd.Context(), &acl.ExpandRequest{
Subject: &acl.Subject{
Ref: &acl.Subject_Set{
Set: &acl.SubjectSet{
Relation: args[0],
Namespace: args[1],
Object: args[2],
},
},
},
cl := rts.NewExpandServiceClient(conn)
resp, err := cl.Expand(cmd.Context(), &rts.ExpandRequest{
Subject: rts.NewSubjectSet(args[1], args[2], args[0]),
MaxDepth: maxDepth,
})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/relationtuple/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"os"
"path/filepath"

acl "github.com/ory/keto/proto/ory/keto/acl/v1alpha1"
rts "github.com/ory/keto/proto/ory/keto/relation_tuples/v1alpha2"

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

Expand All @@ -25,7 +25,7 @@ func newCreateCmd() *cobra.Command {
"A directory will be traversed and all relation tuples will be created.\n" +
"Pass the special filename `-` to read from STD_IN.",
Args: cobra.MinimumNArgs(1),
RunE: transactRelationTuples(acl.RelationTupleDelta_INSERT),
RunE: transactRelationTuples(rts.RelationTupleDelta_ACTION_INSERT),
}
cmd.Flags().AddFlagSet(packageFlags)

Expand Down
15 changes: 8 additions & 7 deletions cmd/relationtuple/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package relationtuple
import (
"fmt"

rts "github.com/ory/keto/proto/ory/keto/relation_tuples/v1alpha2"

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

"github.com/ory/keto/cmd/client"
"github.com/ory/keto/internal/relationtuple"
acl "github.com/ory/keto/proto/ory/keto/acl/v1alpha1"
)

func newDeleteCmd() *cobra.Command {
Expand All @@ -19,39 +20,39 @@ func newDeleteCmd() *cobra.Command {
"A directory will be traversed and all relation tuples will be deleted.\n" +
"Pass the special filename `-` to read from STD_IN.",
Args: cobra.MinimumNArgs(1),
RunE: transactRelationTuples(acl.RelationTupleDelta_DELETE),
RunE: transactRelationTuples(rts.RelationTupleDelta_ACTION_DELETE),
}
cmd.Flags().AddFlagSet(packageFlags)

return cmd
}

func transactRelationTuples(action acl.RelationTupleDelta_Action) func(*cobra.Command, []string) error {
func transactRelationTuples(action rts.RelationTupleDelta_Action) func(*cobra.Command, []string) error {
return func(cmd *cobra.Command, args []string) error {
conn, err := client.GetWriteConn(cmd)
if err != nil {
return err
}

var tuples []*relationtuple.InternalRelationTuple
var deltas []*acl.RelationTupleDelta
var deltas []*rts.RelationTupleDelta
for _, fn := range args {
tuple, err := readTuplesFromArg(cmd, fn)
if err != nil {
return err
}
for _, t := range tuple {
tuples = append(tuples, t)
deltas = append(deltas, &acl.RelationTupleDelta{
deltas = append(deltas, &rts.RelationTupleDelta{
Action: action,
RelationTuple: t.ToProto(),
})
}
}

cl := acl.NewWriteServiceClient(conn)
cl := rts.NewWriteServiceClient(conn)

_, err = cl.TransactRelationTuples(cmd.Context(), &acl.TransactRelationTuplesRequest{
_, err = cl.TransactRelationTuples(cmd.Context(), &rts.TransactRelationTuplesRequest{
RelationTupleDeltas: deltas,
})
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions cmd/relationtuple/delete_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package relationtuple
import (
"fmt"

rts "github.com/ory/keto/proto/ory/keto/relation_tuples/v1alpha2"

"github.com/ory/x/pointerx"

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

"github.com/ory/keto/cmd/client"
acl "github.com/ory/keto/proto/ory/keto/acl/v1alpha1"
)

const (
Expand Down Expand Up @@ -53,9 +54,9 @@ func deleteRelationTuplesFromQuery(cmd *cobra.Command, args []string) error {
return err
}
defer conn.Close()
cl := acl.NewWriteServiceClient(conn)
_, err = cl.DeleteRelationTuples(cmd.Context(), &acl.DeleteRelationTuplesRequest{
Query: (*acl.DeleteRelationTuplesRequest_Query)(query),
cl := rts.NewWriteServiceClient(conn)
_, err = cl.DeleteRelationTuples(cmd.Context(), &rts.DeleteRelationTuplesRequest{
Query: (*rts.DeleteRelationTuplesRequest_Query)(query),
})
if err != nil {
_, _ = fmt.Fprintf(cmd.ErrOrStderr(), "Could not make request: %s\n", err)
Expand Down
10 changes: 5 additions & 5 deletions cmd/relationtuple/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strconv"

acl "github.com/ory/keto/proto/ory/keto/acl/v1alpha1"
rts "github.com/ory/keto/proto/ory/keto/relation_tuples/v1alpha2"

"github.com/ory/x/flagx"

Expand Down Expand Up @@ -43,8 +43,8 @@ func registerRelationTupleFlags(flags *pflag.FlagSet) {
}
}

func readQueryFromFlags(cmd *cobra.Command) (*acl.ListRelationTuplesRequest_Query, error) {
query := &acl.ListRelationTuplesRequest_Query{
func readQueryFromFlags(cmd *cobra.Command) (*rts.ListRelationTuplesRequest_Query, error) {
query := &rts.ListRelationTuplesRequest_Query{
Namespace: flagx.MustGetString(cmd, FlagNamespace),
Object: flagx.MustGetString(cmd, FlagObject),
Relation: flagx.MustGetString(cmd, FlagRelation),
Expand Down Expand Up @@ -102,13 +102,13 @@ func getTuples(pageSize *int32, pageToken *string) func(cmd *cobra.Command, _ []
}
defer conn.Close()

cl := acl.NewReadServiceClient(conn)
cl := rts.NewReadServiceClient(conn)
query, err := readQueryFromFlags(cmd)
if err != nil {
return err
}

resp, err := cl.ListRelationTuples(cmd.Context(), &acl.ListRelationTuplesRequest{
resp, err := cl.ListRelationTuples(cmd.Context(), &rts.ListRelationTuplesRequest{
Query: query,
PageSize: *pageSize,
PageToken: *pageToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ files:/photos/mountains.jpg#access@(directories:/photos#access)' | \
jq "[ .[] | { relation_tuple: . , action: \"insert\" } ]" -c | \
curl -X PATCH --silent --fail \
--data @- \
http://127.0.0.1:4467/relation-tuples
http://127.0.0.1:4467/admin/relation-tuples

echo "Successfully created tuples"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import grpc from '@ory/keto-grpc-client/node_modules/@grpc/grpc-js/build/src/index.js'
import { acl, write, writeService } from '@ory/keto-grpc-client'
import { relationTuples, write, writeService } from '@ory/keto-grpc-client'

const writeClient = new writeService.WriteServiceClient(
'127.0.0.1:4467',
Expand All @@ -10,19 +10,19 @@ const writeRequest = new write.TransactRelationTuplesRequest()

const insert = (tuple) => {
const tupleDelta = new write.RelationTupleDelta()
tupleDelta.setAction(write.RelationTupleDelta.Action.INSERT)
tupleDelta.setAction(write.RelationTupleDelta.Action.ACTION_INSERT)
tupleDelta.setRelationTuple(tuple)

writeRequest.addRelationTupleDeltas(tupleDelta)
}

const addSimpleTuple = (namespace, object, relation, user) => {
const relationTuple = new acl.RelationTuple()
const relationTuple = new relationTuples.RelationTuple()
relationTuple.setNamespace(namespace)
relationTuple.setObject(object)
relationTuple.setRelation(relation)

const sub = new acl.Subject()
const sub = new relationTuples.Subject()
sub.setId(user)
relationTuple.setSubject(sub)

Expand All @@ -43,17 +43,17 @@ addSimpleTuple('directories', '/photos', 'access', 'laura')
['files', '/photos/mountains.jpg'],
['directories', '/photos']
].forEach(([namespace, object]) => {
const relationTuple = new acl.RelationTuple()
const relationTuple = new relationTuples.RelationTuple()
relationTuple.setNamespace(namespace)
relationTuple.setObject(object)
relationTuple.setRelation('access')

const subjectSet = new acl.SubjectSet()
const subjectSet = new relationTuples.SubjectSet()
subjectSet.setNamespace(namespace)
subjectSet.setObject(object)
subjectSet.setRelation('owner')

const sub = new acl.Subject()
const sub = new relationTuples.Subject()
sub.setSet(subjectSet)
relationTuple.setSubject(sub)

Expand All @@ -63,17 +63,17 @@ addSimpleTuple('directories', '/photos', 'access', 'laura')
// should be subject set rewrite
// access on parent means access on child
;['/photos/beach.jpg', '/photos/mountains.jpg'].forEach((file) => {
const relationTuple = new acl.RelationTuple()
const relationTuple = new relationTuples.RelationTuple()
relationTuple.setNamespace('files')
relationTuple.setObject(file)
relationTuple.setRelation('access')

const subjectSet = new acl.SubjectSet()
const subjectSet = new relationTuples.SubjectSet()
subjectSet.setNamespace('directories')
subjectSet.setObject('/photos')
subjectSet.setRelation('access')

const sub = new acl.Subject()
const sub = new relationTuples.Subject()
sub.setSet(subjectSet)
relationTuple.setSubject(sub)

Expand Down
Loading